Load svg using vue-svg-loader not working
See original GitHub issue.storybook/webpack.config.js
const path = require('path');
const fs = require('fs');
// Export a function. Accept the base config as the only param.
module.exports = async ({ config, mode }) => {
// `mode` has a value of 'DEVELOPMENT' or 'PRODUCTION'
// You can change the configuration based on that.
// 'PRODUCTION' is used when building the static version of storybook.
// Make whatever fine-grained changes you need
config.module.rules.push({
test: /\.scss$/,
use: [
"style-loader", // creates style nodes from JS strings
"css-loader", // translates CSS into CommonJS
"sass-loader" // compiles Sass to CSS, using Node Sass by default
]
});
config.module.rules.push({
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {name: 'assets/[name].[hash:8].[ext]'},
},
],
});
config.module.rules.push({
test: /\.vue$/,
use: [
{
loader: "vue-svg-inline-loader",
options: { /* ... */ }
}
]
});
config.module.rules.push({
test: /\.svg$/,
loader: 'vue-svg-loader',
options: {name: 'assets/[name].[hash:8].[ext]'},
});
config.resolve.alias['@'] = path.resolve('src')
// Return the altered config
return { ...config, node: { fs: 'empty' } };
};
index.vue
<template>
<div>
<IconTest/>
</div>
</template>
<script>
import IconTest from "@/assets/svg/test-icon.svg"
export default {
components:{
IconTest
}
}
</script>
error:
[Vue warn]: Invalid Component definition: static/media/test-icon.d9ed9e17.svg
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:18 (4 by maintainers)
Top Results From Across the Web
SVG loading vue-svg-loader; [Vue warn]: Invalid Component ...
yes, I would like to use vue-svg-loader instead of file-loader and I would like to bypass it in case of SVGs,.. How and...
Read more >Using SVG and Vue.js: A complete guide - LogRocket Blog
This is a complete guide to using SVG with Vue, including practical examples and best practices to help you along the way.
Read more >vue-svg-loader
This loader inlines the SVGs which enables you to style aspects like for example stroke/fill color. Optimized. Each SVG you import is optimized...
Read more >vue-svg-inline-loader - npm
Webpack loader used for inline replacement of SVG images with actual ... Start using vue-svg-inline-loader in your project by running `npm i ...
Read more >Vue 3 not rendering children elements in SVG dynamic ...
I'd say the problem is that it was designed to convert SVG's to Vue 2 components. Vue 3 has different internals so depending...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@devtoni’s workaround worked for me too, with one additional change.
As of Storybook
v6.9.0
, I had to addpdf
to the test regex that was being replaced. The updated code that worked for me is:https://github.com/storybookjs/vue-cli-plugin-storybook/issues/69#issuecomment-668171815