diff --git a/.changeset/metal-pigs-jog.md b/.changeset/metal-pigs-jog.md new file mode 100644 index 000000000..582e342c9 --- /dev/null +++ b/.changeset/metal-pigs-jog.md @@ -0,0 +1,5 @@ +--- +"modular-scripts": patch +--- + +Refactor modular config into readable parts diff --git a/packages/modular-scripts/package.json b/packages/modular-scripts/package.json index 083acd5e4..5fe22270b 100644 --- a/packages/modular-scripts/package.json +++ b/packages/modular-scripts/package.json @@ -122,6 +122,7 @@ "webpack": "5.73.0", "webpack-dev-server": "4.9.3", "webpack-manifest-plugin": "5.0.0", + "webpack-merge": "^5.8.0", "ws": "8.8.1" }, "peerDependencies": { diff --git a/packages/modular-scripts/react-scripts/config/parts/appConfig.js b/packages/modular-scripts/react-scripts/config/parts/appConfig.js new file mode 100644 index 000000000..9ca4a2d46 --- /dev/null +++ b/packages/modular-scripts/react-scripts/config/parts/appConfig.js @@ -0,0 +1,71 @@ +'use strict'; +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const InlineChunkHtmlPlugin = require('../../../react-dev-utils/InlineChunkHtmlPlugin'); +const InterpolateHtmlPlugin = require('../../../react-dev-utils/InterpolateHtmlPlugin'); + +function createConfig() { + return { + optimization: { + // Automatically split vendor and commons + splitChunks: { chunks: 'all' }, + // 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}`, + }, + }, + }; +} + +function createPluginConfig({ + isEnvProduction, + shouldInlineRuntimeChunk, + env, + paths, +}) { + return { + plugins: [ + // Generates an `index.html` file with the