fix(vite): only transform js-like files in deno loader (#3234)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type { Plugin } from "vite";
|
||||
import {
|
||||
type Loader,
|
||||
MediaType,
|
||||
RequestedModuleType,
|
||||
ResolutionMode,
|
||||
Workspace,
|
||||
@@ -140,6 +141,7 @@ export function deno(): Plugin {
|
||||
|
||||
const maybeJsx = babelTransform({
|
||||
ssr: !!options?.ssr,
|
||||
media: result.mediaType,
|
||||
code,
|
||||
id: specifier,
|
||||
isDev,
|
||||
@@ -183,6 +185,7 @@ export function deno(): Plugin {
|
||||
|
||||
const maybeJsx = babelTransform({
|
||||
ssr: !!options?.ssr,
|
||||
media: result.mediaType,
|
||||
id,
|
||||
code,
|
||||
isDev,
|
||||
@@ -233,6 +236,32 @@ export function deno(): Plugin {
|
||||
};
|
||||
}
|
||||
|
||||
function isJsMediaType(media: MediaType): boolean {
|
||||
switch (media) {
|
||||
case MediaType.JavaScript:
|
||||
case MediaType.Jsx:
|
||||
case MediaType.Mjs:
|
||||
case MediaType.Cjs:
|
||||
case MediaType.TypeScript:
|
||||
case MediaType.Mts:
|
||||
case MediaType.Cts:
|
||||
case MediaType.Tsx:
|
||||
return true;
|
||||
|
||||
case MediaType.Dts:
|
||||
case MediaType.Dmts:
|
||||
case MediaType.Dcts:
|
||||
case MediaType.Css:
|
||||
case MediaType.Json:
|
||||
case MediaType.Html:
|
||||
case MediaType.Sql:
|
||||
case MediaType.Wasm:
|
||||
case MediaType.SourceMap:
|
||||
case MediaType.Unknown:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export type DenoSpecifier = string & { __deno: string };
|
||||
|
||||
function isDenoSpecifier(str: unknown): str is DenoSpecifier {
|
||||
@@ -286,10 +315,16 @@ function getDenoType(id: string, type: string): RequestedModuleType {
|
||||
}
|
||||
|
||||
function babelTransform(
|
||||
options: { ssr: boolean; code: string; id: string; isDev: boolean },
|
||||
options: {
|
||||
media: MediaType;
|
||||
ssr: boolean;
|
||||
code: string;
|
||||
id: string;
|
||||
isDev: boolean;
|
||||
},
|
||||
) {
|
||||
if (
|
||||
!/\.([tj]sx?|[mc[jt]s)$/.test(options.id) &&
|
||||
!isJsMediaType(options.media) &&
|
||||
!/^https?:\/\//.test(options.id)
|
||||
) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user