title: How to resolve css loader in webpack config?
body: <p>I am trying to set up a react project and managed to add components correctly.  Now I am trying to add css to this project but I having a hard time.</p>
  
  <p>I have tried numerous approaches with no result and I have some basic knowledge of how to go about it however no attempt worked.  I have added the loader and the necessary plugins but I always get an error.  One approach I have tried and which I believe to be the correct one is the following:</p>
  
  <pre><code>npm install --save-dev style-loader css-loader
  </code></pre>
  
  <p>Then in rules.js:</p>
  
  <pre><code>...
  {
      test: /\.css$/,
      exclude: /node_modules/,
      use: ['style-loader', 'css-loader']
  
  }
  </code></pre>
  
  <p>These are my files:</p>
  
  <p>paths.js</p>
  
  <pre><code>import path from 'path';
  
  module.exports = {
      root: path.resolve(__dirname, '../', '../'),
      outputPath: path.resolve(__dirname, '../', '../', 'build'),
      entryPath: path.resolve(__dirname, '../', '../', 'src/index.js'),
      templatePath: path.resolve(__dirname, '../', '../', 'public/index.html'),
      imagesFolder: 'images',
      fontsFolder: 'fonts',
      cssFolder: 'css'
  }
  </code></pre>
  
  <p>rules.js</p>
  
  <pre><code>module.exports = [
      {
          test: /\.js$/,
          exclude: /node_modules/,
          use: {
              loader: 'babel-loader'
          }
      },
      {
          test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
          exclude: /node_modules/,
          loader: 'file-loader'
      },
      {
          test: /\.(woff|woff2)$/,
          exclude: /node_modules/,
          loader: 'url-loader?prefix=font/&amp;limit=5000'
      },
      {
          test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
          exclude: /node_modules/,
          loader: 'url-loader?limit=10000&amp;mimetype=application/octet-stream'
      },
      {
          test: /\.(jpe?g|png|gif|svg)$/i,
          use: ['url-loader?limit=10000', 'img-loader']
      }
  ];
  </code></pre>
  
  <p>webpack.common.babel.js</p>
  
  <pre><code>import webpack from 'webpack';
  import HtmlWebpackPlugin from 'html-webpack-plugin';
  
  import paths from './paths';
  import rules from './rules';
  
  module.exports = {
      entry: paths.entryPath,
      module: {
          rules
      },
      resolve: {
          modules: ['src', 'node_modules'],
          extensions: ['*', '.js', '.scss', '.css']
      },
      plugins: [
          new webpack.ProgressPlugin(),
          new HtmlWebpackPlugin({
              template: paths.templatePath,
              minify: {
                  collapseInlineTagWhitespace: true,
                  collapseWhitespace: true,
                  preserveLineBreaks: true,
                  minifyURLs: true,
                  removeComments: true,
                  removeAttributeQuotes: true
              }
          })
      ]
  };
  </code></pre>
  
  <p>webpack.dev.babel.js</p>
  
  <pre><code>import webpack from 'webpack';
  
  import paths from './paths';
  import rules from './rules';
  
  module.exports = {
      mode: 'development',
      output: {
          filename: '[name].js',
          path: paths.outputPath,
          chunkFilename: '[name].js'
      },
      module: {
          rules
      },
      performance: {
          hints: 'warning',
          maxAssetSize: 450000,
          maxEntrypointSize: 8500000,
          assetFilter: assetFilename =&gt; {
              return (
                  assetFilename.endsWith('.css') || assetFilename.endsWith('.js')
              );
          }
      },
      optimization: {
          splitChunks: {
              chunks: 'all'
          }
      },
      devServer: {
          contentBase: paths.outputPath,
          compress: true,
          hot: true,
          historyApiFallback: true
      },
      plugins: [
          new webpack.HotModuleReplacementPlugin()
      ]
  };
  </code></pre>
  
  <p>webpack.prod.babel.js</p>
  
  <pre><code>import CleanWebpackPlugin from 'clean-webpack-plugin';
  
  import paths from './paths';
  import rules from './rules';
  
  module.exports = {
      mode: 'production',
      output: {
          filename: `${paths.jsFolder}/[name].[hash].js`,
          path: paths.outputPath,
          chunkFilename: '[name].[chunkhash].js'
      },
      module: {
          rules
      },
      plugins: [
          new CleanWebpackPlugin([paths.outputPath.split('/').pop()], {
              root: paths.root
          })
      ],
      devtool: 'source-map'
  };
  </code></pre>
  
  <p>webpack.config.js</p>
  
  <pre><code>require('@babel/register');
  const webpackMerge = require('webpack-merge');
  
  const common = require('./config/webpack/webpack.common.babel');
  
  const envs = {
      development: 'dev',
      production: 'prod'
  };
  
  /* eslint-disable global-require,import/no-dynamic-require */
  const env = envs[process.env.NODE_ENV || 'development'];
  const envConfig = require(`./config/webpack/webpack.${env}.babel`);
  module.exports = webpackMerge(common, envConfig);
  </code></pre>
  
  <p>package.json</p>
  
  <pre><code>{
    "name": "photoly",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
    "scripts": {
      "start": "cross-env NODE_ENV=development webpack-dev-server --open"
    },
    "author": "Nikolas Pitsillos",
    "license": "ISC",
    "devDependencies": {
      "@babel/cli": "^7.4.4",
      "@babel/core": "^7.4.5",
      "@babel/node": "^7.4.5",
      "@babel/plugin-proposal-class-properties": "^7.4.4",
      "@babel/plugin-proposal-object-rest-spread": "^7.4.4",
      "@babel/plugin-syntax-dynamic-import": "^7.2.0",
      "@babel/plugin-syntax-import-meta": "^7.2.0",
      "@babel/plugin-transform-async-to-generator": "^7.4.4",
      "@babel/plugin-transform-runtime": "^7.4.4",
      "@babel/preset-env": "^7.4.5",
      "@babel/preset-react": "^7.0.0",
      "@babel/register": "^7.4.4",
      "@babel/runtime": "^7.4.5",
      "babel-core": "^7.0.0-bridge.0",
      "babel-eslint": "^10.0.1",
      "babel-jest": "^24.8.0",
      "babel-loader": "^8.0.6",
      "clean-webpack-plugin": "^2.0.2",
      "eslint": "^5.16.0",
      "eslint-config-airbnb": "^17.1.0",
      "eslint-config-prettier": "^4.3.0",
      "eslint-loader": "^2.1.2",
      "eslint-plugin-babel": "^5.3.0",
      "eslint-plugin-import": "^2.17.2",
      "eslint-plugin-jsx-a11y": "^6.2.1",
      "eslint-plugin-prettier": "^3.1.0",
      "eslint-plugin-react": "^7.13.0",
      "file-loader": "^3.0.1",
      "html-loader": "^0.5.5",
      "html-webpack-plugin": "^3.2.0",
      "img-loader": "^3.0.1",
      "prettier": "^1.17.1",
      "react": "^16.8.6",
      "react-dom": "^16.8.6",
      "react-router-dom": "^5.0.0",
      "url-loader": "^1.1.2",
      "webpack": "^4.32.2",
      "webpack-cli": "^3.3.2",
      "webpack-dev-server": "^3.4.1",
      "webpack-merge": "^4.2.1"
    },
    "dependencies": {
      "bootstrap": "^4.3.1",
      "cross-env": "^5.2.0",
      "react-bootstrap": "^1.0.0-beta.8",
      "react-redux": "^7.0.3",
      "redux": "^4.0.1",
      "redux-thunk": "^2.3.0"
    }
  }
  
  </code></pre>
  
  <p>This is my index.js file:</p>
  
  <pre><code>import React from 'react';
  import ReactDOM from 'react-dom';
  
  import App from './components/app/App';
  
  import '../node_modules/bootstrap/dist/css/bootstrap'
  
  ReactDOM.render(
      &lt;App /&gt;,
      document.getElementById('root')
  );
  </code></pre>
  
  <p>The error I get after running npm start</p>
  
  <pre><code>ERROR in ./node_modules/bootstrap/dist/css/bootstrap.css 7:0
  Module parse failed: Unexpected token (7:0)
  You may need an appropriate loader to handle this file type.
  |  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  |  */
  &gt; :root {
  |   --blue: #007bff;
  |   --indigo: #6610f2;
   @ ./src/index.js 4:0-54
  </code></pre>
  
  <p>Thank you for your help in advance.  If this is too complicated to solve can someone please point me to a working tutorial with a full setup for react, webpack, babel and support for css/sass styling?</p>