From 98d363197674adfe99a292811808672ef05070d5 Mon Sep 17 00:00:00 2001 From: danzeuss Date: Sat, 28 Dec 2019 05:11:43 -0300 Subject: [PATCH 1/7] . --- packages/react-scripts/config/paths.js | 9 ++ .../react-scripts/config/webpack.config.js | 113 +++++++++++------- packages/react-scripts/scripts/build.js | 16 ++- packages/react-scripts/scripts/start.js | 8 +- 4 files changed, 92 insertions(+), 54 deletions(-) diff --git a/packages/react-scripts/config/paths.js b/packages/react-scripts/config/paths.js index acaca7f4d48..eebf10cb5c8 100644 --- a/packages/react-scripts/config/paths.js +++ b/packages/react-scripts/config/paths.js @@ -73,6 +73,15 @@ const resolveModule = (resolveFn, filePath) => { return resolveFn(`${filePath}.js`); }; +const appPages = [ + { + name: 'index', + title: 'index', + appHtml: resolveApp('public/index.html'), + appIndexJs: resolveApp('src/index.js'), + }, +]; + // config after eject: we're in ./config/ module.exports = { dotenv: resolveApp('.env'), diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index bad4290061b..27ccc0f7c58 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -146,18 +146,44 @@ module.exports = function(webpackEnv) { return loaders; }; - return { - mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development', - // Stop compilation early in production - bail: isEnvProduction, - devtool: isEnvProduction - ? shouldUseSourceMap - ? 'source-map' - : false - : isEnvDevelopment && 'cheap-module-source-map', - // These are the "entry points" to our application. - // This means they will be the "root" imports that are included in JS bundle. - entry: [ + const htmlPlugins = []; + + paths.appPages.forEach(appPage => { + htmlPlugins.push( + new HtmlWebpackPlugin( + Object.assign( + {}, + { + inject: true, + template: appPage.appHtml, + // filename: `${appPage.name}.html`, + // title: appPage.title, + // chunks: [appPage.name] + }, + isEnvProduction + ? { + minify: { + removeComments: true, + collapseWhitespace: true, + removeRedundantAttributes: true, + useShortDoctype: true, + removeEmptyAttributes: true, + removeStyleLinkTypeAttributes: true, + keepClosingSlash: true, + minifyJS: true, + minifyCSS: true, + minifyURLs: true, + }, + } + : undefined + ) + ) + ); + }); + + let entries = {}; + paths.appPages.forEach(appPage => { + entries[appPage.name] = [ // Include an alternative client for WebpackDevServer. A client's job is to // connect to WebpackDevServer by a socket and get notified about changes. // When you save a file, the client will either apply hot updates (in case @@ -171,11 +197,25 @@ module.exports = function(webpackEnv) { isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient'), // Finally, this is your app's code: - paths.appIndexJs, + appPage.appIndexJs, // We include the app code last so that if there is a runtime error during // initialization, it doesn't blow up the WebpackDevServer client, and // changing JS code would still trigger a refresh. - ].filter(Boolean), + ].filter(Boolean); + }); + + return { + mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development', + // Stop compilation early in production + bail: isEnvProduction, + devtool: isEnvProduction + ? shouldUseSourceMap + ? 'source-map' + : false + : isEnvDevelopment && 'cheap-module-source-map', + // These are the "entry points" to our application. + // This means they will be the "root" imports that are included in JS bundle. + entry: entries, output: { // The build folder. path: isEnvProduction ? paths.appBuild : undefined, @@ -270,8 +310,8 @@ module.exports = function(webpackEnv) { : false, }, cssProcessorPluginOptions: { - preset: ['default', { minifyFontValues: { removeQuotes: false } }] - } + preset: ['default', { minifyFontValues: { removeQuotes: false } }], + }, }), ], // Automatically split vendor and commons @@ -580,32 +620,9 @@ module.exports = function(webpackEnv) { ], }, plugins: [ - // Generates an `index.html` file with the