Skip to content

Commit

Permalink
Fix: Pass devtool webpack option in dev mode (#569)
Browse files Browse the repository at this point in the history
Closes #456
  • Loading branch information
AttackTheDarkness authored and sapegin committed Aug 10, 2017
1 parent 7bc9424 commit debcc48
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ module.exports = {

> **Warning:** This option disables config load from `webpack.config.js`, load your config [manually](Webpack.md#reusing-your-projects-webpack-config).
> **Note:** `entry`, `externals`, `output`, `watch`, `stats` and `devtool` options will be ignored.
> **Note:** `entry`, `externals`, `output`, `watch`, and `stats` options will be ignored. For production builds, `devtool` will also be ignored.
> **Note:** `CommonsChunkPlugins`, `HtmlWebpackPlugin`, `UglifyJsPlugin`, `HotModuleReplacementPlugin` plugins will be ignored because Styleguidist already includes them or they may break Styleguidist.
Expand Down
4 changes: 2 additions & 2 deletions docs/Webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = {
};
```

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

> **Warning:** This option disables config load from `webpack.config.js`, see above how to load your config manually.
> **Note:** `entry`, `externals`, `output`, `watch`, `stats` and `devtool` options will be ignored.
> **Note:** `entry`, `externals`, `output`, `watch`, and `stats` options will be ignored. For production builds, `devtool` will also be ignored.
> **Note:** `CommonsChunkPlugins`, `HtmlWebpackPlugin`, `UglifyJsPlugin`, `HotModuleReplacementPlugin` plugins will be ignored because Styleguidist already includes them or they may break Styleguidist.
Expand Down
18 changes: 18 additions & 0 deletions scripts/utils/__tests__/mergeWebpackConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,21 @@ it('should ignore certain Webpack plugins', () => {
expect(result.plugins[0].constructor.name).toBe('UglifyJsPlugin');
expect(result.plugins[1].constructor.name).toBe('MyPlugin');
});

it('should pass devtool settings in development', () => {
const result = mergeWebpackConfig(
{ devtool: false },
() => ({ devtool: 'source-map' }),
'development'
);
expect(result).toEqual({ devtool: 'source-map' });
});

it('should ignore devtool settings in production', () => {
const result = mergeWebpackConfig(
{ devtool: false },
() => ({ devtool: 'source-map' }),
'production'
);
expect(result).toEqual({ devtool: false });
});
18 changes: 8 additions & 10 deletions scripts/utils/mergeWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ const isFunction = require('lodash/isFunction');
const omit = require('lodash/omit');
const mergeBase = require('webpack-merge');

const IGNORE_SECTIONS = [
'entry',
'externals',
'output',
'watch',
'stats',
'devtool',
'styleguidist',
];
const IGNORE_SECTIONS = ['entry', 'externals', 'output', 'watch', 'stats', 'styleguidist'];
const IGNORE_SECTIONS_ENV = {
development: [],
// For production builds, we'll ignore devtool settings to avoid
// source mapping bloat.
production: ['devtool'],
};

const IGNORE_PLUGINS = [
'CommonsChunkPlugins',
Expand Down Expand Up @@ -46,6 +44,6 @@ const merge = mergeBase({
*/
module.exports = function mergeWebpackConfig(baseConfig, userConfig, env) {
const userConfigObject = isFunction(userConfig) ? userConfig(env) : userConfig;
const safeUserConfig = omit(userConfigObject, IGNORE_SECTIONS);
const safeUserConfig = omit(userConfigObject, IGNORE_SECTIONS.concat(IGNORE_SECTIONS_ENV[env]));
return merge(baseConfig, safeUserConfig);
};

0 comments on commit debcc48

Please sign in to comment.