chore: simplify jsx config handling (#1973)
This commit is contained in:
+10
-13
@@ -16,16 +16,12 @@ export interface EsbuildBuilderOptions {
|
||||
/** The path to the deno.json / deno.jsonc config file. */
|
||||
configPath: string;
|
||||
/** The JSX configuration. */
|
||||
jsxConfig: JSXConfig;
|
||||
jsx?: string;
|
||||
jsxImportSource?: string;
|
||||
target: string | string[];
|
||||
absoluteWorkingDir: string;
|
||||
}
|
||||
|
||||
export interface JSXConfig {
|
||||
jsx: "react" | "react-jsx";
|
||||
jsxImportSource?: string;
|
||||
}
|
||||
|
||||
export class EsbuildBuilder implements Builder {
|
||||
#options: EsbuildBuilderOptions;
|
||||
|
||||
@@ -83,8 +79,14 @@ export class EsbuildBuilder implements Builder {
|
||||
sourcemap: opts.dev ? "linked" : false,
|
||||
...minifyOptions,
|
||||
|
||||
jsx: JSX_RUNTIME_MODE[opts.jsxConfig.jsx],
|
||||
jsxImportSource: opts.jsxConfig.jsxImportSource,
|
||||
jsx: opts.jsx === "react"
|
||||
? "transform"
|
||||
: opts.jsx === "react-native" || opts.jsx === "preserve"
|
||||
? "preserve"
|
||||
: !opts.jsxImportSource
|
||||
? "transform"
|
||||
: "automatic",
|
||||
jsxImportSource: opts.jsxImportSource ?? "preact",
|
||||
|
||||
absWorkingDir,
|
||||
outdir: ".",
|
||||
@@ -126,11 +128,6 @@ export class EsbuildBuilder implements Builder {
|
||||
}
|
||||
}
|
||||
|
||||
const JSX_RUNTIME_MODE = {
|
||||
"react": "transform",
|
||||
"react-jsx": "automatic",
|
||||
} as const;
|
||||
|
||||
function buildIdPlugin(buildId: string): Plugin {
|
||||
const file = import.meta.resolve("../runtime/build_id.ts");
|
||||
const url = new URL(file);
|
||||
|
||||
@@ -28,9 +28,7 @@ Deno.test("esbuild snapshot with cwd=Deno.cwd()", async () => {
|
||||
entrypoints: {
|
||||
main: mainEntry,
|
||||
},
|
||||
jsxConfig: {
|
||||
jsx: "react-jsx",
|
||||
},
|
||||
jsx: "react-jsx",
|
||||
target: "es2020",
|
||||
});
|
||||
|
||||
@@ -50,9 +48,7 @@ Deno.test({
|
||||
entrypoints: {
|
||||
main: mainEntry,
|
||||
},
|
||||
jsxConfig: {
|
||||
jsx: "react-jsx",
|
||||
},
|
||||
jsx: "react-jsx",
|
||||
target: "es2020",
|
||||
});
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ export {
|
||||
EsbuildBuilder,
|
||||
type EsbuildBuilderOptions,
|
||||
EsbuildSnapshot,
|
||||
type JSXConfig,
|
||||
} from "./esbuild.ts";
|
||||
export { AotSnapshot } from "./aot_snapshot.ts";
|
||||
export interface Builder {
|
||||
|
||||
Reference in New Issue
Block a user