Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/plugin-vite/src/plugins/deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as path from "@std/path";
import * as babel from "@babel/core";
import babelReact from "@babel/preset-react";
import { httpAbsolute } from "./patches/http_absolute.ts";
import { JS_REG } from "../utils.ts";

interface DenoState {
type: RequestedModuleType;
Expand Down Expand Up @@ -180,7 +181,7 @@ export function deno(): Plugin {
// Skip for non-js files like `.css`
if (
meta.type === RequestedModuleType.Default &&
!/\.([tj]sx?|[mc]?[tj]s)$/.test(id)
!JS_REG.test(id)
) {
return;
}
Expand Down
5 changes: 3 additions & 2 deletions packages/plugin-vite/src/plugins/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { jsxComments } from "./patches/jsx_comment.ts";
import babelReact from "@babel/preset-react";
import { inlineEnvVarsPlugin } from "./patches/inline_env_vars.ts";
import { removePolyfills } from "./patches/remove_polyfills.ts";
import { JS_REG, JSX_REG } from "../utils.ts";

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

const presets = [];
if (!options?.ssr && /\.(tsx?|m[jt]s)$/.test(id)) {
if (!options?.ssr && JSX_REG.test(id)) {
presets.push([babelReact, {
runtime: "automatic",
importSource: "preact",
Expand Down
3 changes: 3 additions & 0 deletions packages/plugin-vite/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import * as path from "@std/path";
import type { FsRouteFileNoMod, UniqueNamer } from "fresh/internal-dev";

export const JS_REG = /\.([tj]sx?|[mc]?[tj]s)(\?.*)?$/;
export const JSX_REG = /\.[tj]sx?(\?.*)?$/;

export function pathWithRoot(fileOrDir: string, root?: string): string {
if (path.isAbsolute(fileOrDir)) return fileOrDir;

Expand Down
Loading