Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
fix(next-storybook): make rules an array in webpack config (vercel#22125
Browse files Browse the repository at this point in the history
)

the `next-storybook` plugin throws an error since version `10.0.6-canary.9`, specifically since vercel#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 vercel#17306 (comment)
  • Loading branch information
stefanprobst authored May 5, 2021
1 parent f03f5f9 commit 3bb922d
Showing 1 changed file with 19 additions and 21 deletions.
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

0 comments on commit 3bb922d

Please sign in to comment.