Skip to content

Custom Vite plugin for transforming SVGs only works in development mode, not in build mode. #15894

Closed Answered by gabrielecirulli
gabrielecirulli asked this question in Q&A
Discussion options

You must be logged in to vote

While messing around more with the Vite configuration, I noticed that there's a plugins field under worker.

It appears that the plugin must be placed within this field too if I want the worker code to be able to use the plugin. This appears to have fixed my issue.

Here's the updated vite.config.ts:

import { sveltekit } from "@sveltejs/kit/vite";
import { svgResourcePlugin } from "./plugins/svgResourcePlugin";
import { defineConfig } from "vitest/config";

const config = defineConfig({
  plugins: [svgResourcePlugin(), sveltekit()],
  worker: {
    format: "es",
    plugins: [svgResourcePlugin()],
  },
  test: {
    include: ["src/**/*.{test,spec}.{js,ts}"],
  },
});

export default config;

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gabrielecirulli
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant