title: How to use webpack with create-react-app?
body: <p>I've created a <a href="https://github.com/facebook/create-react-app" rel="noreferrer">create-react-app</a> project following the <a href="https://facebook.github.io/create-react-app/docs/getting-started" rel="noreferrer">documentation provided by create-react-app</a></p>
  
  <p>1) I create my project and cd into it</p>
  
  <pre><code>npx create-react-app my-app
  cd my-app
  </code></pre>
  
  <p>2) I've followed the <a href="https://webpack.js.org/guides/getting-started/" rel="noreferrer">getting started documentation</a> and installed <a href="https://github.com/webpack/webpack" rel="noreferrer">webpack</a>, webpack-cli, and webpack-dev-server.</p>
  
  <pre><code>npm install --save-dev webpack webpack-dev-server webpack-cli
  </code></pre>
  
  <p>3) Considering that babel is needed Ive also followed these steps from <a href="https://www.robinwieruch.de/minimal-react-webpack-babel-setup/" rel="noreferrer">this instruction</a> </p>
  
  <pre><code>npm install --save-dev @babel/core @babel/preset-env
  npm install --save-dev babel-loader
  npm install --save-dev @babel/preset-react
  </code></pre>
  
  <p>4) I've also created the following <strong>webpack.config.js</strong> file following <a href="https://webpack.js.org/guides/getting-started/#using-a-configuration" rel="noreferrer">this instruction</a></p>
  
  <pre><code>const path = require('path');
  
  module.exports = {
    entry: './src/index.js',
    mode: 'production',
    module: {
      rules: [
          {
            test: /\.js$/,
            exclude: /node_modules/,
            use: {
              loader: 'babel-loader',
              options: {
              "presets": ["@babel/preset-env","@babel/preset-react"]        }
            }
          }
      ]
    },
    output: {
      filename: 'main.js',
      path: path.resolve(__dirname, 'dist')
    }
  };
  </code></pre>
  
  <p>See below for my package.json below</p>
  
  <pre><code>{
    "name": "my-app",
    "version": "0.1.0",
    "dependencies": {
      "react": "^16.7.0",
      "react-dom": "^16.7.0",
      "react-scripts": "2.1.3"
    },
    "scripts": {
      "start": "react-scripts start",
      "build": "react-scripts build",
      "test": "react-scripts test",
      "eject": "react-scripts eject",
      "start:dev": "webpack-dev-server",
      "build:dev": "webpack"
    },
    "eslintConfig": {
      "extends": "react-app"
    },
    "browserslist": [
      "&gt;0.2%",
      "not dead",
      "not ie &lt;= 11",
      "not op_mini all"
    ],
    "devDependencies": {
      "@babel/core": "^7.2.2",
      "@babel/preset-env": "^7.2.3",
      "@babel/preset-react": "^7.0.0",
      "babel-loader": "^8.0.5",
      "webpack": "^4.28.3",
      "webpack-cli": "^3.2.0",
      "webpack-dev-server": "^3.1.14"
    }
  }
  </code></pre>
  
  <p>When I run the following command</p>
  
  <pre><code>npm run start:dev
  </code></pre>
  
  <p>I get the following error</p>
  
  <pre><code> webpack-dev-server
  
  ℹ ｢wds｣: Project is running at http://localhost:8080/
  ℹ ｢wds｣: webpack output is served from /
  ✖ ｢wdm｣: Hash: ebe0431a84f29f0e98e9
  Version: webpack 4.28.3
  Time: 5058ms
  Built at: 01/05/2019 1:49:37 PM
   1 asset
  Entrypoint main = main.js
   [0] ./node_modules/react/index.js 190 bytes {0} [built]
   [4] ./node_modules/react-dom/index.js 1.33 KiB {0} [built]
   [5] ./src/logo.svg 2.65 KiB {0} [built] [failed] [1 error]
   [6] ./src/serviceWorker.js 4.6 KiB {0} [built]
   [7] multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js 40 bytes {0} [built]
   [8] (webpack)-dev-server/client?http://localhost:8080 7.78 KiB {0} [built]
   [9] ./node_modules/url/url.js 22.8 KiB {0} [built]
  [16] ./node_modules/strip-ansi/index.js 161 bytes {0} [built]
  [18] ./node_modules/loglevel/lib/loglevel.js 7.68 KiB {0} [built]
  [19] (webpack)-dev-server/client/socket.js 1.05 KiB {0} [built]
  [21] (webpack)-dev-server/client/overlay.js 3.58 KiB {0} [built]
  [26] (webpack)/hot sync nonrecursive ^\.\/log$ 170 bytes {0} [built]
  [28] (webpack)/hot/emitter.js 75 bytes {0} [built]
  [34] ./src/index.css 168 bytes {0} [built] [failed] [1 error]
  [37] ./src/index.js + 1 modules 3.58 KiB {0} [built]
       | ./src/index.js 472 bytes [built]
       | ./src/App.js 3.09 KiB [built]
      + 23 hidden modules
  
  ERROR in ./src/App.css 1:0
  Module parse failed: Unexpected token (1:0)
  You may need an appropriate loader to handle this file type.
  &gt; .App {
  |   text-align: center;
  | }
   @ ./src/App.js 21:0-19
   @ ./src/index.js
   @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js
  
  ERROR in ./src/logo.svg 1:0
  Module parse failed: Unexpected token (1:0)
  You may need an appropriate loader to handle this file type.
  &gt; &lt;svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"&gt;
  |     &lt;g fill="#61DAFB"&gt;
  |         &lt;path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/&gt;
   @ ./src/App.js 20:0-30 42:13-17
   @ ./src/index.js
   @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js
  
  ERROR in ./src/index.css 1:5
  Module parse failed: Unexpected token (1:5)
  You may need an appropriate loader to handle this file type.
  &gt; body {
  |   margin: 0;
  |   padding: 0;
   @ ./src/index.js 3:0-21
   @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/index.js
  ℹ ｢wdm｣: Failed to compile.
  </code></pre>
  
  <p>I also ran the following command</p>
  
  <pre><code>npm run build:dev
  </code></pre>
  
  <p>This generated this error: </p>
  
  <pre><code>&gt; my-app@0.1.0 build:dev /Users/chriscruz/Desktop/my-app
  &gt; webpack
  
  Hash: eff8d3ad52e3c88d156c
  Version: webpack 4.28.3
  Time: 2647ms
  Built at: 01/05/2019 1:54:01 PM
   1 asset
  Entrypoint main = main.js
   [3] ./src/logo.svg 2.65 KiB {0} [built] [failed] [1 error]
   [4] ./src/serviceWorker.js 4.6 KiB {0} [built]
   [9] (webpack)/buildin/global.js 472 bytes {0} [built]
  [10] ./src/index.css 168 bytes {0} [built] [failed] [1 error]
  [11] ./src/App.css 165 bytes {0} [built] [failed] [1 error]
  [13] ./src/index.js + 1 modules 3.58 KiB {0} [built]
       | ./src/index.js 472 bytes [built]
       | ./src/App.js 3.09 KiB [built]
      + 8 hidden modules
  
  ERROR in ./src/App.css 1:0
  Module parse failed: Unexpected token (1:0)
  You may need an appropriate loader to handle this file type.
  &gt; .App {
  |   text-align: center;
  | }
   @ ./src/App.js 21:0-19
   @ ./src/index.js
  
  ERROR in ./src/logo.svg 1:0
  Module parse failed: Unexpected token (1:0)
  You may need an appropriate loader to handle this file type.
  &gt; &lt;svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"&gt;
  |     &lt;g fill="#61DAFB"&gt;
  |         &lt;path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/&gt;
   @ ./src/App.js 20:0-30 42:13-17
   @ ./src/index.js
  
  ERROR in ./src/index.css 1:5
  Module parse failed: Unexpected token (1:5)
  You may need an appropriate loader to handle this file type.
  &gt; body {
  |   margin: 0;
  |   padding: 0;
   @ ./src/index.js 3:0-21
  npm ERR! code ELIFECYCLE
  npm ERR! errno 2
  npm ERR! my-app@0.1.0 build:dev: `webpack`
  npm ERR! Exit status 2
  npm ERR! 
  npm ERR! Failed at the my-app@0.1.0 build:dev script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /Users/chriscruz/.npm/_logs/2019-01-05T18_54_01_643Z-debug.log
  </code></pre>