A live demo is available through the CodeSandBox of the repo.
nuxt-svg-loader
as a dependency using yarn or npm to your projectnuxt-svg-loader
to modules
section of nuxt.config.js
{
modules: [
'nuxt-svg-loader',
]
}
?inline
at the end of the file path
<template>
<nav>
<a href="https://github.com/vuejs/vue">
<VueLogo />
Vue
</a>
<a href="https://github.com/svg/svgo">
<SVGOLogo />
SVGO
</a>
<a href="https://github.com/webpack/webpack">
<WebpackLogo />
webpack
</a>
<!-- Inline svg -->
<a class="with-background-svg" href="https://github.com/webpack/webpack">
webpack
</a>
<a href="https://github.com/webpack/webpack">
<img src="https://github.com/Developmint/nuxt-svg-loader/raw/master/./components/NuxtTwo.svg?inline">
webpack>
</a>
</nav>
</template>
<script>
import VueLogo from '@/assets/svg/vue.svg';
import SVGOLogo from '@/assets/svg/svgo.svg';
import WebpackLogo from '@/assets/svg/webpack.svg';
export default { name: 'Example', components: { VueLogo, SVGOLogo, WebpackLogo, } };
- No more options are needed. It'll simply work
## Configuration
The plugin will work seamlessly out of the box.
It will also include SVGO defaults to avoid collisions between your optimized SVG files!
If you want to configure the underlying loader (or SVGO), you can do that easily as well.
(All options available [here](https://github.com/egoist/svg-to-vue-component#loader-options))
```js
// file: nuxt.config.js
export default {
// ...
// Your loader options as svgLoader object
svgLoader: {
svgoConfig: {
plugins: [
{ prefixIds: false } // Disables prefixing for SVG IDs
]
}
}
}
svgo
to svgoConfig
export default {
svgLoader: {
svgo: { //Rename to svgoConfig
plugins: [
{ prefixIds: true } // Delete that line (or the whole svgLoader object if you don't have any other configurations)
]
}
}
}
If you turn on Eslint on save by server, you should exclude .svg
files of eslint-loader
.
Example:
// nuxt.config.js
build: {
extend(config, ctx) {
// Run ESLint on save
if (ctx.isDev && ctx.isClient) {
config.module.rules.push({
enforce: 'pre',
test: /\.(js|vue)$/,
loader: 'eslint-loader',
exclude: /(node_modules)|(\.svg$)/ /* <--- here */
})
}
}
}
yarn install
or npm install
npm run dev
Copyright (c) Alexander Lichter