-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Full-control webpack config with default results in duplicate style loader rules #4296
Comments
These symptoms sound just like what I'm seeing in a React project, although we are pinned at We use the full control + default mode and our setup looks roughly like import ourConfig from 'path/to/config'
module.exports = (baseConfig, env, defaultConfig) => {
const merged = {
// keep storybook's defaults
...defaultConfig,
// add our rules (required for SASS loaders, js/happypack, etc)
module: {
rules: [
...baseConfig.module.rules,
...ourConfig.module.rules
]
},
// add our plugins (babel transforms, etc)
plugins: [...defaultConfig.plugins, ...ourPluginsFiltered ],
// our changes to `resolve`
resolve: { ...defaultConfig.resolve, ...ourConfig.resolve }
}
return merged
} In our case the error is coming from which is added by Definitely a workaround but posting in case it unblocks someone else. |
@Yogu, I don't know what is MCVE is, but if it will help me to reproduce that'd be great. Also, please share your custom webpack.config for Storybook. @jfsiii, It looks not related to the Angular issue. BTW, |
@igor-dv Here's more info about our setup Failing `webpack.config.js` (extends default config)
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ourConfig = require('../webpack')
const ourPluginsFiltered = ourConfig.plugins
// filter our HMR plugin since Storybook has its own
// otherwise get a `SyntaxError: Maximum call stack exceeded` error
.filter(p => !(p instanceof webpack.HotModuleReplacementPlugin))
// exclude any of our `HtmlWebpackPlugin` entries
// they're for creating our own entry points (index.html, unsupported.html, etc)
// This also prevents _our_ `index.html` from clobbering storybook's file
.filter(p => !(p instanceof HtmlWebpackPlugin))
const storySourceRule = {
test: /(\b|\.)stories\.js$/,
exclude: /node_modules/,
loaders: [
{
loader: require.resolve('@storybook/addon-storysource/loader'),
options: {
uglyCommentsRegex: [
/^eslint-.*/,
/^global.*/,
]
}
}
],
enforce: 'pre',
}
module.exports = (baseConfig, env, defaultConfig) => {
const merged = {
// keep storybook's defaults
...defaultConfig,
// add our rules (required for SASS loaders, js/happypack, etc)
module: {
rules: [
...defaultConfig.module.rules,
...ourConfig.module.rules,
storySourceRule
],
},
// add our plugins (babel transforms, etc)
plugins: [...defaultConfig.plugins, ...ourPluginsFiltered ],
// our changes to `resolve` which allow `import`s like
// import Button from 'components/interactive/LinkButton'
// vs
// import Button from './client/components/interactive/LinkButton'
resolve: { ...defaultConfig.resolve, ...ourConfig.resolve }
}
return merged
} Working `webpack.config.js` (extends base config)
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ourConfig = require('../webpack')
const ourPluginsFiltered = ourConfig.plugins
// filter our HMR plugin since Storybook has its own
// otherwise get a `SyntaxError: Maximum call stack exceeded` error
.filter(p => !(p instanceof webpack.HotModuleReplacementPlugin))
// exclude any of our `HtmlWebpackPlugin` entries
// they're for creating our own entry points (index.html, unsupported.html, etc)
// This also prevents _our_ `index.html` from clobbering storybook's file
.filter(p => !(p instanceof HtmlWebpackPlugin))
const storySourceRule = {
test: /(\b|\.)stories\.js$/,
exclude: /node_modules/,
loaders: [
{
loader: require.resolve('@storybook/addon-storysource/loader'),
options: {
uglyCommentsRegex: [
/^eslint-.*/,
/^global.*/,
]
}
}
],
enforce: 'pre',
}
module.exports = (baseConfig, env, defaultConfig) => {
const merged = {
// keep storybook's defaults
...defaultConfig,
// add our rules (required for SASS loaders, js/happypack, etc)
module: {
rules: [
// using `baseConfig` instead of `defaultConfig` because
// default included additional CSS rules which caused errors
// when importing a component which imported a CSS file, like
// `import from 'read/dist/style.css'`
...defaultConfig.module.rules,
...ourConfig.module.rules,
storySourceRule
],
},
// add our plugins (babel transforms, etc)
plugins: [...defaultConfig.plugins, ...ourPluginsFiltered ],
// our changes to `resolve` which allow `import`s like
// import Button from 'components/interactive/LinkButton'
// vs
// import Button from './client/components/interactive/LinkButton'
resolve: { ...defaultConfig.resolve, ...ourConfig.resolve }
}
return merged
}
CSS rules from `ourConfig`[ { loader: 'style-loader', options: { sourceMap: true } },
{ loader: 'css-loader',
options: { sourceMap: true, minimize: false } },
{ loader: 'resolve-url-loader', options: { sourceMap: true } } ] CSS rules from `defaultConfig`[ '/Users/jfsiii/work/stae-product/node_modules/@storybook/core/node_modules/style-loader/index.js',
{ loader:
'/Users/jfsiii/work/stae-product/node_modules/css-loader/index.js',
options: { importLoaders: 1 } },
{ loader:
'/Users/jfsiii/work/stae-product/node_modules/@storybook/core/node_modules/postcss-loader/lib/index.js',
options:
{ ident: 'postcss', postcss: {}, plugins: [Function: plugins] } } ] When I use `baseConfig` rules[ { test: /\.js$/,
use: [ [Object] ],
include: [ '/Users/jfsiii/work/stae-product' ],
exclude: [ '/Users/jfsiii/work/stae-product/node_modules' ] } |
For documentation Stack trace
|
Maybe we are not filtering out our default css rules well for angular-cli? |
That's what I think, too. The code for this is still there (applyAngularCliWebpackConfig), but apparently it's not executed in the right spot anymore since alpha 21. |
Fixed by #4431 |
@kroeder with this update there is no way to adjust angular-cli plugins/loaders cause they are merged after custom config. |
@artaommahe, it will be fixed with #4405 |
We use storybook with angular in full-control webpack.config mode (to configure ts aliases). In v4.0.0-alpha.20 this worked fine, but sincd v4.0.0-alpha.21, we get the error "Module build failed: Unknown word" while loading CSS file. This is because
module.rules
includes css rules twice - once from angular-cli and once from the storybook's default webpack. I guess this should be migitgated byapplyAngularCliWebpackConfig
which extractsrulesExcludingStyles
for this reason. However, this function is no longer called to generate the default config passed to our custom webpack function.I guess this problem was introduced with presets (#4027), but I have not looked further into it.
Steps to reproduce
If the description is not clear enough, I can try to make an MCVE.
Please specify which version of Storybook and optionally any affected addons that you're running
The text was updated successfully, but these errors were encountered: