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
2828const ModuleScopePlugin = require ( 'react-dev-utils/ModuleScopePlugin' ) ;
2929const getCSSModuleLocalIdent = require ( 'react-dev-utils/getCSSModuleLocalIdent' ) ;
3030const paths = require ( './paths-wptheme' ) ; // wptheme modified
31- const modules = require ( './modules' ) ;
31+ const modules = require ( './modules-wptheme ' ) ; // wptheme modified
3232const getClientEnvironment = require ( './env' ) ;
3333const ModuleNotFoundPlugin = require ( 'react-dev-utils/ModuleNotFoundPlugin' ) ;
3434const 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 , [ / r u n t i m e - .+ [ . ] j s / ] ) ,
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