Skip to content

Commit fb155b9

Browse files
viankakrisnakasperpeulen
authored andcommitted
Use env variable to disable source maps (facebook#2818)
* use env variable to disable source maps * Rename to use SOURCE_MAP with explicit value * Update webpack.config.prod.js
1 parent 3e0069f commit fb155b9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const publicPath = paths.servedPath;
4141
// Some apps do not use client-side routing with pushState.
4242
// For these, "homepage" can be set to "." to enable relative asset paths.
4343
const shouldUseRelativeAssetPaths = publicPath === './';
44+
// Source maps are resource heavy and can cause out of memory issue for large source files.
45+
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
4446
// `publicUrl` is just like `publicPath`, but we will provide it to our app
4547
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
4648
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
@@ -74,7 +76,7 @@ module.exports = {
7476
bail: true,
7577
// We generate sourcemaps in production. This is slow but gives good results.
7678
// You can exclude the *.map files from the build during deployment.
77-
devtool: 'source-map',
79+
devtool: shouldUseSourceMap ? 'source-map' : false,
7880
// In production, we only want to load the polyfills and the app code.
7981
entry: [require.resolve('./polyfills'), paths.appIndexJs],
8082
output: {
@@ -216,7 +218,7 @@ module.exports = {
216218
options: {
217219
importLoaders: 1,
218220
minimize: true,
219-
sourceMap: true,
221+
sourceMap: shouldUseSourceMap,
220222
},
221223
},
222224
{
@@ -307,7 +309,7 @@ module.exports = {
307309
// https://github.com/facebookincubator/create-react-app/issues/2488
308310
ascii_only: true,
309311
},
310-
sourceMap: true,
312+
sourceMap: shouldUseSourceMap,
311313
}),
312314
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
313315
new ExtractTextPlugin({

0 commit comments

Comments
 (0)