Skip to content
Discussion options

You must be logged in to vote

Ok writing custom plugin was easy so if someone has similar problem just use this:

const injectViteClientInDevModePlugin = (...sources: string[]): PluginOption => ({
  name: "inject-vite-client",
  enforce: "pre",
  transform(code: string, id: string) {
    if (process.env.NODE_ENV !== "development") return;
    if (sources.some((source) => id.endsWith(source))) {
      if (!code.includes("@vite/client")) {
        code = `import "/@vite/client";\n${code}`;
      }
      return { code, map: null };
    }
  },
});

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by igieon
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