9
9
'use strict' ;
10
10
11
11
const fs = require ( 'fs' ) ;
12
+ const isWsl = require ( 'is-wsl' ) ;
12
13
const path = require ( 'path' ) ;
13
14
const webpack = require ( 'webpack' ) ;
14
15
const resolve = require ( 'resolve' ) ;
@@ -27,13 +28,15 @@ const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeM
27
28
const ModuleScopePlugin = require ( 'react-dev-utils/ModuleScopePlugin' ) ;
28
29
const getCSSModuleLocalIdent = require ( 'react-dev-utils/getCSSModuleLocalIdent' ) ;
29
30
const paths = require ( './paths' ) ;
31
+ const modules = require ( './modules' ) ;
30
32
const getClientEnvironment = require ( './env' ) ;
31
33
const ModuleNotFoundPlugin = require ( 'react-dev-utils/ModuleNotFoundPlugin' ) ;
32
34
const ForkTsCheckerWebpackPlugin = require ( 'react-dev-utils/ForkTsCheckerWebpackPlugin' ) ;
33
35
const typescriptFormatter = require ( 'react-dev-utils/typescriptFormatter' ) ;
34
36
// @remove -on-eject-begin
35
37
const getCacheIdentifier = require ( 'react-dev-utils/getCacheIdentifier' ) ;
36
38
// @remove -on-eject-end
39
+ const postcssNormalize = require ( 'postcss-normalize' ) ;
37
40
38
41
// Source maps are resource heavy and can cause out of memory issue for large source files.
39
42
const shouldUseSourceMap = process . env . GENERATE_SOURCEMAP !== 'false' ;
@@ -81,10 +84,7 @@ module.exports = function(webpackEnv) {
81
84
isEnvDevelopment && require . resolve ( 'style-loader' ) ,
82
85
isEnvProduction && {
83
86
loader : MiniCssExtractPlugin . loader ,
84
- options : Object . assign (
85
- { } ,
86
- shouldUseRelativeAssetPaths ? { publicPath : '../../' } : undefined
87
- ) ,
87
+ options : shouldUseRelativeAssetPaths ? { publicPath : '../../' } : { } ,
88
88
} ,
89
89
{
90
90
loader : require . resolve ( 'css-loader' ) ,
@@ -107,6 +107,10 @@ module.exports = function(webpackEnv) {
107
107
} ,
108
108
stage : 3 ,
109
109
} ) ,
110
+ // Adds PostCSS Normalize as the reset css with default options,
111
+ // so that it honors browserslist config in package.json
112
+ // which in turn let's users customize the target behavior as per their needs.
113
+ postcssNormalize ( ) ,
110
114
] ,
111
115
sourceMap : isEnvProduction && shouldUseSourceMap ,
112
116
} ,
@@ -163,6 +167,8 @@ module.exports = function(webpackEnv) {
163
167
filename : isEnvProduction
164
168
? 'static/js/[name].[contenthash:8].js'
165
169
: isEnvDevelopment && 'static/js/bundle.js' ,
170
+ // TODO: remove this when upgrading to webpack 5
171
+ futureEmitAssets : true ,
166
172
// There are also additional JS chunk files if you use code splitting.
167
173
chunkFilename : isEnvProduction
168
174
? 'static/js/[name].[contenthash:8].chunk.js'
@@ -220,7 +226,9 @@ module.exports = function(webpackEnv) {
220
226
} ,
221
227
// Use multi-process parallel running to improve the build speed
222
228
// Default number of concurrent runs: os.cpus().length - 1
223
- parallel : true ,
229
+ // Disabled on WSL (Windows Subsystem for Linux) due to an issue with Terser
230
+ // https://github.com/webpack-contrib/terser-webpack-plugin/issues/21
231
+ parallel : ! isWsl ,
224
232
// Enable file caching
225
233
cache : true ,
226
234
sourceMap : shouldUseSourceMap ,
@@ -258,9 +266,8 @@ module.exports = function(webpackEnv) {
258
266
// We placed these paths second because we want `node_modules` to "win"
259
267
// if there are any conflicts. This matches Node resolution mechanism.
260
268
// https://github.com/facebook/create-react-app/issues/253
261
- modules : [ 'node_modules' ] . concat (
262
- // It is guaranteed to exist because we tweak it in `env.js`
263
- process . env . NODE_PATH . split ( path . delimiter ) . filter ( Boolean )
269
+ modules : [ 'node_modules' , paths . appNodeModules ] . concat (
270
+ modules . additionalModulePaths || [ ]
264
271
) ,
265
272
// These are the reasonable defaults supported by the Node ecosystem.
266
273
// We also include JSX as a common component filename extension to support
@@ -304,7 +311,7 @@ module.exports = function(webpackEnv) {
304
311
// First, run the linter.
305
312
// It's important to do this before Babel processes the JS.
306
313
{
307
- test : / \. ( j s | m j s | j s x ) $ / ,
314
+ test : / \. ( j s | m j s | j s x | t s | t s x ) $ / ,
308
315
enforce : 'pre' ,
309
316
use : [
310
317
{
@@ -588,6 +595,16 @@ module.exports = function(webpackEnv) {
588
595
new ManifestPlugin ( {
589
596
fileName : 'asset-manifest.json' ,
590
597
publicPath : publicPath ,
598
+ generate : ( seed , files ) => {
599
+ const manifestFiles = files . reduce ( function ( manifest , file ) {
600
+ manifest [ file . name ] = file . path ;
601
+ return manifest ;
602
+ } , seed ) ;
603
+
604
+ return {
605
+ files : manifestFiles ,
606
+ } ;
607
+ } ,
591
608
} ) ,
592
609
// Moment.js is an extremely popular library that bundles large locale files
593
610
// by default due to how Webpack interprets its code. This is a practical
@@ -620,10 +637,15 @@ module.exports = function(webpackEnv) {
620
637
async : isEnvDevelopment ,
621
638
useTypescriptIncrementalApi : true ,
622
639
checkSyntacticErrors : true ,
640
+ resolveModuleNameModule : process . versions . pnp
641
+ ? `${ __dirname } /pnpTs.js`
642
+ : undefined ,
643
+ resolveTypeReferenceDirectiveModule : process . versions . pnp
644
+ ? `${ __dirname } /pnpTs.js`
645
+ : undefined ,
623
646
tsconfig : paths . appTsConfig ,
624
647
reportFiles : [
625
648
'**' ,
626
- '!**/*.json' ,
627
649
'!**/__tests__/**' ,
628
650
'!**/?(*.)(spec|test).*' ,
629
651
'!**/src/setupProxy.*' ,
@@ -642,6 +664,7 @@ module.exports = function(webpackEnv) {
642
664
dgram : 'empty' ,
643
665
dns : 'mock' ,
644
666
fs : 'empty' ,
667
+ http2 : 'empty' ,
645
668
net : 'empty' ,
646
669
tls : 'empty' ,
647
670
child_process : 'empty' ,
0 commit comments