Skip to content

Commit 1e3a64f

Browse files
viankakrisnaTimer
authored andcommitted
Use env variable to disable source maps (#2818)
* use env variable to disable source maps * Rename to use SOURCE_MAP with explicit value * Update webpack.config.prod.js
1 parent badfc2a commit 1e3a64f

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
@@ -29,6 +29,8 @@ const publicPath = paths.servedPath;
2929
// Some apps do not use client-side routing with pushState.
3030
// For these, "homepage" can be set to "." to enable relative asset paths.
3131
const shouldUseRelativeAssetPaths = publicPath === './';
32+
// Source maps are resource heavy and can cause out of memory issue for large source files.
33+
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
3234
// `publicUrl` is just like `publicPath`, but we will provide it to our app
3335
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
3436
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
@@ -62,7 +64,7 @@ module.exports = {
6264
bail: true,
6365
// We generate sourcemaps in production. This is slow but gives good results.
6466
// You can exclude the *.map files from the build during deployment.
65-
devtool: 'source-map',
67+
devtool: shouldUseSourceMap ? 'source-map' : false,
6668
// In production, we only want to load the polyfills and the app code.
6769
entry: [require.resolve('./polyfills'), paths.appIndexJs],
6870
output: {
@@ -204,7 +206,7 @@ module.exports = {
204206
options: {
205207
importLoaders: 1,
206208
minimize: true,
207-
sourceMap: true,
209+
sourceMap: shouldUseSourceMap,
208210
},
209211
},
210212
{
@@ -300,7 +302,7 @@ module.exports = {
300302
// https://github.com/facebookincubator/create-react-app/issues/2488
301303
ascii_only: true,
302304
},
303-
sourceMap: true,
305+
sourceMap: shouldUseSourceMap,
304306
}),
305307
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
306308
new ExtractTextPlugin({

0 commit comments

Comments
 (0)