Open gsaada opened 5 years ago
@gsaada There are existing rules that test for /\.vue$/
or /\.svg$/
files like you do and my guess is that they are conflicting. You should leverage Webpack include/exclude rule parameters to avoid conflicts.
Here’s an example on how to modify an existing rule in Storybook Webpack config to add an exclude
option:
// .storybook/main.js
const path = require('path');
module.exports = {
// ...
webpackFinal: (config) => {
// Prevent Storybook generic SVG loader from taking care of SVG icons going in the sprite
const fileLoader = config.module.rules.find((rule, i) => {
return rule.loader && rule.loader.match(/file-loader/);
});
fileLoader.exclude = path.resolve('./src/assets/icons');
// Custom loader with an `include` to limit the loader to only icons
config.module.rules.push({
test: /\.svg$/,
include: path.resolve('./src/assets/icons'),
use: [
{
loader: 'svg-sprite-loader',
},
],
});
}
// ...
};
This config solved the issue for me:
module.exports = ({ config }) => {
let rule = config.module.rules.find(r =>
// it can be another rule with file loader
// we should get only svg related
r.test && r.test.toString().includes('svg') &&
// file-loader might be resolved to js file path so "endsWith" is not reliable enough
r.loader && r.loader.includes('file-loader')
);
rule.test = /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani)(\?.*)?$/;
config.module.rules.push(
{
test: /\.svg$/,
use: ['vue-svg-loader']
}
)
// ...
return config;
}
Original post: https://stackoverflow.com/questions/56971513/storybook-does-not-load-svgs-in-components-of-vue-project
.storybook/webpack.config.js
index.vue
error:
[Vue warn]: Invalid Component definition: static/media/test-icon.d9ed9e17.svg