Webpack to import css together with REACTJS

Asked

Viewed 46 times

2

Hello,

I am making a Component (REACTJS), I would like to import the css come. I’m using the css-loader and style-loader.

As I had never done something like this, I do not know if the configuration is correct.

webpack.config.js

module.exports = {
  entry: './src/index.js',

  output: {
    filename: 'main.js',
    path: path.resolve('dist')
  },

  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: 'babel-loader',
          options: {
            cacheDirectory: true
          }
        }
      },

      {
        test: /\.css$/,
        loader: 'style-loader!css-loader',
        use: ['style-loader', 'css-loader']
      }
    ]
  }
}

Project in the NPM : https://www.npmjs.com/package/slidal

When I install, I can use the component, but the css does not come together.

  • Oops, I’m gonna remove the answer since it wasn’t helpful. I wanted to bring you a solution to avoid all this stress, which would be using Styledcomponent or JSS, so you wouldn’t have to import any css style and everything would be inside the JS. Note the way Materialui works, it is very interesting.

  • I have worked with both solutions in creating libs, and it worked well.

  • I solved using the style from '..... and use each place within the Component style in line and not using class names with --, changing the pattern to upper case

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.