From a47b929fe1e7bf3d323ca19aa0f659f879403d79 Mon Sep 17 00:00:00 2001 From: Nerissa Lin Date: Sat, 29 May 2021 10:41:30 -0700 Subject: [PATCH] webpack changes needed since we are working with CreateREactAppv2.x which produces a different Webpack file. need to make some modifications according to github.com/satendra02/react-chrome-extension/issues/2 --- config/webpack.config.js | 63 +++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 33 deletions(-) diff --git a/config/webpack.config.js b/config/webpack.config.js index 9a4c976..e9d6586 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -169,31 +169,28 @@ module.exports = function (webpackEnv) { : 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: - isEnvDevelopment && !shouldUseReactRefresh - ? [ - // 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 - // of CSS changes), or refresh the page (in case of JS changes). When you - // make a syntax error, this client will display a syntax error overlay. - // Note: instead of the default WebpackDevServer client, we use a custom one - // to bring better experience for Create React App users. You can replace - // the line below with these two lines if you prefer the stock client: - // - // require.resolve('webpack-dev-server/client') + '?/', - // require.resolve('webpack/hot/dev-server'), - // - // When using the experimental react-refresh integration, - // the webpack plugin takes care of injecting the dev client for us. - webpackDevClientEntry, - // Finally, this is your app's code: - paths.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. - ] - : paths.appIndexJs, + entry: { + app: [ + // 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 + // of CSS changes), or refresh the page (in case of JS changes). When you + // make a syntax error, this client will display a syntax error overlay. + // Note: instead of the default WebpackDevServer client, we use a custom one + // to bring better experience for Create React App users. You can replace + // the line below with these two lines if you prefer the stock client: + // require.resolve('webpack-dev-server/client') + '?/', + // require.resolve('webpack/hot/dev-server'), + isEnvDevelopment && + require.resolve("react-dev-utils/webpackHotDevClient"), + // Finally, this is your app's code: + paths.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), + content: path.appContent, + }, output: { // The build folder. path: isEnvProduction ? paths.appBuild : undefined, @@ -297,16 +294,14 @@ module.exports = function (webpackEnv) { // Automatically split vendor and commons // https://twitter.com/wSokra/status/969633336732905474 // https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366 - splitChunks: { - chunks: "all", - name: isEnvDevelopment, - }, + // splitChunks: { + // chunks: "all", + // name: isEnvDevelopment, + // }, // Keep the runtime chunk separated to enable long term caching // https://twitter.com/wSokra/status/969679223278505985 // https://github.com/facebook/create-react-app/issues/5358 - runtimeChunk: { - name: (entrypoint) => `runtime-${entrypoint.name}`, - }, + runtimeChunk: false, }, resolve: { // This allows you to set a fallback for where webpack should look for modules. @@ -564,7 +559,9 @@ module.exports = function (webpackEnv) { {}, { inject: true, + chunks: ["app"], template: paths.appHtml, + filename: "popup.html", }, isEnvProduction ? { @@ -653,7 +650,7 @@ module.exports = function (webpackEnv) { manifest[file.name] = file.path; return manifest; }, seed); - const entrypointFiles = entrypoints.main.filter( + const entrypointFiles = entrypoints.app.filter( (fileName) => !fileName.endsWith(".map") );