Skip to content

Commit cb391c6

Browse files
committed
3.2.0 webpack.config changes
1 parent ff40f68 commit cb391c6

File tree

2 files changed

+89
-36
lines changed

2 files changed

+89
-36
lines changed

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

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ module.exports = function(webpackEnv) {
6666
const isEnvDevelopment = webpackEnv === 'development';
6767
const isEnvProduction = webpackEnv === 'production';
6868

69+
// Variable used for enabling profiling in Production
70+
// passed into alias object. Uses a flag if passed into the build command
71+
const isEnvProductionProfile =
72+
isEnvProduction && process.argv.includes('--profile');
73+
6974
// Webpack uses `publicPath` to determine where the app is being served from.
7075
// It requires a trailing slash, or the file assets will get an incorrect path.
7176
// In development, we always serve from the root. This makes config easier.
@@ -202,6 +207,9 @@ module.exports = function(webpackEnv) {
202207
// Prevents conflicts when multiple Webpack runtimes (from different apps)
203208
// are used on the same page.
204209
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
210+
// this defaults to 'window', but by setting it to 'this' then
211+
// module chunks which are built will work in web workers as well.
212+
globalObject: 'this',
205213
},
206214
optimization: {
207215
minimize: isEnvProduction,
@@ -234,6 +242,9 @@ module.exports = function(webpackEnv) {
234242
mangle: {
235243
safari10: true,
236244
},
245+
// Added for profiling in devtools
246+
keep_classnames: isEnvProductionProfile,
247+
keep_fnames: isEnvProductionProfile,
237248
output: {
238249
ecma: 5,
239250
comments: false,
@@ -303,6 +314,12 @@ module.exports = function(webpackEnv) {
303314
// Support React Native Web
304315
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
305316
'react-native': 'react-native-web',
317+
// Allows for better profiling with ReactDevTools
318+
...(isEnvProductionProfile && {
319+
'react-dom$': 'react-dom/profiling',
320+
'scheduler/tracing': 'scheduler/tracing-profiling',
321+
}),
322+
...(modules.webpackAliases || {}),
306323
},
307324
plugins: [
308325
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
@@ -342,25 +359,27 @@ module.exports = function(webpackEnv) {
342359
eslintPath: require.resolve('eslint'),
343360
resolvePluginsRelativeTo: __dirname,
344361
// @remove-on-eject-begin
362+
ignore: process.env.EXTEND_ESLINT === 'true',
345363
baseConfig: (() => {
346-
const eslintCli = new eslint.CLIEngine();
347-
let eslintConfig;
348-
try {
349-
eslintConfig = eslintCli.getConfigForFile(paths.appIndexJs);
350-
} catch (e) {
351-
// A config couldn't be found.
352-
}
353-
354364
// We allow overriding the config only if the env variable is set
355-
if (process.env.EXTEND_ESLINT === 'true' && eslintConfig) {
365+
if (process.env.EXTEND_ESLINT === 'true') {
366+
const eslintCli = new eslint.CLIEngine();
367+
let eslintConfig;
368+
try {
369+
eslintConfig = eslintCli.getConfigForFile(
370+
paths.appIndexJs
371+
);
372+
} catch (e) {
373+
console.error(e);
374+
process.exit(1);
375+
}
356376
return eslintConfig;
357377
} else {
358378
return {
359379
extends: [require.resolve('eslint-config-react-app')],
360380
};
361381
}
362382
})(),
363-
ignore: false,
364383
useEslintrc: false,
365384
// @remove-on-eject-end
366385
},
@@ -598,7 +617,7 @@ module.exports = function(webpackEnv) {
598617
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
599618
// Makes some environment variables available in index.html.
600619
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
601-
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
620+
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
602621
// In production, it will be an empty string unless you specify "homepage"
603622
// in `package.json`, in which case it will be the pathname of that URL.
604623
// In development, this will be an empty string.
@@ -631,20 +650,27 @@ module.exports = function(webpackEnv) {
631650
filename: 'static/css/[name].[contenthash:8].css',
632651
chunkFilename: 'static/css/[name].[contenthash:8].chunk.css',
633652
}),
634-
// Generate a manifest file which contains a mapping of all asset filenames
635-
// to their corresponding output file so that tools can pick it up without
636-
// having to parse `index.html`.
653+
// Generate an asset manifest file with the following content:
654+
// - "files" key: Mapping of all asset filenames to their corresponding
655+
// output file so that tools can pick it up without having to parse
656+
// `index.html`
657+
// - "entrypoints" key: Array of files which are included in `index.html`,
658+
// can be used to reconstruct the HTML if necessary
637659
new ManifestPlugin({
638660
fileName: 'asset-manifest.json',
639661
publicPath: publicPath,
640-
generate: (seed, files) => {
641-
const manifestFiles = files.reduce(function(manifest, file) {
662+
generate: (seed, files, entrypoints) => {
663+
const manifestFiles = files.reduce((manifest, file) => {
642664
manifest[file.name] = file.path;
643665
return manifest;
644666
}, seed);
667+
const entrypointFiles = entrypoints.main.filter(
668+
fileName => !fileName.endsWith('.map')
669+
);
645670

646671
return {
647672
files: manifestFiles,
673+
entrypoints: entrypointFiles,
648674
};
649675
},
650676
}),

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

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @remove-on-eject-begin
22
/**
3-
* Copyright (c) 2015-present, Facebook, Inc.
3+
* Copyright (c) 2019-present, https://github.com/devloco
44
*
55
* This source code is licensed under the MIT license found in the
66
* LICENSE file in the root directory of this source tree.
@@ -28,7 +28,7 @@ const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeM
2828
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
2929
const getCSSModuleLocalIdent = require('react-dev-utils/getCSSModuleLocalIdent');
3030
const paths = require('./paths-wptheme'); // wptheme modified
31-
const modules = require('./modules');
31+
const modules = require('./modules-wptheme'); // wptheme modified
3232
const getClientEnvironment = require('./env');
3333
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin');
3434
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin');
@@ -78,6 +78,11 @@ module.exports = function(webpackEnv) {
7878
const isEnvDevelopment = webpackEnv === 'development';
7979
const isEnvProduction = webpackEnv === 'production';
8080

81+
// Variable used for enabling profiling in Production
82+
// passed into alias object. Uses a flag if passed into the build command
83+
const isEnvProductionProfile =
84+
isEnvProduction && process.argv.includes('--profile');
85+
8186
// wptheme added - start
8287
const publicPathWithTrailingSlash = isEnvProduction
8388
? wpThemeUserConfig.homepage.endsWith('/')
@@ -227,6 +232,9 @@ module.exports = function(webpackEnv) {
227232
// Prevents conflicts when multiple Webpack runtimes (from different apps)
228233
// are used on the same page.
229234
jsonpFunction: `webpackJsonp${appPackageJson.name}`,
235+
// this defaults to 'window', but by setting it to 'this' then
236+
// module chunks which are built will work in web workers as well.
237+
globalObject: 'this',
230238
},
231239
optimization: {
232240
minimize: isEnvProduction,
@@ -259,6 +267,9 @@ module.exports = function(webpackEnv) {
259267
mangle: {
260268
safari10: true,
261269
},
270+
// Added for profiling in devtools
271+
keep_classnames: isEnvProductionProfile,
272+
keep_fnames: isEnvProductionProfile,
262273
output: {
263274
ecma: 5,
264275
comments: false,
@@ -328,6 +339,12 @@ module.exports = function(webpackEnv) {
328339
// Support React Native Web
329340
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
330341
'react-native': 'react-native-web',
342+
// Allows for better profiling with ReactDevTools
343+
...(isEnvProductionProfile && {
344+
'react-dom$': 'react-dom/profiling',
345+
'scheduler/tracing': 'scheduler/tracing-profiling',
346+
}),
347+
...(modules.webpackAliases || {}),
331348
},
332349
plugins: [
333350
// Adds support for installing with Plug'n'Play, leading to faster installs and adding
@@ -367,25 +384,27 @@ module.exports = function(webpackEnv) {
367384
eslintPath: require.resolve('eslint'),
368385
resolvePluginsRelativeTo: __dirname,
369386
// @remove-on-eject-begin
387+
ignore: process.env.EXTEND_ESLINT === 'true',
370388
baseConfig: (() => {
371-
const eslintCli = new eslint.CLIEngine();
372-
let eslintConfig;
373-
try {
374-
eslintConfig = eslintCli.getConfigForFile(paths.appIndexJs);
375-
} catch (e) {
376-
// A config couldn't be found.
377-
}
378-
379389
// We allow overriding the config only if the env variable is set
380-
if (process.env.EXTEND_ESLINT === 'true' && eslintConfig) {
390+
if (process.env.EXTEND_ESLINT === 'true') {
391+
const eslintCli = new eslint.CLIEngine();
392+
let eslintConfig;
393+
try {
394+
eslintConfig = eslintCli.getConfigForFile(
395+
paths.appIndexJs
396+
);
397+
} catch (e) {
398+
console.error(e);
399+
process.exit(1);
400+
}
381401
return eslintConfig;
382402
} else {
383403
return {
384404
extends: [require.resolve('eslint-config-react-app')],
385405
};
386406
}
387407
})(),
388-
ignore: false,
389408
useEslintrc: false,
390409
// @remove-on-eject-end
391410
},
@@ -631,7 +650,7 @@ module.exports = function(webpackEnv) {
631650
new InlineChunkHtmlPlugin(HtmlWebpackPlugin, [/runtime-.+[.]js/]),
632651
// Makes some environment variables available in index.html.
633652
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
634-
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
653+
// <link rel="icon" href="%PUBLIC_URL%/favicon.ico">
635654
// In production, it will be an empty string unless you specify "homepage"
636655
// in `package.json`, in which case it will be the pathname of that URL.
637656
// In development, this will be an empty string.
@@ -651,11 +670,10 @@ module.exports = function(webpackEnv) {
651670
// a plugin that prints an error when you attempt to do this.
652671
// See https://github.com/facebook/create-react-app/issues/240
653672
isEnvDevelopment && new CaseSensitivePathsPlugin(),
654-
// wptheme added section - start
673+
// wptheme added FileWatcherPlugin
655674
// For create-react-wptheme: watch addition files in the public folder for changes
656675
// touchFile is used to force WebPack to do a rebuild. It must be a file that WebPack is watching.
657676
new FileWatcherPlugin(fileWatcherPluginConfig),
658-
// wptheme added section - end
659677
// If you require a missing module and then `npm install` it, you still have
660678
// to restart the development server for Webpack to discover it. This plugin
661679
// makes the discovery automatic so you don't have to restart.
@@ -666,23 +684,32 @@ module.exports = function(webpackEnv) {
666684
new MiniCssExtractPlugin({
667685
// Options similar to the same options in webpackOptions.output
668686
// both options are optional
687+
// wptheme - remove [contenthash] in favor of using HtmlWebpackPlugin's cache
688+
// busting instead (see below).
669689
filename: 'static/css/[name].css',
670690
chunkFilename: 'static/css/[name].chunk.css',
671691
}),
672-
// Generate a manifest file which contains a mapping of all asset filenames
673-
// to their corresponding output file so that tools can pick it up without
674-
// having to parse `index.html`.
692+
// Generate an asset manifest file with the following content:
693+
// - "files" key: Mapping of all asset filenames to their corresponding
694+
// output file so that tools can pick it up without having to parse
695+
// `index.html`
696+
// - "entrypoints" key: Array of files which are included in `index.html`,
697+
// can be used to reconstruct the HTML if necessary
675698
new ManifestPlugin({
676699
fileName: 'asset-manifest.json',
677700
publicPath: publicPath,
678-
generate: (seed, files) => {
679-
const manifestFiles = files.reduce(function(manifest, file) {
701+
generate: (seed, files, entrypoints) => {
702+
const manifestFiles = files.reduce((manifest, file) => {
680703
manifest[file.name] = file.path;
681704
return manifest;
682705
}, seed);
706+
const entrypointFiles = entrypoints.main.filter(
707+
fileName => !fileName.endsWith('.map')
708+
);
683709

684710
return {
685711
files: manifestFiles,
712+
entrypoints: entrypointFiles,
686713
};
687714
},
688715
}),

0 commit comments

Comments
 (0)