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

fix(next-storybook): make rules an array in webpack config #22125

Merged
merged 7 commits into from
May 5, 2021
40 changes: 19 additions & 21 deletions packages/next-plugin-storybook/preset.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function webpackFinal(config) {
...nextWebpackConfig.resolve,
}

config.module.rules = {
config.module.rules = [
...filterModuleRules(config),
...nextWebpackConfig.module.rules.map((rule) => {
// we need to resolve next-babel-loader since it's not available
Expand All @@ -37,31 +37,29 @@ async function webpackFinal(config) {
}
return rule
}),
}
]

return config
}

function filterModuleRules(config) {
return [
...config.module.rules.filter((rule) => {
// the rules we're filtering use RegExp for the test
if (!(rule.test instanceof RegExp)) return true
// use Next.js' built-in CSS
if (rule.test.test('hello.css')) {
return false
}
// use next-babel-loader instead of storybook's babel-loader
if (
rule.test.test('hello.js') &&
Array.isArray(rule.use) &&
rule.use[0].loader === 'babel-loader'
) {
return false
}
return true
}),
]
return config.module.rules.filter((rule) => {
// the rules we're filtering use RegExp for the test
if (!(rule.test instanceof RegExp)) return true
// use Next.js' built-in CSS
if (rule.test.test('hello.css')) {
return false
}
// use next-babel-loader instead of storybook's babel-loader
if (
rule.test.test('hello.js') &&
Array.isArray(rule.use) &&
rule.use[0].loader === 'babel-loader'
) {
return false
}
return true
})
}

module.exports = {
Expand Down