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 { Plugin } from "vite";
|
||||||
import {
|
import {
|
||||||
type Loader,
|
type Loader,
|
||||||
|
MediaType,
|
||||||
RequestedModuleType,
|
RequestedModuleType,
|
||||||
ResolutionMode,
|
ResolutionMode,
|
||||||
Workspace,
|
Workspace,
|
||||||
@@ -140,6 +141,7 @@ export function deno(): Plugin {
|
|||||||
|
|
||||||
const maybeJsx = babelTransform({
|
const maybeJsx = babelTransform({
|
||||||
ssr: !!options?.ssr,
|
ssr: !!options?.ssr,
|
||||||
|
media: result.mediaType,
|
||||||
code,
|
code,
|
||||||
id: specifier,
|
id: specifier,
|
||||||
isDev,
|
isDev,
|
||||||
@@ -183,6 +185,7 @@ export function deno(): Plugin {
|
|||||||
|
|
||||||
const maybeJsx = babelTransform({
|
const maybeJsx = babelTransform({
|
||||||
ssr: !!options?.ssr,
|
ssr: !!options?.ssr,
|
||||||
|
media: result.mediaType,
|
||||||
id,
|
id,
|
||||||
code,
|
code,
|
||||||
isDev,
|
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 };
|
export type DenoSpecifier = string & { __deno: string };
|
||||||
|
|
||||||
function isDenoSpecifier(str: unknown): str is DenoSpecifier {
|
function isDenoSpecifier(str: unknown): str is DenoSpecifier {
|
||||||
@@ -286,10 +315,16 @@ function getDenoType(id: string, type: string): RequestedModuleType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function babelTransform(
|
function babelTransform(
|
||||||
options: { ssr: boolean; code: string; id: string; isDev: boolean },
|
options: {
|
||||||
|
media: MediaType;
|
||||||
|
ssr: boolean;
|
||||||
|
code: string;
|
||||||
|
id: string;
|
||||||
|
isDev: boolean;
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
!/\.([tj]sx?|[mc[jt]s)$/.test(options.id) &&
|
!isJsMediaType(options.media) &&
|
||||||
!/^https?:\/\//.test(options.id)
|
!/^https?:\/\//.test(options.id)
|
||||||
) {
|
) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user