Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
fix storybook when using emotion 11 styled()
Browse files Browse the repository at this point in the history
  • Loading branch information
joshnies committed Aug 4, 2021
1 parent e8d1e5e commit 261fd93
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
const path = require('path');
const fs = require('fs');

// Work-around for using emotion 11 with Storybook
function getPackageDir(filepath) {
let currDir = path.dirname(require.resolve(filepath));
while (true) {
if (fs.existsSync(path.join(currDir, 'package.json'))) {
return currDir;
}
const { dir, root } = path.parse(currDir);
if (dir === root) {
throw new Error(
`Could not find package.json in the parent directories starting from ${filepath}.`
);
}
currDir = dir;
}
}

module.exports = {
stories: [
'../stories/**/*.stories.mdx',
'../stories/**/*.stories.@(js|jsx|ts|tsx)',
],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
// Work-around for using emotion 11 with Storybook
webpackFinal: async (config) => {
config.resolve.alias = {
'@emotion/core': getPackageDir('@emotion/react'),
'@emotion/styled': getPackageDir('@emotion/styled'),
'emotion-theming': getPackageDir('@emotion/react'),
};
return config;
},
};

0 comments on commit 261fd93

Please sign in to comment.