fix: workaround vite treating npm: as built-ins (#3205)
Upstream fix: https://github.com/vitejs/vite/pull/20558
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import type { Plugin } from "vite";
|
||||
import * as babel from "@babel/core";
|
||||
import { cjsPlugin } from "./commonjs.ts";
|
||||
import { npmWorkaround } from "./npm_workaround.ts";
|
||||
|
||||
export function patches(): Plugin {
|
||||
return {
|
||||
name: "fresh:patches",
|
||||
applyToEnvironment() {
|
||||
return true;
|
||||
},
|
||||
resolveId(id) {
|
||||
if (id.startsWith("deno-npm:")) {
|
||||
return id.slice("deno-".length);
|
||||
}
|
||||
},
|
||||
transform(code, id) {
|
||||
const res = babel.transformSync(code, {
|
||||
filename: id,
|
||||
babelrc: false,
|
||||
plugins: [npmWorkaround, cjsPlugin],
|
||||
});
|
||||
|
||||
if (res?.code) {
|
||||
return {
|
||||
code: res.code,
|
||||
map: res.map,
|
||||
};
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user