svg-to-vue-loader
v1.0.6
Published
Webpack Loader to convert svg files to Vue components
Maintainers
Readme
Usage
Install
npm add --save-dev svg-to-vue-loader vue-loader @vue/compiler-sfc # Npm
yarn add -D svg-to-vue-loader vue-loader @vue/compiler-sfc # Yarn
pnpm add -D svg-to-vue-loader vue-loader @vue/compiler-sfc # Pnpm
Config
// webpack.config.ts
import type webpack from 'webpack';
import { VueLoaderPlugin } from 'vue-loader';
import type svgToVueLoaderOptions from 'svg-to-vue-loader/options';
export default {
// ...
// support cache
cache: {
type: 'filesystem',
},
module: {
rules: [
{
test: /\.svg$/,
use: [
{
use: [
'vue-loader',
{
loader: 'svg-to-vue-loader',
options: {
// Your options here
} satisfies svgToVueLoaderOptions,
},
],
},
],
},
],
},
plugins: [new VueLoaderPlugin()],
// ..
} satisfies webpack.Configuration;
or
// webpack.config.ts
import { VueLoaderPlugin } from 'vue-loader';
/**
* @type {import('webpack').Configuration}
*/
export default {
// ...
// support cache
cache: {
type: 'filesystem',
},
module: {
rules: [
{
test: /\.svg$/,
use: [
{
loader: 'psvg-to-vue-loader',
use: [
'vue-loader',
{
loader: 'svg-to-vue-loader',
/** @type {import('svg-to-vue-loader/options')} */
options: {
// Your options here
},
},
],
},
],
},
],
},
plugins: [new vueLoaderPlugin()],
// ..
};
Types
// type.d.ts
declare module '*.svg' {
import type { componentType } from 'svg-to-vue-loader';
export default componentType;
}