1
1
'use strict' ;
2
2
3
- const path = require ( 'path' ) ;
4
3
const autoprefixer = require ( 'autoprefixer' ) ;
5
- const HotModuleReplacementPlugin = require ( 'webpack/lib/HotModuleReplacementPlugin' ) ;
6
- const DefinePlugin = require ( 'webpack/lib/DefinePlugin' ) ;
7
- const NamedModulesPlugin = require ( 'webpack/lib/NamedModulesPlugin' ) ;
8
- const InterpolateHtmlPlugin = require ( 'react-dev-utils/InterpolateHtmlPlugin' ) ;
4
+ const path = require ( 'path' ) ;
5
+ const webpack = require ( 'webpack' ) ;
9
6
const HtmlWebpackPlugin = require ( 'html-webpack-plugin' ) ;
7
+ const CaseSensitivePathsPlugin = require ( 'case-sensitive-paths-webpack-plugin' ) ;
8
+ const InterpolateHtmlPlugin = require ( 'react-dev-utils/InterpolateHtmlPlugin' ) ;
10
9
const getClientEnvironment = require ( './env' ) ;
11
10
const paths = require ( '../config/paths' ) ;
12
11
@@ -20,10 +19,20 @@ const publicUrl = '';
20
19
// Get environment variables to inject into our app.
21
20
const env = getClientEnvironment ( publicUrl ) ;
22
21
22
+ // This is the development configuration.
23
+ // It is focused on developer experience and fast rebuilds.
24
+ // The production configuration is different and lives in a separate file.
23
25
module . exports = {
26
+ mode : 'development' ,
27
+ // You may want 'eval' instead if you prefer to see the compiled output in DevTools.
28
+ // See the discussion in https://github.com/facebook/create-react-app/issues/343.
24
29
devtool : 'cheap-module-source-map' ,
25
-
30
+ // These are the "entry points" to our application.
31
+ // This means they will be the "root" imports that are included in JS bundle.
32
+ // The first two entry points enable "hot" CSS and auto-refreshes for JS.
26
33
entry : [
34
+ // We ship a few polyfills by default:
35
+ require . resolve ( './polyfills' ) ,
27
36
// Include an alternative client for WebpackDevServer. A client's job is to
28
37
// connect to WebpackDevServer by a socket and get notified about changes.
29
38
// When you save a file, the client will either apply hot updates (in case
@@ -42,34 +51,44 @@ module.exports = {
42
51
43
52
paths . appIndexJs
44
53
] ,
45
-
46
54
output : {
55
+ // Add /* filename */ comments to generated require()s in the output.
47
56
pathinfo : true ,
48
-
49
- // The build folder.
50
- path : paths . appBuild ,
51
-
52
57
// This does not produce a real file. It's just the virtual path that is
53
58
// served by WebpackDevServer in development. This is the JS bundle
54
59
// containing code from all our entry points, and the Webpack runtime.
55
60
filename : 'static/js/bundle.js' ,
56
-
61
+ // There are also additional JS chunk files if you use code splitting.
62
+ chunkFilename : 'static/js/[name].chunk.js' ,
63
+ // This is the URL that app is served from. We use "/" in development.
57
64
publicPath : publicPath ,
58
-
59
65
// Point sourcemap entries to original disk location (format as URL on Windows)
60
66
devtoolModuleFilenameTemplate : info =>
61
67
path . resolve ( info . absoluteResourcePath ) . replace ( / \\ / g, '/' )
62
68
} ,
63
-
69
+ optimization : {
70
+ // Automatically split vendor and commons
71
+ // https://twitter.com/wSokra/status/969633336732905474
72
+ // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
73
+ splitChunks : {
74
+ chunks : 'all' ,
75
+ name : 'vendors'
76
+ } ,
77
+ // Keep the runtime chunk seperated to enable long term caching
78
+ // https://twitter.com/wSokra/status/969679223278505985
79
+ runtimeChunk : true
80
+ } ,
64
81
resolve : {
65
82
modules : [ 'node_modules' ] ,
66
83
extensions : [ '.js' , '.elm' ]
67
84
} ,
68
-
69
85
module : {
70
86
noParse : / \. e l m $ / ,
71
-
87
+ strictExportPresence : true ,
72
88
rules : [
89
+ // Disable require.ensure as it's not a standard language feature.
90
+ { parser : { requireEnsure : false } } ,
91
+
73
92
{
74
93
test : / \. j s $ / ,
75
94
exclude : [ / [ / \\ \\ ] e l m - s t u f f [ / \\ \\ ] / , / [ / \\ \\ ] n o d e _ m o d u l e s [ / \\ \\ ] / ] ,
@@ -169,8 +188,9 @@ module.exports = {
169
188
// "style" loader turns CSS into JS modules that inject <style> tags.
170
189
// In production, we use a plugin to extract that CSS to a file, but
171
190
// in development "style" loader enables hot editing of CSS.
191
+ // By default we support CSS Modules with the extension .module.css
172
192
{
173
- test : / \. c s s $ / ,
193
+ test : / \. c s s / ,
174
194
use : [
175
195
require . resolve ( 'style-loader' ) ,
176
196
{
@@ -180,17 +200,18 @@ module.exports = {
180
200
}
181
201
} ,
182
202
{
203
+ // Options for PostCSS as we reference these options twice
204
+ // Adds vendor prefixing based on your specified browser support in
205
+ // package.json
183
206
loader : require . resolve ( 'postcss-loader' ) ,
184
207
options : {
185
- ident : 'postcss' , // https://webpack.js.org/guides/migrating/#complex-options
208
+ // Necessary for external CSS imports to work
209
+ // https://github.com/facebook/create-react-app/issues/2677
210
+ ident : 'postcss' ,
186
211
plugins : ( ) => [
212
+ require ( 'postcss-flexbugs-fixes' ) ,
187
213
autoprefixer ( {
188
- browsers : [
189
- '>1%' ,
190
- 'last 4 versions' ,
191
- 'Firefox ESR' ,
192
- 'not ie < 9'
193
- ]
214
+ flexbox : 'no-2009'
194
215
} )
195
216
]
196
217
}
@@ -217,20 +238,26 @@ module.exports = {
217
238
}
218
239
]
219
240
} ,
220
-
221
241
plugins : [
222
- new DefinePlugin ( env . stringified ) ,
223
-
224
- new InterpolateHtmlPlugin ( env . raw ) ,
225
-
242
+ // Generates an `index.html` file with the <script> injected.
226
243
new HtmlWebpackPlugin ( {
227
244
inject : true ,
228
245
template : paths . appHtml
229
246
} ) ,
230
-
231
- new HotModuleReplacementPlugin ( ) ,
232
-
233
- new NamedModulesPlugin ( )
247
+ // Makes some environment variables available in index.html.
248
+ // The public URL is available as %PUBLIC_URL% in index.html, e.g.:
249
+ // <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
250
+ // In development, this will be an empty string.
251
+ new InterpolateHtmlPlugin ( env . raw ) ,
252
+ // Makes some environment variables available to the JS code, for example:
253
+ // if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
254
+ new webpack . DefinePlugin ( env . stringified ) ,
255
+ // This is necessary to emit hot updates (currently CSS only):
256
+ new webpack . HotModuleReplacementPlugin ( ) ,
257
+ // Watcher doesn't work well if you mistype casing in a path so we use
258
+ // a plugin that prints an error when you attempt to do this.
259
+ // See https://github.com/facebook/create-react-app/issues/240
260
+ new CaseSensitivePathsPlugin ( )
234
261
] ,
235
262
236
263
// Some libraries import Node modules but don't use them in the browser.
@@ -241,5 +268,8 @@ module.exports = {
241
268
net : 'empty' ,
242
269
tls : 'empty' ,
243
270
child_process : 'empty'
244
- }
271
+ } ,
272
+ // Turn off performance processing because we utilize
273
+ // our own hints via the FileSizeReporter
274
+ performance : false
245
275
} ;
0 commit comments