Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit e36639f

Browse files
authored
perf(infrastructure): Cut build time in half with opt-in env var (#1128)
A new `GENERATE_SOURCE_MAPS=false` env var disables source map generation in dev mode, which cuts build and recompile times in half. Invoked like so: ```bash GENERATE_SOURCE_MAPS=false npm run dev ```
1 parent 0754628 commit e36639f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

webpack.config.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ const OUT_PATH = path.resolve('./build');
2626
const PUBLIC_PATH = '/assets/';
2727
const IS_DEV = process.env.MDC_ENV === 'development';
2828
const IS_PROD = process.env.MDC_ENV === 'production';
29+
const GENERATE_SOURCE_MAPS =
30+
process.env.MDC_GENERATE_SOURCE_MAPS === 'true' ||
31+
(process.env.MDC_GENERATE_SOURCE_MAPS !== 'false' && IS_DEV);
32+
const DEVTOOL = GENERATE_SOURCE_MAPS ? 'source-map' : false;
2933

3034
const banner = [
3135
'/*!',
@@ -50,20 +54,20 @@ const CSS_LOADER_CONFIG = [
5054
{
5155
loader: 'css-loader',
5256
options: {
53-
sourceMap: true,
57+
sourceMap: GENERATE_SOURCE_MAPS,
5458
},
5559
},
5660
{
5761
loader: 'postcss-loader',
5862
options: {
59-
sourceMap: IS_DEV,
60-
plugins: () =>[require('autoprefixer')({grid: false})],
63+
sourceMap: GENERATE_SOURCE_MAPS,
64+
plugins: () => [require('autoprefixer')({grid: false})],
6165
},
6266
},
6367
{
6468
loader: 'sass-loader',
6569
options: {
66-
sourceMap: true,
70+
sourceMap: GENERATE_SOURCE_MAPS,
6771
includePaths: glob.sync('packages/*/node_modules').map((d) => path.join(__dirname, d)),
6872
},
6973
},
@@ -106,7 +110,7 @@ module.exports = [{
106110
devServer: {
107111
disableHostCheck: true,
108112
},
109-
devtool: IS_DEV ? 'source-map' : false,
113+
devtool: DEVTOOL,
110114
module: {
111115
rules: [{
112116
test: /\.js$/,
@@ -133,7 +137,7 @@ module.exports = [{
133137
devServer: {
134138
disableHostCheck: true,
135139
},
136-
devtool: IS_DEV ? 'source-map' : false,
140+
devtool: DEVTOOL,
137141
module: {
138142
rules: [{
139143
test: /\.js$/,
@@ -190,7 +194,7 @@ module.exports = [{
190194
devServer: {
191195
disableHostCheck: true,
192196
},
193-
devtool: IS_DEV ? 'source-map' : false,
197+
devtool: DEVTOOL,
194198
module: {
195199
rules: [{
196200
test: /\.scss$/,
@@ -220,7 +224,7 @@ if (IS_DEV) {
220224
devServer: {
221225
disableHostCheck: true,
222226
},
223-
devtool: 'source-map',
227+
devtool: DEVTOOL,
224228
module: {
225229
rules: [{
226230
test: /\.scss$/,

0 commit comments

Comments
 (0)