Created
July 10, 2019 15:53
-
-
Save connebs/17518ebd55ab7408311833095ce1542b to your computer and use it in GitHub Desktop.
Override CRA config in storybook
This file contains hidden or 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
| const DirectoryNamedWebpackPlugin = require('directory-named-webpack-plugin'); | |
| const findBabelLoader = config => | |
| config.module.rules.findIndex( | |
| rule => rule.use && rule.use[0] && rule.use[0].loader && rule.use[0].loader.includes('babel') | |
| ); | |
| const addBabelPlugin = plugin => config => { | |
| config.module.rules[findBabelLoader(config)].use[0].options.plugins.push(plugin); | |
| return config; | |
| }; | |
| const addBabelPreset = preset => config => { | |
| config.module.rules[findBabelLoader(config)].use[0].options.presets.push(preset); | |
| return config; | |
| }; | |
| module.exports = ({ config }) => { | |
| if (!config.resolve.plugins) { | |
| config.resolve.plugins = []; | |
| } | |
| config.resolve.plugins.push( | |
| new DirectoryNamedWebpackPlugin({ | |
| exclude: /node_modules/, | |
| }) | |
| ); | |
| config = addBabelPlugin('emotion')(config); | |
| config = addBabelPreset('@emotion/babel-preset-css-prop')(config); | |
| return config; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment