Skip to content

Commit a743b0c

Browse files
fix(vite): account for query params in module ids (#3257)
1 parent f1fe325 commit a743b0c

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import * as path from "@std/path";
1010
import * as babel from "@babel/core";
1111
import babelReact from "@babel/preset-react";
1212
import { httpAbsolute } from "./patches/http_absolute.ts";
13+
import { JS_REG } from "../utils.ts";
1314

1415
interface DenoState {
1516
type: RequestedModuleType;
@@ -180,7 +181,7 @@ export function deno(): Plugin {
180181
// Skip for non-js files like `.css`
181182
if (
182183
meta.type === RequestedModuleType.Default &&
183-
!/\.([tj]sx?|[mc]?[tj]s)$/.test(id)
184+
!JS_REG.test(id)
184185
) {
185186
return;
186187
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { jsxComments } from "./patches/jsx_comment.ts";
55
import babelReact from "@babel/preset-react";
66
import { inlineEnvVarsPlugin } from "./patches/inline_env_vars.ts";
77
import { removePolyfills } from "./patches/remove_polyfills.ts";
8+
import { JS_REG, JSX_REG } from "../utils.ts";
89

910
export function patches(): Plugin {
1011
let isDev = false;
@@ -18,10 +19,10 @@ export function patches(): Plugin {
1819
return true;
1920
},
2021
transform(code, id, options) {
21-
if (!/\.([tj]sx?|[mc][tj]s)$/.test(id)) return;
22+
if (!JS_REG.test(id)) return;
2223

2324
const presets = [];
24-
if (!options?.ssr && /\.(tsx?|m[jt]s)$/.test(id)) {
25+
if (!options?.ssr && JSX_REG.test(id)) {
2526
presets.push([babelReact, {
2627
runtime: "automatic",
2728
importSource: "preact",

packages/plugin-vite/src/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as path from "@std/path";
22
import type { FsRouteFileNoMod, UniqueNamer } from "fresh/internal-dev";
33

4+
export const JS_REG = /\.([tj]sx?|[mc]?[tj]s)(\?.*)?$/;
5+
export const JSX_REG = /\.[tj]sx?(\?.*)?$/;
6+
47
export function pathWithRoot(fileOrDir: string, root?: string): string {
58
if (path.isAbsolute(fileOrDir)) return fileOrDir;
69

0 commit comments

Comments
 (0)