jpkleemans / vite-svg-loader

Vite plugin to load SVG files as Vue components
MIT License
555 stars 59 forks source link

doesn't work with alias #50

Closed mikob closed 2 years ago

mikob commented 2 years ago
import ErrorSvg from "../../src/assets/icons/error.svg?component";
console.log("ErrorSvg", ErrorSvg);

works.

import ErrorSvg from "@/assets/icons/error.svg?component";
console.log("ErrorSvg", ErrorSvg);

always logs a base64-encoded url.

relevant vite config:

  plugins: [
    vue(),
    svgLoader({
      defaultImport: "component", // or 'raw' or 'url'
    }),
  ],
  resolve: {
    alias: [{ find: "@", replacement: "./src" }],
  },
jpkleemans commented 2 years ago

Hi, I think you need to change the resolve config to:

alias: [{ find: "@", replacement: path.resolve(__dirname, './src') }],

If that doesn't work, could you share a Code Sandbox to reproduce the problem?

mikob commented 2 years ago

@jpkleemans nice, that worked, thank you! Would you mind helping me understand why that's needed?