Skip to content

Commit 05f435d

Browse files
author
mildmojo
committed
Adds dev writeToDisk option for react-scripts start.
Applies the patch from this abandoned PR: facebook#7812 Based on this 4-year-old issue about emitting dev builds to disk: facebook#1070 To use, call `react-scripts start --writeToDisk`. This will emit dev environment built files to the normally-production output path.
1 parent 97e6d55 commit 05f435d

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

packages/react-scripts/config/paths.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
2424
// We can't use a relative path in HTML because we don't want to load something
2525
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
2626
const publicUrlOrPath = getPublicUrlOrPath(
27-
process.env.NODE_ENV === 'development',
27+
process.env.NODE_ENV === 'development' && !process.argv.includes('--writeToDisk'),
2828
require(resolveApp('package.json')).homepage,
2929
process.env.PUBLIC_URL
3030
);

packages/react-scripts/config/webpack.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ module.exports = function(webpackEnv) {
6868
const isEnvDevelopment = webpackEnv === 'development';
6969
const isEnvProduction = webpackEnv === 'production';
7070

71+
// Passing this flag will write build files to the production build path
72+
const writeToDisk = process.argv.includes('--writeToDisk');
73+
7174
// Variable used for enabling profiling in Production
7275
// passed into alias object. Uses a flag if passed into the build command
7376
const isEnvProductionProfile =
@@ -176,7 +179,7 @@ module.exports = function(webpackEnv) {
176179
},
177180
output: {
178181
// The build folder.
179-
path: isEnvProduction ? paths.appBuild : undefined,
182+
path: isEnvProduction || writeToDisk ? paths.appBuild : undefined,
180183
// Add /* filename */ comments to generated require()s in the output.
181184
pathinfo: isEnvDevelopment,
182185
// There will be one main bundle, and one file per asynchronous chunk.

packages/react-scripts/config/webpackDevServer.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,6 @@ module.exports = function(proxy, allowedHost) {
134134
// https://github.com/facebook/create-react-app/issues/2272#issuecomment-302832432
135135
app.use(noopServiceWorkerMiddleware(paths.publicUrlOrPath));
136136
},
137+
writeToDisk: process.argv.includes('--writeToDisk'),
137138
};
138139
};

packages/react-scripts/scripts/start.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ checkBrowsers(paths.appPath, isInteractive)
155155
}
156156

157157
console.log(chalk.cyan('Starting the development server...\n'));
158-
openBrowser(urls.localUrlForBrowser);
158+
if (!process.argv.includes('--writeToDisk')) {
159+
openBrowser(urls.localUrlForBrowser);
160+
}
159161
});
160162

161163
['SIGINT', 'SIGTERM'].forEach(function(sig) {

0 commit comments

Comments
 (0)