The `vue-svg-inline-loader` is a Webpack loader designed for Vue 2 projects, enabling the inlining of SVG images directly into HTML templates. It parses `<img>` tags, replaces them with the actual SVG content, and offers built-in SVGO support for optimization. The loader is highly configurable, allowing for attribute manipulation, adding titles, and handling Vue directives on inlined SVGs. The current stable version is 2.1.5. It's important to note that this loader is *not compatible* with Vue 3 projects created via Vue CLI, as those environments utilize Vite/Rollup instead of Webpack; for such setups, the author recommends `vue-svg-inline-plugin`. Its primary differentiators include deep integration with the Webpack build process for Vue Single File Components, robust SVGO integration, and fine-grained control over inlined SVG attributes.
npm install vue-svg-inline-loaderVerified import paths — ran on the pinned version, not inferred.
Demonstrates configuring `vue-svg-inline-loader` in a Vue CLI (Webpack-based) project to inline SVG assets, applying SVGO optimizations, and showing a basic Vue component usage with an `<img>` tag that will be replaced.
For Vue 3 projects, switch to the `vue-svg-inline-plugin` which is designed for Vite environments. For existing Vue 2 projects, ensure your build environment uses Webpack.
No direct consumer fix needed if your environment supports ES6. If you were relying on the loader's transpiled output or `core-js@2`, update your own build process or `core-js` dependency.
Review SVG attribute handling in non-template contexts and adjust if unexpected changes in attribute duplication or removal occur after updating.
Verify that inlined SVGs correctly inherit attributes. If attributes are no longer inherited as expected, adjust your SVG definitions or loader options.
Ensure all image tags intended for SVG inlining are located within the `<template>` section of a Vue Single File Component.
Utilize the sprite option exclusively within Vue SFCs for proper functionality.
For Vue 3 projects, switch to the `vue-svg-inline-plugin`. For Vue 2 projects, ensure your build system uses Webpack.
Ensure your webpack configuration (e.g., `vue.config.js`) explicitly includes a rule for `.svg` files that uses `vue-svg-inline-loader`, and that any default or other SVG loaders are properly excluded or cleared for those files.
Add the `data-svg-inline` attribute to the `<img>` tag (or configure the loader to use a different attribute via `transformImageAttributesToVueDirectives`). Verify the loader is correctly applied in `vue.config.js` and the SVG path is resolvable by Webpack.