Skip to content

Commit e7c87d5

Browse files
fix: vite resolution things
1 parent d026375 commit e7c87d5

9 files changed

Lines changed: 510 additions & 295 deletions

File tree

packages/plugin-vite/src/plugins/commonjs.ts

Lines changed: 0 additions & 268 deletions
This file was deleted.

packages/plugin-vite/src/plugins/deno.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
Workspace,
77
} from "@deno/loader";
88
import * as path from "@std/path";
9+
import * as babel from "@babel/core";
10+
import { npmWorkaround } from "./patches/npm_workaround.ts";
911

1012
interface DenoState {
1113
type: RequestedModuleType;
@@ -140,6 +142,21 @@ export function deno(): Plugin {
140142

141143
const code = new TextDecoder().decode(result.code);
142144

145+
// Ensure vite never sees `npm:` specifiers. The load call here
146+
// can potentially insert JSX pragmas which refer to `npm:`
147+
// specifiers.
148+
const res = babel.transformSync(code, {
149+
filename: id,
150+
babelrc: false,
151+
plugins: [npmWorkaround],
152+
});
153+
if (res?.code) {
154+
return {
155+
code: res.code,
156+
map: res.map,
157+
};
158+
}
159+
143160
return {
144161
code,
145162
};

packages/plugin-vite/src/plugins/patches.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import type { Plugin } from "vite";
22
import * as babel from "@babel/core";
3-
import { npmWorkaround } from "./npm_workaround.ts";
3+
import { npmWorkaround } from "./patches/npm_workaround.ts";
4+
import { cjsPlugin } from "./patches/commonjs.ts";
5+
import { jsxComments } from "./patches/jsx_comment.ts";
46

57
export function patches(): Plugin {
68
return {
@@ -12,7 +14,7 @@ export function patches(): Plugin {
1214
const res = babel.transformSync(code, {
1315
filename: id,
1416
babelrc: false,
15-
plugins: [npmWorkaround],
17+
plugins: [npmWorkaround, cjsPlugin, jsxComments],
1618
});
1719

1820
if (res?.code) {

0 commit comments

Comments
 (0)