Skip to content

Instantly share code, notes, and snippets.

@jessarcher
Last active February 9, 2020 23:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jessarcher/fc1a1bf87f8131b3beccc73b2209b667 to your computer and use it in GitHub Desktop.
Save jessarcher/fc1a1bf87f8131b3beccc73b2209b667 to your computer and use it in GitHub Desktop.
Storybook config to replace the loader for SVG files
module.exports = {
webpackFinal: async config => {
// Remove 'svg' from the existing regex covering all images
const svgRule = config.module.rules.find(rule => typeof rule.test.test === 'function' && rule.test.test('.svg'));
svgRule.test = new RegExp(svgRule.test.source.replace('svg|', ''))
// Add a new rule for svg files only
config.module.rules.push({
test: /\.svg$/,
use: [
{
loader: 'html-loader',
options: {
minimize: true
}
}
]
});
return config
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment