Skip to content

Commit 674a5b8

Browse files
committed
3.0.1 all changes applied, not tested
1 parent df7601a commit 674a5b8

File tree

6 files changed

+710
-628
lines changed

6 files changed

+710
-628
lines changed

packages/react-scripts/config/webpack.config.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'use strict';
1010

1111
const fs = require('fs');
12+
const isWsl = require('is-wsl');
1213
const path = require('path');
1314
const webpack = require('webpack');
1415
const resolve = require('resolve');
@@ -27,13 +28,15 @@ const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeM
2728
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2829
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
2930
const paths = require('./paths');
31+
const modules = require('./modules');
3032
const getClientEnvironment = require('./env');
3133
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
3234
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
3335
const typescriptFormatter = require('react-dev-utils/typescriptFormatter');
3436
// @remove-on-eject-begin
3537
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier');
3638
// @remove-on-eject-end
39+
const postcssNormalize = require('postcss-normalize');
3740

3841
// Source maps are resource heavy and can cause out of memory issue for large source files.
3942
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
@@ -81,10 +84,7 @@ module.exports = function(webpackEnv) {
8184
isEnvDevelopment && require.resolve('style-loader'),
8285
isEnvProduction && {
8386
loader: MiniCssExtractPlugin.loader,
84-
options: Object.assign(
85-
{},
86-
shouldUseRelativeAssetPaths ? { publicPath: '../../' } : undefined
87-
),
87+
options: shouldUseRelativeAssetPaths ? { publicPath: '../../' } : {},
8888
},
8989
{
9090
loader: require.resolve('css-loader'),
@@ -107,6 +107,10 @@ module.exports = function(webpackEnv) {
107107
},
108108
stage: 3,
109109
}),
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(),
110114
],
111115
sourceMap: isEnvProduction && shouldUseSourceMap,
112116
},
@@ -163,6 +167,8 @@ module.exports = function(webpackEnv) {
163167
filename: isEnvProduction
164168
? 'static/js/[name].[contenthash:8].js'
165169
: isEnvDevelopment && 'static/js/bundle.js',
170+
// TODO: remove this when upgrading to webpack 5
171+
futureEmitAssets: true,
166172
// There are also additional JS chunk files if you use code splitting.
167173
chunkFilename: isEnvProduction
168174
? 'static/js/[name].[contenthash:8].chunk.js'
@@ -220,7 +226,9 @@ module.exports = function(webpackEnv) {
220226
},
221227
// Use multi-process parallel running to improve the build speed
222228
// 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,
224232
// Enable file caching
225233
cache: true,
226234
sourceMap: shouldUseSourceMap,
@@ -258,9 +266,8 @@ module.exports = function(webpackEnv) {
258266
// We placed these paths second because we want `node_modules` to "win"
259267
// if there are any conflicts. This matches Node resolution mechanism.
260268
// 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 || []
264271
),
265272
// These are the reasonable defaults supported by the Node ecosystem.
266273
// We also include JSX as a common component filename extension to support
@@ -304,7 +311,7 @@ module.exports = function(webpackEnv) {
304311
// First, run the linter.
305312
// It's important to do this before Babel processes the JS.
306313
{
307-
test: /\.(js|mjs|jsx)$/,
314+
test: /\.(js|mjs|jsx|ts|tsx)$/,
308315
enforce: 'pre',
309316
use: [
310317
{
@@ -588,6 +595,16 @@ module.exports = function(webpackEnv) {
588595
new ManifestPlugin({
589596
fileName: 'asset-manifest.json',
590597
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+
},
591608
}),
592609
// Moment.js is an extremely popular library that bundles large locale files
593610
// by default due to how Webpack interprets its code. This is a practical
@@ -620,10 +637,15 @@ module.exports = function(webpackEnv) {
620637
async: isEnvDevelopment,
621638
useTypescriptIncrementalApi: true,
622639
checkSyntacticErrors: true,
640+
resolveModuleNameModule: process.versions.pnp
641+
? `${__dirname}/pnpTs.js`
642+
: undefined,
643+
resolveTypeReferenceDirectiveModule: process.versions.pnp
644+
? `${__dirname}/pnpTs.js`
645+
: undefined,
623646
tsconfig: paths.appTsConfig,
624647
reportFiles: [
625648
'**',
626-
'!**/*.json',
627649
'!**/__tests__/**',
628650
'!**/?(*.)(spec|test).*',
629651
'!**/src/setupProxy.*',
@@ -642,6 +664,7 @@ module.exports = function(webpackEnv) {
642664
dgram: 'empty',
643665
dns: 'mock',
644666
fs: 'empty',
667+
http2: 'empty',
645668
net: 'empty',
646669
tls: 'empty',
647670
child_process: 'empty',

0 commit comments

Comments
 (0)