Unverified Commit 3a2cd0e0 authored by stefanprobst's avatar stefanprobst Committed by GitHub

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

the `next-storybook` plugin throws an error since version `10.0.6-canary.9`, specifically since #17306:

```
ERR! WebpackOptionsValidationError: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
ERR!  - configuration.module.rules should be an array
```

this PR makes `module.rules` an array again.

also see https://github.com/vercel/next.js/pull/17306#issuecomment-774996237
parent 3a78ccd4
...@@ -25,7 +25,7 @@ async function webpackFinal(config) { ...@@ -25,7 +25,7 @@ async function webpackFinal(config) {
...nextWebpackConfig.resolve, ...nextWebpackConfig.resolve,
} }
config.module.rules = { config.module.rules = [
...filterModuleRules(config), ...filterModuleRules(config),
...nextWebpackConfig.module.rules.map((rule) => { ...nextWebpackConfig.module.rules.map((rule) => {
// we need to resolve next-babel-loader since it's not available // we need to resolve next-babel-loader since it's not available
...@@ -37,14 +37,13 @@ async function webpackFinal(config) { ...@@ -37,14 +37,13 @@ async function webpackFinal(config) {
} }
return rule return rule
}), }),
} ]
return config return config
} }
function filterModuleRules(config) { function filterModuleRules(config) {
return [ return config.module.rules.filter((rule) => {
...config.module.rules.filter((rule) => {
// the rules we're filtering use RegExp for the test // the rules we're filtering use RegExp for the test
if (!(rule.test instanceof RegExp)) return true if (!(rule.test instanceof RegExp)) return true
// use Next.js' built-in CSS // use Next.js' built-in CSS
...@@ -60,8 +59,7 @@ function filterModuleRules(config) { ...@@ -60,8 +59,7 @@ function filterModuleRules(config) {
return false return false
} }
return true return true
}), })
]
} }
module.exports = { module.exports = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment