fix(vite): npm resolution + cjs + duplicated preact signals (#3211)

This commit is contained in:
Marvin Hagemeister
2025-08-16 19:26:39 +02:00
committed by GitHub
parent 71071171ed
commit 59549c9532
18 changed files with 1047 additions and 466 deletions
+24 -3
View File
@@ -1,18 +1,39 @@
import type { Plugin } from "vite";
import * as babel from "@babel/core";
import { npmWorkaround } from "./npm_workaround.ts";
import { cjsPlugin } from "./patches/commonjs.ts";
import { jsxComments } from "./patches/jsx_comment.ts";
import babelReact from "@babel/preset-react";
export function patches(): Plugin {
let isDev = false;
return {
name: "fresh:patches",
config(_, env) {
isDev = env.command === "serve";
},
applyToEnvironment() {
return true;
},
transform(code, id) {
transform(code, id, options) {
if (code.includes("__commonJS") || /\.(tsx?|m[jt]s)$/.test(id)) {
return;
}
const presets = [];
if (!options?.ssr) {
presets.push([babelReact, {
runtime: "automatic",
importSource: "preact",
development: isDev,
}]);
}
const res = babel.transformSync(code, {
filename: id,
babelrc: false,
plugins: [npmWorkaround],
plugins: [cjsPlugin, jsxComments],
presets,
});
if (res?.code) {