1 | // @remove-on-eject-begin
|
2 | /**
|
3 | * Copyright (c) 2015-present, Facebook, Inc.
|
4 | * All rights reserved.
|
5 | *
|
6 | * This source code is licensed under the BSD-style license found in the
|
7 | * LICENSE file in the root directory of this source tree. An additional grant
|
8 | * of patent rights can be found in the PATENTS file in the same directory.
|
9 | */
|
10 | // @remove-on-eject-end
|
11 | ;
|
12 |
|
13 | const autoprefixer = require('autoprefixer');
|
14 | const path = require('path');
|
15 | const webpack = require('webpack');
|
16 | const HtmlWebpackPlugin = require('html-webpack-plugin');
|
17 | const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
18 | const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
19 | const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
20 | const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
21 | const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
22 | const getClientEnvironment = require('./env');
|
23 | const paths = require('./paths');
|
24 | const AppVersionEnv = require('./appVersionEnv');
|
25 | const { CheckerPlugin } = require('awesome-typescript-loader');
|
26 |
|
27 | // Webpack uses `publicPath` to determine where the app is being served from.
|
28 | // In development, we always serve from the root. This makes config easier.
|
29 | const publicPath = '/';
|
30 | // `publicUrl` is just like `publicPath`, but we will provide it to our app
|
31 | // as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
32 | // Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
33 | const publicUrl = '';
|
34 | // Get environment variables to inject into our app.
|
35 | const env = getClientEnvironment(publicUrl);
|
36 |
|
37 | // This is the development configuration.
|
38 | // It is focused on developer experience and fast rebuilds.
|
39 | // The production configuration is different and lives in a separate file.
|
40 | module.exports = {
|
41 | // You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
42 | // See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
43 | //devtool: 'cheap-module-source-map',
|
44 | devtool: 'inline-source-map',
|
45 | // These are the "entry points" to our application.
|
46 | // This means they will be the "root" imports that are included in JS bundle.
|
47 | // The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
48 | entry: [
|
49 | // Include an alternative client for WebpackDevServer. A client's job is to
|
50 | // connect to WebpackDevServer by a socket and get notified about changes.
|
51 | // When you save a file, the client will either apply hot updates (in case
|
52 | // of CSS changes), or refresh the page (in case of JS changes). When you
|
53 | // make a syntax error, this client will display a syntax error overlay.
|
54 | // Note: instead of the default WebpackDevServer client, we use a custom one
|
55 | // to bring better experience for Create React App users. You can replace
|
56 | // the line below with these two lines if you prefer the stock client:
|
57 | // require.resolve('webpack-dev-server/client') + '?/',
|
58 | // require.resolve('webpack/hot/dev-server'),
|
59 | require.resolve('react-dev-utils/webpackHotDevClient'),
|
60 | // We ship a few polyfills by default:
|
61 | require.resolve('./polyfills'),
|
62 | // Errors should be considered fatal in development
|
63 | require.resolve('react-error-overlay'),
|
64 | // Finally, this is your app's code:
|
65 | paths.appIndexJs,
|
66 | // We include the app code last so that if there is a runtime error during
|
67 | // initialization, it doesn't blow up the WebpackDevServer client, and
|
68 | // changing JS code would still trigger a refresh.
|
69 | ],
|
70 | output: {
|
71 | // Next line is not used in dev but WebpackDevServer crashes without it:
|
72 | path: paths.appBuild,
|
73 | // Add /* filename */ comments to generated require()s in the output.
|
74 | pathinfo: true,
|
75 | // This does not produce a real file. It's just the virtual path that is
|
76 | // served by WebpackDevServer in development. This is the JS bundle
|
77 | // containing code from all our entry points, and the Webpack runtime.
|
78 | filename: 'static/js/bundle.js',
|
79 | // There are also additional JS chunk files if you use code splitting.
|
80 | chunkFilename: 'static/js/[name].chunk.js',
|
81 | // This is the URL that app is served from. We use "/" in development.
|
82 | publicPath: publicPath,
|
83 | // Point sourcemap entries to original disk location (format as URL on Windows)
|
84 | devtoolModuleFilenameTemplate: info =>
|
85 | path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
86 | },
|
87 | resolve: {
|
88 | // This allows you to set a fallback for where Webpack should look for modules.
|
89 | // We placed these paths second because we want `node_modules` to "win"
|
90 | // if there are any conflicts. This matches Node resolution mechanism.
|
91 | // https://github.com/facebookincubator/create-react-app/issues/253
|
92 | modules: ['node_modules', paths.appNodeModules].concat(
|
93 | // It is guaranteed to exist because we tweak it in `env.js`
|
94 | process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
95 | ),
|
96 | // These are the reasonable defaults supported by the Node ecosystem.
|
97 | // We also include JSX as a common component filename extension to support
|
98 | // some tools, although we do not recommend using it, see:
|
99 | // https://github.com/facebookincubator/create-react-app/issues/290
|
100 | // `web` extension prefixes have been added for better support
|
101 | // for React Native Web.
|
102 | extensions: ['.ts', '.tsx', '.web.js', '.js', '.json', '.web.jsx', '.jsx'],
|
103 | alias: {
|
104 | // @remove-on-eject-begin
|
105 | // Resolve Babel runtime relative to react-scripts.
|
106 | // It usually still works on npm 3 without this but it would be
|
107 | // unfortunate to rely on, as react-scripts could be symlinked,
|
108 | // and thus babel-runtime might not be resolvable from the source.
|
109 | 'babel-runtime': path.dirname(
|
110 | require.resolve('babel-runtime/package.json')
|
111 | ),
|
112 | // @remove-on-eject-end
|
113 | // Support React Native Web
|
114 | // https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
115 | 'react-native': 'react-native-web',
|
116 | },
|
117 | plugins: [
|
118 | // Prevents users from importing files from outside of src/ (or node_modules/).
|
119 | // This often causes confusion because we only process files within src/ with babel.
|
120 | // To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
121 | // please link the files into your node_modules/ and let module-resolution kick in.
|
122 | // Make sure your source files are compiled, as they will not be processed in any way.
|
123 | // new ModuleScopePlugin(paths.appSrc),
|
124 | ],
|
125 | },
|
126 | module: {
|
127 | strictExportPresence: true,
|
128 | rules: [
|
129 | // TODO: Disable require.ensure as it's not a standard language feature.
|
130 | // We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
131 | // { parser: { requireEnsure: false } },
|
132 |
|
133 | // First, run the linter.
|
134 | // It's important to do this before Babel processes the JS.
|
135 | // {
|
136 | // test: /\.(js|jsx)$/,
|
137 | // enforce: 'pre',
|
138 | // use: [
|
139 | // {
|
140 | // options: {
|
141 | // formatter: eslintFormatter,
|
142 | // // @remove-on-eject-begin
|
143 | // baseConfig: {
|
144 | // extends: [require.resolve('eslint-config-react-app')],
|
145 | // },
|
146 | // ignore: false,
|
147 | // useEslintrc: false,
|
148 | // // @remove-on-eject-end
|
149 | // },
|
150 | // loader: require.resolve('eslint-loader'),
|
151 | // },
|
152 | // ],
|
153 | // include: paths.appSrc,
|
154 | // },
|
155 | // ** ADDING/UPDATING LOADERS **
|
156 | // The "file" loader handles all assets unless explicitly excluded.
|
157 | // The `exclude` list *must* be updated with every change to loader extensions.
|
158 | // When adding a new loader, you must add its `test`
|
159 | // as a new entry in the `exclude` list for "file" loader.
|
160 |
|
161 | // "file" loader makes sure those assets get served by WebpackDevServer.
|
162 | // When you `import` an asset, you get its (virtual) filename.
|
163 | // In production, they would get copied to the `build` folder.
|
164 | {
|
165 | exclude: [
|
166 | /\.html$/,
|
167 | /\.(ts|tsx|js|jsx)$/,
|
168 | /\.css$/,
|
169 | /\.scss$/,
|
170 | /\.json$/,
|
171 | /\.bmp$/,
|
172 | /\.gif$/,
|
173 | /\.jpe?g$/,
|
174 | /\.png$/,
|
175 | ],
|
176 | loader: require.resolve('file-loader'),
|
177 | options: {
|
178 | name: 'static/media/[name].[hash:8].[ext]',
|
179 | },
|
180 | },
|
181 | // "url" loader works like "file" loader except that it embeds assets
|
182 | // smaller than specified limit in bytes as data URLs to avoid requests.
|
183 | // A missing `test` is equivalent to a match.
|
184 | {
|
185 | test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
186 | loader: require.resolve('url-loader'),
|
187 | options: {
|
188 | limit: 10000,
|
189 | name: 'static/media/[name].[hash:8].[ext]',
|
190 | },
|
191 | },
|
192 | // Process JS with Babel.
|
193 | // {
|
194 | // test: /\.(js|jsx)$/,
|
195 | // include: paths.appSrc,
|
196 | // loader: require.resolve('babel-loader'),
|
197 | // options: {
|
198 | // // @remove-on-eject-begin
|
199 | // babelrc: false,
|
200 | // presets: [require.resolve('babel-preset-react-app')],
|
201 | // // @remove-on-eject-end
|
202 | // // This is a feature of `babel-loader` for webpack (not Babel itself).
|
203 | // // It enables caching results in ./node_modules/.cache/babel-loader/
|
204 | // // directory for faster rebuilds.
|
205 | // cacheDirectory: true,
|
206 | // },
|
207 | // },
|
208 | {
|
209 | test: /\.(ts|tsx)$/,
|
210 | include: paths.appSrc,
|
211 | loader: require.resolve('awesome-typescript-loader'),
|
212 | options: {
|
213 | useBabel: true,
|
214 | useCache: true,
|
215 | babelOptions: {
|
216 | presets: [require.resolve('babel-preset-react-app')]
|
217 | }
|
218 | },
|
219 | },
|
220 | // "postcss" loader applies autoprefixer to our CSS.
|
221 | // "css" loader resolves paths in CSS and adds assets as dependencies.
|
222 | // "style" loader turns CSS into JS modules that inject <style> tags.
|
223 | // In production, we use a plugin to extract that CSS to a file, but
|
224 | // in development "style" loader enables hot editing of CSS.
|
225 | {
|
226 | test: /\.css$/,
|
227 | use: [
|
228 | require.resolve('style-loader'),
|
229 | {
|
230 | loader: require.resolve('css-loader'),
|
231 | options: {
|
232 | importLoaders: 1,
|
233 | },
|
234 | },
|
235 | {
|
236 | loader: require.resolve('postcss-loader'),
|
237 | options: {
|
238 | // Necessary for external CSS imports to work
|
239 | // https://github.com/facebookincubator/create-react-app/issues/2677
|
240 | ident: 'postcss',
|
241 | plugins: () => [
|
242 | require('postcss-flexbugs-fixes'),
|
243 | autoprefixer({
|
244 | browsers: [
|
245 | '>1%',
|
246 | 'last 4 versions',
|
247 | 'Firefox ESR',
|
248 | 'not ie < 9', // React doesn't support IE8 anyway
|
249 | ],
|
250 | flexbox: 'no-2009',
|
251 | }),
|
252 | ],
|
253 | },
|
254 | },
|
255 | ],
|
256 | },
|
257 | {
|
258 | test: /\.scss$/,
|
259 | exclude: /\.global\.scss$/,
|
260 | use: [
|
261 | require.resolve('style-loader'),
|
262 | {
|
263 | loader: require.resolve('css-loader'),
|
264 | options: {
|
265 | importLoaders: 2,
|
266 | modules: true,
|
267 | localIdentName: "[local]___[hash:base64:5]"
|
268 | },
|
269 | },
|
270 | {
|
271 | loader: require.resolve('postcss-loader'),
|
272 | options: {
|
273 | // Necessary for external CSS imports to work
|
274 | // https://github.com/facebookincubator/create-react-app/issues/2677
|
275 | ident: 'postcss',
|
276 | plugins: () => [
|
277 | require('postcss-flexbugs-fixes'),
|
278 | autoprefixer({
|
279 | browsers: [
|
280 | '>1%',
|
281 | 'last 4 versions',
|
282 | 'Firefox ESR',
|
283 | 'not ie < 9', // React doesn't support IE8 anyway
|
284 | ],
|
285 | flexbox: 'no-2009',
|
286 | }),
|
287 | ],
|
288 | },
|
289 | },
|
290 | {
|
291 | loader: require.resolve('sass-loader')
|
292 | }
|
293 | ],
|
294 | },
|
295 | {
|
296 | test: /\.global\.scss$/,
|
297 | use: [
|
298 | require.resolve('style-loader'),
|
299 | {
|
300 | loader: require.resolve('css-loader'),
|
301 | options: {
|
302 | importLoaders: 2
|
303 | },
|
304 | },
|
305 | {
|
306 | loader: require.resolve('postcss-loader'),
|
307 | options: {
|
308 | // Necessary for external CSS imports to work
|
309 | // https://github.com/facebookincubator/create-react-app/issues/2677
|
310 | ident: 'postcss',
|
311 | plugins: () => [
|
312 | require('postcss-flexbugs-fixes'),
|
313 | autoprefixer({
|
314 | browsers: [
|
315 | '>1%',
|
316 | 'last 4 versions',
|
317 | 'Firefox ESR',
|
318 | 'not ie < 9', // React doesn't support IE8 anyway
|
319 | ],
|
320 | flexbox: 'no-2009',
|
321 | }),
|
322 | ],
|
323 | },
|
324 | },
|
325 | {
|
326 | loader: require.resolve('sass-loader')
|
327 | }
|
328 | ],
|
329 | },
|
330 | // ** STOP ** Are you adding a new loader?
|
331 | // Remember to add the new extension(s) to the "file" loader exclusion list.
|
332 | ],
|
333 | },
|
334 | plugins: [
|
335 | // For awesome-typescript-loader
|
336 | new CheckerPlugin(),
|
337 | // Makes some environment variables available in index.html.
|
338 | // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
339 | // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
340 | // In development, this will be an empty string.
|
341 | new InterpolateHtmlPlugin(env.raw),
|
342 | // Generates an `index.html` file with the <script> injected.
|
343 | new HtmlWebpackPlugin({
|
344 | inject: true,
|
345 | template: paths.appHtml,
|
346 | }),
|
347 | // Add module names to factory functions so they appear in browser profiler.
|
348 | new webpack.NamedModulesPlugin(),
|
349 | // Makes some environment variables available to the JS code, for example:
|
350 | // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
351 | new webpack.DefinePlugin(
|
352 | AppVersionEnv.extendEnvironment(
|
353 | env.stringified
|
354 | )
|
355 | ),
|
356 | // This is necessary to emit hot updates (currently CSS only):
|
357 | new webpack.HotModuleReplacementPlugin(),
|
358 | // Watcher doesn't work well if you mistype casing in a path so we use
|
359 | // a plugin that prints an error when you attempt to do this.
|
360 | // See https://github.com/facebookincubator/create-react-app/issues/240
|
361 | new CaseSensitivePathsPlugin(),
|
362 | // If you require a missing module and then `npm install` it, you still have
|
363 | // to restart the development server for Webpack to discover it. This plugin
|
364 | // makes the discovery automatic so you don't have to restart.
|
365 | // See https://github.com/facebookincubator/create-react-app/issues/186
|
366 | new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
367 | // Moment.js is an extremely popular library that bundles large locale files
|
368 | // by default due to how Webpack interprets its code. This is a practical
|
369 | // solution that requires the user to opt into importing specific locales.
|
370 | // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
371 | // You can remove this if you don't use Moment.js:
|
372 | new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
373 | // For defining app version
|
374 | AppVersionEnv.gitRevisionPlugin,
|
375 | ],
|
376 | // Some libraries import Node modules but don't use them in the browser.
|
377 | // Tell Webpack to provide empty mocks for them so importing them works.
|
378 | node: {
|
379 | dgram: 'empty',
|
380 | fs: 'empty',
|
381 | net: 'empty',
|
382 | tls: 'empty',
|
383 | },
|
384 | // Turn off performance hints during development because we don't do any
|
385 | // splitting or minification in interest of speed. These warnings become
|
386 | // cumbersome.
|
387 | performance: {
|
388 | hints: false,
|
389 | },
|
390 | };
|