Nuxt SVGO is a Nuxt 3 module designed to integrate optimized SVG files directly into Vue applications as components. Currently at version 4.2.6, the library maintains a consistent release cadence, primarily focusing on compatibility with the latest Nuxt monorepo updates. Feature additions, such as Nuxt 3 layers support (v4.2.0) and type declaration generation for Vite (v4.1.0), are rolled out periodically. Its key differentiation lies in seamlessly combining SVGO's optimization capabilities with Nuxt's component system, allowing developers to import `.svg` files directly as Vue components or leverage an auto-import mechanism. It offers flexibility through options for custom import paths, component prefixes, and controlling global registration, effectively addressing concerns about bundle size with a large number of icons. This module simplifies SVG asset management by transforming raw SVG files into optimized, ready-to-use Vue components within the Nuxt ecosystem.
npm install nuxt-svgoVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to configure nuxt-svgo and use both direct SVG file imports as Vue components, and auto-imported SVG components (Vite-style) in a Nuxt 3 application, showing different sizing options and requiring example SVG files.
Ensure all peer dependencies listed in `package.json` (or the installation instructions) are installed, e.g., `npm install svgo-loader vue vue-loader vue-svg-loader`.
If `global: false` is set, either manually import each SVG component you wish to use (`import MyIcon from '~/assets/icons/my-icon.svg'`) in your script setup, or ensure your build setup is correctly tree-shaking and importing components as needed by Nuxt/Vite without explicit global registration.
Add `:fontControlled="false"` to your SVG component when you intend to manage its dimensions using `width`, `height`, or other explicit sizing CSS properties, e.g., `<IconHome class="w-5 h-5" :fontControlled="false" />`.
Review your `svgo.autoImportPath` configuration in relation to your Nuxt Layers setup. Ensure the paths correctly resolve to the desired SVG assets within your layers or extend configurations where necessary.
If `autoImportPath` is `false`, you must explicitly `import` each SVG file as a Vue component in your script section, e.g., `import MySvg from '~/assets/my-svg.svg'`. Ensure your component templates use the imported name `<MySvg />`.
Verify the exact path to your SVG file. If using direct imports, ensure `svgo.autoImportPath` is not set in a way that prevents resolution, or use the auto-import feature for SVGs in the designated path. Check file existence and correct casing.
Restart your Nuxt development server to regenerate types. Ensure `svgo.global` is not `false` if you intend to use auto-import without explicit script imports. If `global: false`, you must explicitly import the component in your script block, and potentially declare module types for `.svg` files if not automatically handled.
Configure SVGO options in your `nuxt.config.ts` (`svgo.svgoConfig`) to preserve necessary attributes or styles. If using custom styles, ensure `:fontControlled="false"` is set on the component. Inspect the rendered SVG in developer tools to see what attributes are missing or overridden.