0

I'm trying to set up React-Table, which relies on a style sheet that needs to be imported into Webpack with the following statement:

import ReactTable from 'react-table'

Unfortunately, I'm not very familiar with configuring Webpack and am not sure where this line should go. Here's my webpack.config.js file:

const loaders = require('loaders');

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js',
    sourceMapFilename: "bundle.js.map"
  },
  module: {
      loaders: [
          loaders.css,
          loaders.url,
          {
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
            presets: ['react', 'es2015', 'stage-1']
          }
    }]
  },
  resolve: {
    extensions: ['*', '.js', '.jsx']
  },
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }
};

Can anyone point me in the right direction?

5
  • Please upload the loaders files as well, thanks. Commented Dec 3, 2017 at 10:44
  • Those files are Node modules; how should I include them? Commented Dec 3, 2017 at 13:27
  • Never mind. Why would you want to use something that is deprecated. Commented Dec 3, 2017 at 16:13
  • 1
    What version of webpack? Does this help - webpack.js.org/guides/asset-management/#loading-css Commented Dec 3, 2017 at 17:50
  • @olore I'm running Webpack 3.8.1. Yes, that link explains it. Do you want to add it as an answer (with the relevant text, in case the link changes later) and I will accept? Commented Dec 4, 2017 at 7:05

1 Answer 1

2

Try updating your webpack file with this and install all loaders like css-loader, url-loader, file-loader, style-loader, sass-loader etc.

module.exports = {
  entry: [
    './src/index.js'
  ],
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js',
    sourceMapFilename: "bundle.js.map"
  },
  module: {
  loaders: [
     {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
        query: {
           presets: ['es2015', 'react']
        }
     },
     { test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000' },
     {test: /\.eot(\?v=\d+.\d+.\d+)?$/, loader: 'file-loader'},
     {test: /\.css$/, loader: "style-loader!css-loader" },
     {test: /\.scss$/, loaders: ['style-loader', 'css-loader', 'sass-loader']},

  ]
  },
  resolve: {
    extensions: ['*', '.js', '.jsx']
  },
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }
};

Also if you want to make your stylesheet work with webpack and see those changes in app, you can put that stylesheet in your styles folder and import it in your entry file i.e src/index.js. Something like this :-

 import './styles/style.css' ;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.