2

I am using react-bootstrap and css modules. In my webpack.config.js i am able to run my bootstrap.css with this config:

{ test: /\.css$/, loader: "style-loader!css-loader" }

However my css modules should have this setup:

{
    test: /\.css$/,
    loaders: [
        'style?sourceMap',
    'css?modules&importLoaders=1&localIdentName=[path]___[name]__[local]___[hash:base64:5]'
    ]
}

How do I combine them to make it work for css modules and react-bootstrap

1 Answer 1

2

You might keep both loaders: one for global CSS (like Bootstrap) and the other for CSS modules.

In order to avoid conflicts between loaders with same test property, use webpack's rules include and exclude properties:

{
  test: /\.css$/,
  loader: "style-loader!css-loader",
  include: [
    /* Paths to Bootstrap and further global CSS only */
  ]
},
{
  test: /\.css$/,
  loaders: [
    'style?sourceMap',
    'css?modules&importLoaders=1&localIdentName[path]___[name]__[local]___[hash:base64:5]'
  ],
  include: [
    /* eg. Paths to your source directory  */
  ]
}
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.