fix(vite): npm resolution + cjs + duplicated preact signals (#3211)
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user