From 885fe178dd2b6b4227f18511bb0749722df40bf0 Mon Sep 17 00:00:00 2001 From: Rishabh Date: Wed, 16 Jun 2021 20:47:23 +0530 Subject: [PATCH] Updated local start mode script no issues - adds new start-combined script which combines all chunks in `yarn start` for local portal development - allows easier loading of local portal bundle in ghost via load-portal script, which needs to inject single script - updates `yarn start:dev` to use updated script which uses the combined mode for better local development refs https://gist.github.com/simpixelated/90a3c16c3ed268fe24f5e5c9585ced2f --- ghost/portal/package.json | 3 ++- ghost/portal/scripts/load-portal.js | 5 +---- ghost/portal/scripts/start-combined.js | 14 ++++++++++++++ ghost/portal/scripts/start-mode.js | 2 +- 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 ghost/portal/scripts/start-combined.js diff --git a/ghost/portal/package.json b/ghost/portal/package.json index 0e1e850b11..577a288cba 100644 --- a/ghost/portal/package.json +++ b/ghost/portal/package.json @@ -26,7 +26,8 @@ "react-scripts": "4.0.3" }, "scripts": { - "start": "react-scripts start", + "start": "BROWSER=none react-scripts start", + "start:combined": "BROWSER=none node ./scripts/start-combined.js", "start:dev": "node ./scripts/start-mode.js", "dev": "node ./scripts/dev-mode.js", "build": "npm run build:combined", diff --git a/ghost/portal/scripts/load-portal.js b/ghost/portal/scripts/load-portal.js index 1bc5f30553..a2ce499dac 100644 --- a/ghost/portal/scripts/load-portal.js +++ b/ghost/portal/scripts/load-portal.js @@ -1,4 +1,4 @@ -/** Script to load live Portal script chunks for local development */ +/** Script to load Portal bundle for local development */ function loadScript(src) { var script = document.createElement('script'); script.src = src; @@ -6,6 +6,3 @@ function loadScript(src) { } loadScript('http://localhost:3000/static/js/bundle.js'); -loadScript('http://localhost:3000/static/js/1.chunk.js'); -loadScript('http://localhost:3000/static/js/0.chunk.js'); -loadScript('http://localhost:3000/static/js/main.chunk.js'); diff --git a/ghost/portal/scripts/start-combined.js b/ghost/portal/scripts/start-combined.js new file mode 100644 index 0000000000..fcd80a39a9 --- /dev/null +++ b/ghost/portal/scripts/start-combined.js @@ -0,0 +1,14 @@ +const rewire = require('rewire'); +const defaults = rewire('react-scripts/scripts/start.js'); +let configFactory = defaults.__get__('configFactory'); + +defaults.__set__('configFactory', (env) => { + const config = configFactory(env); + config.optimization.splitChunks = { + cacheGroups: { + default: false + } + }; + config.optimization.runtimeChunk = false; + return config; +}); diff --git a/ghost/portal/scripts/start-mode.js b/ghost/portal/scripts/start-mode.js index d5962c1ada..760efe24ef 100644 --- a/ghost/portal/scripts/start-mode.js +++ b/ghost/portal/scripts/start-mode.js @@ -77,7 +77,7 @@ function doYarnStart() { return; } const options = getBuildOptions(); - yarnStartProcess = spawn('BROWSER=none yarn start', options); + yarnStartProcess = spawn('yarn start:combined', options); ['SIGINT', 'SIGTERM'].forEach(function (sig) { yarnStartProcess.on(sig, function () {