This repository was archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix storybook when using emotion 11 styled()
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |