cyyynthia / vite-plugin-magical-svg

An all-in-one Vite plugin that magically makes working with SVGs and bundling them a breeze.
BSD 3-Clause "New" or "Revised" License
45 stars 6 forks source link

Issue with default export when used in a esm project ("type": "module") #6

Closed belgattitude closed 11 months ago

belgattitude commented 11 months ago

Got an issue when importing the plugin... the default cjs export might not be correct as confirmed by https://arethetypeswrong.github.io/?p=vite-plugin-magical-svg%401.0.3.

Issue

TypeError: magicalSvg is not a function

Workaround

import magicalSvg from 'vite-plugin-magical-svg';
import tsconfigPaths from 'vite-tsconfig-paths';
import { defineConfig } from 'vitest/config';
export default defineConfig({
  plugins: [
    tsconfigPaths(),
    (magicalSvg as unknown as { default: typeof magicalSvg }).default({
      target: 'react',
      svgo: false,
    }),
  ],