Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using devtools with react-stylegudist #456 #569

Merged
merged 2 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
};