Skip to content

Commit

Permalink
Add Webpack fix to properly handle react components using "@emotion/s…
Browse files Browse the repository at this point in the history
…tyled"
  • Loading branch information
Vadorequest committed Jan 13, 2021
1 parent 6a60f85 commit f0f4497
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const path = require("path")

const toPath = (_path) => path.join(process.cwd(), _path)

module.exports = {
stories: [
'../src/**/*.stories.mdx',
Expand Down Expand Up @@ -137,4 +141,37 @@ module.exports = {
*/
'storybook-addon-designs',
],

/**
* Customize webpack configuration for Storybook.
*
* This doesn't affect the Next.js application, only the Storybook compilation.
*
* @param config
* @see https://storybook.js.org/docs/react/configure/overview#configure-your-storybook-project
*/
webpackFinal: async (config) => {
return {
...config,
resolve: {
...config.resolve,
alias: {
...config.resolve.alias,

/**
* Map Emotion 10 libraries to Emotion 11 libraries.
*
* Otherwise Storybook fails to compile with "Module not found: Error: Can't resolve '@emotion/styled/base'", etc.
* It wasn't necessary to do this until we imported React component using "@emotion/styled".
* This issue is probably caused because Storybook uses Emotion 10 while we have Emotion 11 used by the Next.js app.
*
* @see https://github.com/storybookjs/storybook/issues/13277#issuecomment-751747964
*/
"@emotion/core": toPath("node_modules/@emotion/react"),
"@emotion/styled": toPath("node_modules/@emotion/styled"),
"emotion-theming": toPath("node_modules/@emotion/react"),
}
}
};
}
};

0 comments on commit f0f4497

Please sign in to comment.