vitejs / vite

Next generation frontend tooling. It's fast!
http://vitejs.dev
MIT License
66.13k stars 5.91k forks source link

Compile svg as js file doesn't work in library mode since v5.2.x #17407

Open pmrotule opened 1 month ago

pmrotule commented 1 month ago

Describe the bug

We have a Vue component library where we use Vite to compile Vue components, but also compile svg files as Vue components using vite-svg-loader. After bumping our vite version from 5.1.7 to 5.2.12, our svg icons were not compiled anymore. No error in the console. We also have build.sourcemap set to true and the sourcemap files for the svg icons are generated, but not the actual js files.

image

I tried to log the code from the load hook of vite-svg-loader and the code is indeed logged. I created a custom plugin in the reproduction repository that show the logs. I also tried to modify the plugin to simply return export default { template: MY_SVG_CODE } instead of using vue/compiler-sfc, but no difference.

Reproduction

https://stackblitz.com/edit/vue3-vite-starter-sbiilv?file=package.json&view=editor

Steps to reproduce

image image

System Info

My computer:
  System:
    OS: macOS 13.5.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 57.20 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
    pnpm: 8.7.4 - ~/Library/pnpm/pnpm
    bun: 1.0.0 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 100.1.37.111
    Chrome: 125.0.6422.142
    Safari: 16.6
  npmPackages:
    @vitejs/plugin-vue: ^5.0.4 => 5.0.4 

Reproduction on Stackblitz:
  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-vue: ^5.0.5 => 5.0.5 
    vite: 5.2.12 => 5.2.12

Used Package Manager

yarn

Logs

Click to expand! ```shell yarn run v1.22.19 warning package.json: No license field $ vite build The CJS build of Vite's Node API is deprecated. See https://vitejs.dev/guide/troubleshooting.html#vite-cjs-node-api-deprecated for more details. vite v5.2.12 building for production... { filePath: '/home/projects/vue3-vite-starter-sbiilv/src/icons/IconGlobe.svg' } ✓ 4 modules transformed. dist/style.css 0.04 kB │ gzip: 0.06 kB dist/components/HelloWorld.vue.mjs 1.80 kB │ gzip: 0.82 kB │ map: 1.05 kB ✓ built in 141ms ✨ Done in 2.35s. ```

Validations

stackblitz[bot] commented 1 month ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.