Skip to content

Commit debcc48

Browse files
AttackTheDarknesssapegin
authored andcommitted
Fix: Pass devtool webpack option in dev mode (styleguidist#569)
Closes styleguidist#456
1 parent 7bc9424 commit debcc48

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

docs/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ module.exports = {
443443

444444
> **Warning:** This option disables config load from `webpack.config.js`, load your config [manually](Webpack.md#reusing-your-projects-webpack-config).
445445
446-
> **Note:** `entry`, `externals`, `output`, `watch`, `stats` and `devtool` options will be ignored.
446+
> **Note:** `entry`, `externals`, `output`, `watch`, and `stats` options will be ignored. For production builds, `devtool` will also be ignored.
447447
448448
> **Note:** `CommonsChunkPlugins`, `HtmlWebpackPlugin`, `UglifyJsPlugin`, `HotModuleReplacementPlugin` plugins will be ignored because Styleguidist already includes them or they may break Styleguidist.
449449

docs/Webpack.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
};
3232
```
3333

34-
> **Note:** `entry`, `externals`, `output`, `watch`, `stats` and `devtool` options will be ignored.
34+
> **Note:** `entry`, `externals`, `output`, `watch`, and `stats` options will be ignored. For production builds, `devtool` will also be ignored.
3535
3636
> **Note:** `CommonsChunkPlugins`, `HtmlWebpackPlugin`, `UglifyJsPlugin`, `HotModuleReplacementPlugin` plugins will be ignored because Styleguidist already includes them or they may break Styleguidist.
3737
@@ -69,7 +69,7 @@ module.exports = {
6969

7070
> **Warning:** This option disables config load from `webpack.config.js`, see above how to load your config manually.
7171
72-
> **Note:** `entry`, `externals`, `output`, `watch`, `stats` and `devtool` options will be ignored.
72+
> **Note:** `entry`, `externals`, `output`, `watch`, and `stats` options will be ignored. For production builds, `devtool` will also be ignored.
7373
7474
> **Note:** `CommonsChunkPlugins`, `HtmlWebpackPlugin`, `UglifyJsPlugin`, `HotModuleReplacementPlugin` plugins will be ignored because Styleguidist already includes them or they may break Styleguidist.
7575

scripts/utils/__tests__/mergeWebpackConfig.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,21 @@ it('should ignore certain Webpack plugins', () => {
3838
expect(result.plugins[0].constructor.name).toBe('UglifyJsPlugin');
3939
expect(result.plugins[1].constructor.name).toBe('MyPlugin');
4040
});
41+
42+
it('should pass devtool settings in development', () => {
43+
const result = mergeWebpackConfig(
44+
{ devtool: false },
45+
() => ({ devtool: 'source-map' }),
46+
'development'
47+
);
48+
expect(result).toEqual({ devtool: 'source-map' });
49+
});
50+
51+
it('should ignore devtool settings in production', () => {
52+
const result = mergeWebpackConfig(
53+
{ devtool: false },
54+
() => ({ devtool: 'source-map' }),
55+
'production'
56+
);
57+
expect(result).toEqual({ devtool: false });
58+
});

scripts/utils/mergeWebpackConfig.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ const isFunction = require('lodash/isFunction');
44
const omit = require('lodash/omit');
55
const mergeBase = require('webpack-merge');
66

7-
const IGNORE_SECTIONS = [
8-
'entry',
9-
'externals',
10-
'output',
11-
'watch',
12-
'stats',
13-
'devtool',
14-
'styleguidist',
15-
];
7+
const IGNORE_SECTIONS = ['entry', 'externals', 'output', 'watch', 'stats', 'styleguidist'];
8+
const IGNORE_SECTIONS_ENV = {
9+
development: [],
10+
// For production builds, we'll ignore devtool settings to avoid
11+
// source mapping bloat.
12+
production: ['devtool'],
13+
};
1614

1715
const IGNORE_PLUGINS = [
1816
'CommonsChunkPlugins',
@@ -46,6 +44,6 @@ const merge = mergeBase({
4644
*/
4745
module.exports = function mergeWebpackConfig(baseConfig, userConfig, env) {
4846
const userConfigObject = isFunction(userConfig) ? userConfig(env) : userConfig;
49-
const safeUserConfig = omit(userConfigObject, IGNORE_SECTIONS);
47+
const safeUserConfig = omit(userConfigObject, IGNORE_SECTIONS.concat(IGNORE_SECTIONS_ENV[env]));
5048
return merge(baseConfig, safeUserConfig);
5149
};

0 commit comments

Comments
 (0)