Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. const autoprefixer = require('autoprefixer');
  4. const path = require('path');
  5. const webpack = require('webpack');
  6. const HtmlWebpackPlugin = require('html-webpack-plugin');
  7. const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
  8. const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
  9. const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
  10. const eslintFormatter = require('react-dev-utils/eslintFormatter');
  11. const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
  12. const getClientEnvironment = require('./env');
  13. const paths = require('./paths');
  14.  
  15. // Webpack uses `publicPath` to determine where the app is being served from.
  16. // In development, we always serve from the root. This makes config easier.
  17. const publicPath = '/';
  18. // `publicUrl` is just like `publicPath`, but we will provide it to our app
  19. // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
  20. // Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
  21. const publicUrl = '';
  22. // Get environment variables to inject into our app.
  23. const env = getClientEnvironment(publicUrl);
  24.  
  25. // This is the development configuration.
  26. // It is focused on developer experience and fast rebuilds.
  27. // The production configuration is different and lives in a separate file.
  28. module.exports = {
  29.   // You may want 'eval' instead if you prefer to see the compiled output in DevTools.
  30.   // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
  31.   devtool: 'cheap-module-source-map',
  32.   // These are the "entry points" to our application.
  33.   // This means they will be the "root" imports that are included in JS bundle.
  34.   // The first two entry points enable "hot" CSS and auto-refreshes for JS.
  35.   entry: [
  36.     // Include an alternative client for WebpackDevServer. A client's job is to
  37.     // connect to WebpackDevServer by a socket and get notified about changes.
  38.     // When you save a file, the client will either apply hot updates (in case
  39.     // of CSS changes), or refresh the page (in case of JS changes). When you
  40.     // make a syntax error, this client will display a syntax error overlay.
  41.     // Note: instead of the default WebpackDevServer client, we use a custom one
  42.     // to bring better experience for Create React App users. You can replace
  43.     // the line below with these two lines if you prefer the stock client:
  44.     // require.resolve('webpack-dev-server/client') + '?/',
  45.     // require.resolve('webpack/hot/dev-server'),
  46.     require.resolve('react-dev-utils/webpackHotDevClient'),
  47.     // We ship a few polyfills by default:
  48.     require.resolve('./polyfills'),
  49.     // Errors should be considered fatal in development
  50.     require.resolve('react-error-overlay'),
  51.     // Finally, this is your app's code:
  52.     paths.appIndexJs,
  53.     // We include the app code last so that if there is a runtime error during
  54.     // initialization, it doesn't blow up the WebpackDevServer client, and
  55.     // changing JS code would still trigger a refresh.
  56.   ],
  57.   output: {
  58.     // Next line is not used in dev but WebpackDevServer crashes without it:
  59.     path: paths.appBuild,
  60.     // Add /* filename */ comments to generated require()s in the output.
  61.     pathinfo: true,
  62.     // This does not produce a real file. It's just the virtual path that is
  63.     // served by WebpackDevServer in development. This is the JS bundle
  64.     // containing code from all our entry points, and the Webpack runtime.
  65.     filename: 'static/js/bundle.js',
  66.     // There are also additional JS chunk files if you use code splitting.
  67.     chunkFilename: 'static/js/[name].chunk.js',
  68.     // This is the URL that app is served from. We use "/" in development.
  69.     publicPath: publicPath,
  70.     // Point sourcemap entries to original disk location
  71.     devtoolModuleFilenameTemplate: info =>
  72.       path.resolve(info.absoluteResourcePath),
  73.   },
  74.   resolve: {
  75.     // This allows you to set a fallback for where Webpack should look for modules.
  76.     // We placed these paths second because we want `node_modules` to "win"
  77.     // if there are any conflicts. This matches Node resolution mechanism.
  78.     // https://github.com/facebookincubator/create-react-app/issues/253
  79.     modules: ['node_modules', paths.appNodeModules].concat(
  80.       // It is guaranteed to exist because we tweak it in `env.js`
  81.       process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
  82.     ),
  83.     // These are the reasonable defaults supported by the Node ecosystem.
  84.     // We also include JSX as a common component filename extension to support
  85.     // some tools, although we do not recommend using it, see:
  86.     // https://github.com/facebookincubator/create-react-app/issues/290
  87.     extensions: ['.js', '.json', '.jsx'],
  88.     alias: {
  89.      
  90.       // Support React Native Web
  91.       // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
  92.       'react-native': 'react-native-web',
  93.     },
  94.     plugins: [
  95.       // Prevents users from importing files from outside of src/ (or node_modules/).
  96.       // This often causes confusion because we only process files within src/ with babel.
  97.       // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
  98.       // please link the files into your node_modules/ and let module-resolution kick in.
  99.       // Make sure your source files are compiled, as they will not be processed in any way.
  100.       new ModuleScopePlugin(paths.appSrc),
  101.     ],
  102.   },
  103.   module: {
  104.     strictExportPresence: true,
  105.     rules: [
  106.       // TODO: Disable require.ensure as it's not a standard language feature.
  107.       // We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
  108.       // { parser: { requireEnsure: false } },
  109.  
  110.       // First, run the linter.
  111.       // It's important to do this before Babel processes the JS.
  112.       {
  113.         test: /\.(js|jsx)$/,
  114.         enforce: 'pre',
  115.         use: [
  116.           {
  117.             options: {
  118.               formatter: eslintFormatter,
  119.              
  120.             },
  121.             loader: require.resolve('eslint-loader'),
  122.           },
  123.         ],
  124.         include: paths.appSrc,
  125.       },
  126.       // ** ADDING/UPDATING LOADERS **
  127.       // The "file" loader handles all assets unless explicitly excluded.
  128.       // The `exclude` list *must* be updated with every change to loader extensions.
  129.       // When adding a new loader, you must add its `test`
  130.       // as a new entry in the `exclude` list for "file" loader.
  131.  
  132.       // "file" loader makes sure those assets get served by WebpackDevServer.
  133.       // When you `import` an asset, you get its (virtual) filename.
  134.       // In production, they would get copied to the `build` folder.
  135.       {
  136.         exclude: [
  137.           /\.html$/,
  138.           /\.(js|jsx)$/,
  139.           /\.css$/,
  140.           /\.json$/,
  141.           /\.bmp$/,
  142.           /\.gif$/,
  143.           /\.jpe?g$/,
  144.           /\.png$/,
  145.         ],
  146.         loader: require.resolve('file-loader'),
  147.         options: {
  148.           name: 'static/media/[name].[hash:8].[ext]',
  149.         },
  150.       },
  151.       // "url" loader works like "file" loader except that it embeds assets
  152.       // smaller than specified limit in bytes as data URLs to avoid requests.
  153.       // A missing `test` is equivalent to a match.
  154.       {
  155.         test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
  156.         loader: require.resolve('url-loader'),
  157.         options: {
  158.           limit: 10000,
  159.           name: 'static/media/[name].[hash:8].[ext]',
  160.         },
  161.       },
  162.       // Process JS with Babel.
  163.       {
  164.         test: /\.(js|jsx)$/,
  165.         include: paths.appSrc,
  166.         loader: require.resolve('babel-loader'),
  167.         options: {
  168.          
  169.           // This is a feature of `babel-loader` for webpack (not Babel itself).
  170.           // It enables caching results in ./node_modules/.cache/babel-loader/
  171.           // directory for faster rebuilds.
  172.           cacheDirectory: true,
  173.         },
  174.       },
  175.       // "postcss" loader applies autoprefixer to our CSS.
  176.       // "css" loader resolves paths in CSS and adds assets as dependencies.
  177.       // "style" loader turns CSS into JS modules that inject <style> tags.
  178.       // In production, we use a plugin to extract that CSS to a file, but
  179.       // in development "style" loader enables hot editing of CSS.
  180.       {
  181.         test: /\.css$/,
  182.         use: [
  183.           require.resolve('style-loader'),
  184.           {
  185.             loader: require.resolve('css-loader'),
  186.             options: {
  187.               importLoaders: 1,
  188.             },
  189.           },
  190.           {
  191.             loader: require.resolve('postcss-loader'),
  192.             options: {
  193.               ident: 'postcss', // https://webpack.js.org/guides/migrating/#complex-options
  194.               plugins: () => [
  195.                 require('postcss-flexbugs-fixes'),
  196.                 autoprefixer({
  197.                   browsers: [
  198.                     '>1%',
  199.                     'last 4 versions',
  200.                     'Firefox ESR',
  201.                     'not ie < 9', // React doesn't support IE8 anyway
  202.                   ],
  203.                   flexbox: 'no-2009',
  204.                 }),
  205.               ],
  206.             },
  207.           },
  208.         ],
  209.       },
  210.       // ** STOP ** Are you adding a new loader?
  211.       // Remember to add the new extension(s) to the "file" loader exclusion list.
  212.     ],
  213.   },
  214.   plugins: [
  215.     // Makes some environment variables available in index.html.
  216.     // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
  217.     // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
  218.     // In development, this will be an empty string.
  219.     new InterpolateHtmlPlugin(env.raw),
  220.     // Generates an `index.html` file with the <script> injected.
  221.     new HtmlWebpackPlugin({
  222.       inject: true,
  223.       template: paths.appHtml,
  224.     }),
  225.     // Makes some environment variables available to the JS code, for example:
  226.     // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
  227.     new webpack.DefinePlugin(env.stringified),
  228.     // This is necessary to emit hot updates (currently CSS only):
  229.     new webpack.HotModuleReplacementPlugin(),
  230.     // Watcher doesn't work well if you mistype casing in a path so we use
  231.     // a plugin that prints an error when you attempt to do this.
  232.     // See https://github.com/facebookincubator/create-react-app/issues/240
  233.     new CaseSensitivePathsPlugin(),
  234.     // If you require a missing module and then `npm install` it, you still have
  235.     // to restart the development server for Webpack to discover it. This plugin
  236.     // makes the discovery automatic so you don't have to restart.
  237.     // See https://github.com/facebookincubator/create-react-app/issues/186
  238.     new WatchMissingNodeModulesPlugin(paths.appNodeModules),
  239.     // Moment.js is an extremely popular library that bundles large locale files
  240.     // by default due to how Webpack interprets its code. This is a practical
  241.     // solution that requires the user to opt into importing specific locales.
  242.     // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
  243.     // You can remove this if you don't use Moment.js:
  244.     new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
  245.   ],
  246.   // Some libraries import Node modules but don't use them in the browser.
  247.   // Tell Webpack to provide empty mocks for them so importing them works.
  248.   node: {
  249.     fs: 'empty',
  250.     net: 'empty',
  251.     tls: 'empty',
  252.   },
  253.   // Turn off performance hints during development because we don't do any
  254.   // splitting or minification in interest of speed. These warnings become
  255.   // cumbersome.
  256.   performance: {
  257.     hints: false,
  258.   },
  259. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement