Skip to content

Instantly share code, notes, and snippets.

@connebs
Created July 10, 2019 15:53
Show Gist options
  • Select an option

  • Save connebs/17518ebd55ab7408311833095ce1542b to your computer and use it in GitHub Desktop.

Select an option

Save connebs/17518ebd55ab7408311833095ce1542b to your computer and use it in GitHub Desktop.
Override CRA config in storybook
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