fix(vite): babel transform being applied for non-js files (#3238)
This commit is contained in:
@@ -3256,6 +3256,7 @@
|
|||||||
"packages/plugin-vite": {
|
"packages/plugin-vite": {
|
||||||
"dependencies": [
|
"dependencies": [
|
||||||
"jsr:@deno/loader@~0.3.2",
|
"jsr:@deno/loader@~0.3.2",
|
||||||
|
"jsr:@marvinh-test/import-json@^0.0.1",
|
||||||
"npm:@babel/core@^7.28.0",
|
"npm:@babel/core@^7.28.0",
|
||||||
"npm:@babel/preset-react@^7.27.1",
|
"npm:@babel/preset-react@^7.27.1",
|
||||||
"npm:@prefresh/vite@^2.4.8",
|
"npm:@prefresh/vite@^2.4.8",
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { value } from "@marvinh-test/import-json";
|
||||||
|
|
||||||
|
export const handler = () => Response.json(value);
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
"@babel/core": "npm:@babel/core@^7.28.0",
|
"@babel/core": "npm:@babel/core@^7.28.0",
|
||||||
"@babel/preset-react": "npm:@babel/preset-react@^7.27.1",
|
"@babel/preset-react": "npm:@babel/preset-react@^7.27.1",
|
||||||
"@deno/loader": "jsr:@deno/loader@^0.3.2",
|
"@deno/loader": "jsr:@deno/loader@^0.3.2",
|
||||||
|
"@marvinh-test/import-json": "jsr:@marvinh-test/import-json@^0.0.1",
|
||||||
"@prefresh/vite": "npm:@prefresh/vite@^2.4.8",
|
"@prefresh/vite": "npm:@prefresh/vite@^2.4.8",
|
||||||
"@tailwindcss/vite": "npm:@tailwindcss/vite@^4.1.12",
|
"@tailwindcss/vite": "npm:@tailwindcss/vite@^4.1.12",
|
||||||
"@types/babel__core": "npm:@types/babel__core@^7.20.5",
|
"@types/babel__core": "npm:@types/babel__core@^7.20.5",
|
||||||
|
|||||||
@@ -323,10 +323,7 @@ function babelTransform(
|
|||||||
isDev: boolean;
|
isDev: boolean;
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
if (
|
if (!isJsMediaType(options.media)) {
|
||||||
!isJsMediaType(options.media) &&
|
|
||||||
!/^https?:\/\//.test(options.id)
|
|
||||||
) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -340,3 +340,24 @@ Deno.test({
|
|||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "vite build - import json from jsr dependency",
|
||||||
|
fn: async () => {
|
||||||
|
await using res = await buildVite(DEMO_DIR);
|
||||||
|
|
||||||
|
await withChildProcessServer(
|
||||||
|
{
|
||||||
|
cwd: res.tmp,
|
||||||
|
args: ["serve", "-A", "--port", "0", "_fresh/server.js"],
|
||||||
|
},
|
||||||
|
async (address) => {
|
||||||
|
const res = await fetch(`${address}/tests/dep_json`);
|
||||||
|
const json = await res.json();
|
||||||
|
expect(json.name).toEqual("@marvinh-test/import-json");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
sanitizeOps: false,
|
||||||
|
sanitizeResources: false,
|
||||||
|
});
|
||||||
|
|||||||
@@ -238,3 +238,16 @@ Deno.test({
|
|||||||
sanitizeResources: false,
|
sanitizeResources: false,
|
||||||
sanitizeOps: false,
|
sanitizeOps: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Deno.test({
|
||||||
|
name: "vite dev - json from jsr dependency",
|
||||||
|
fn: async () => {
|
||||||
|
await withDevServer(DEMO_DIR, async (address) => {
|
||||||
|
const res = await fetch(`${address}/tests/dep_json`);
|
||||||
|
const json = await res.json();
|
||||||
|
expect(json.name).toEqual("@marvinh-test/import-json");
|
||||||
|
});
|
||||||
|
},
|
||||||
|
sanitizeResources: false,
|
||||||
|
sanitizeOps: false,
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user