0

I would like to use Bootstrap in my create-react-app application. I would like all of my CSS to be scoped to their respective components (via CSS modules) but I would like to apply the Bootstrap CSS to my entire application so that the standard controls look a bit nicer. First, I've installed Bootstrap via

npm install --save bootstrap

After I did some research on stackoverflow I found this answer and tried to modify my webpack.config.dev.js file. It now looks like this:

 {
        test: /\.css$/,
        exclude: '/node_modules/bootstrap/',
        use: [
          require.resolve('style-loader'),
          {
            loader: require.resolve('css-loader'),
            options: {
              importLoaders: 1,
              modules: true,
              localIdentName: '[name]__[local]__[hash:base64:5]',
            },
          },
          {
            loader: require.resolve('postcss-loader'),
            options: {
              // Necessary for external CSS imports to work
              // https://github.com/facebookincubator/create-react-app/issues/2677
              ident: 'postcss',
              plugins: () => [
                require('postcss-flexbugs-fixes'),
                autoprefixer({
                  browsers: [
                    '>1%',
                    'last 4 versions',
                    'Firefox ESR',
                    'not ie < 9', // React doesn't support IE8 anyway
                  ],
                  flexbox: 'no-2009',
                }),
              ],
            },
          },
        ],
      },
      {
        // don't apply CSS modules to all .css files in node_modules/bootstrap
        test: /\.css$/,
        include: '/node_modules/bootstrap/',
        use: ['style-loader', 'css-loader']
      },

I am importing the Bootstrap CSS in my index.js like so:

import 'bootstrap/dist/css/bootstrap.min.css';
import 'bootstrap/dist/css/bootstrap-theme.css';

ReactDOM.render(<App />, document.getElementById('root'));
registerServiceWorker();

However, the Bootstrap CSS does not get applied. Can anyone point my into the right direction why that is? Do I need a different config my webpack.config.dev.js file?

4
  • Are you getting any error in terminal? Commented Jan 22, 2018 at 9:30
  • no, simply nothing happens and the CSS Bootstrap styles are not applied globally Commented Jan 22, 2018 at 16:19
  • I'm not sure if it helps but, you can check my medium article: medium.com/monitisemea/… Commented Jan 22, 2018 at 20:36
  • Unfortunately that did not help Commented Jan 27, 2018 at 6:11

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.