vue-svgicon is a build-time utility for Vue 2.x projects that converts raw SVG files into optimized Vue components. It provides both a command-line interface (`vsvg`) and a programmatic API to automate the generation process, supporting features like custom icon templates, ES6 module output, and integration with SVGO for further optimization of SVG assets. The current stable version for Vue 2 applications is 3.3.2. While this specific package targets Vue 2, the project has evolved into the `@yzfe/vue-svgicon` package for Vue 3 compatibility, which is actively maintained. The core differentiator is its approach of pre-compiling SVGs into Vue components, which can lead to better performance by embedding optimized SVGs directly into the application bundle rather than loading them at runtime, offering a distinct advantage over runtime SVG loaders.
npm install vue-svgiconVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to register the `vue-svgicon` component in a Vue 2 application, include essential global CSS for styling, and use a generated SVG icon within a component. It also provides the necessary command-line steps to generate a sample 'vue.svg' icon from a source SVG file.
Adjust your CSS selectors or JavaScript code to use the new '_' separator. Alternatively, you can customize the separator using the `--idSP` option during icon generation if strict backward compatibility is required.
For Vue 3 development, install `@yzfe/vue-svgicon` and its ecosystem tools (e.g., `vite-plugin-svgicon` for Vite or `@yzfe/vue-cli-plugin-svgicon` for Vue CLI) and adapt your codebase accordingly. Do not use `vue-svgicon` v3.x in Vue 3 projects.
Ensure the recommended CSS snippet (or a customized version based on your needs) is included in your global stylesheets. Refer to the `vue-svgicon` documentation for the 'recommended css code for vue-svgicon'.
Use the command `vsvg -s /path/to/svg/source -t /path/for/generated/components --ext ts` to ensure TypeScript definition files are generated alongside the icon components. Verify your `tsconfig.json` is configured to correctly handle these generated `.ts` or `.d.ts` files.
First, ensure you have executed the `vsvg` command to generate your SVG icon components. Second, verify that the import statement for your specific icon (e.g., `import 'icons/my-icon'`) is correct and that the `name` prop on your `<svgicon>` component (e.g., `<svgicon name='my-icon'></svgicon>`) exactly matches the icon's original filename (without the extension).
Add the recommended global CSS rules for `.svg-icon`, `.svg-fill`, `.svg-up`, etc., to your project's main stylesheet. Consult the `vue-svgicon` documentation's 'recommended css code for vue-svgicon' section for the exact styles.
Double-check the import path for the programmatic `build` function: `import build from 'vue-svgicon/dist/lib/build'`. Ensure that `vue-svgicon` is correctly installed in your `node_modules` directory and that your bundler's module resolution configuration is correctly set up to find deep imports within packages.