feat: add build.target option (#1798)
This commit is contained in:
@@ -20,6 +20,7 @@ export interface EsbuildBuilderOptions {
|
|||||||
configPath: string;
|
configPath: string;
|
||||||
/** The JSX configuration. */
|
/** The JSX configuration. */
|
||||||
jsxConfig: JSXConfig;
|
jsxConfig: JSXConfig;
|
||||||
|
target: string | string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface JSXConfig {
|
export interface JSXConfig {
|
||||||
@@ -55,7 +56,7 @@ export class EsbuildBuilder implements Builder {
|
|||||||
entryPoints: opts.entrypoints,
|
entryPoints: opts.entrypoints,
|
||||||
|
|
||||||
platform: "browser",
|
platform: "browser",
|
||||||
target: ["chrome99", "firefox99", "safari15"],
|
target: this.#options.target,
|
||||||
|
|
||||||
format: "esm",
|
format: "esm",
|
||||||
bundle: true,
|
bundle: true,
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ export async function getFreshConfigWithDefaults(
|
|||||||
manifest,
|
manifest,
|
||||||
build: {
|
build: {
|
||||||
outDir: "",
|
outDir: "",
|
||||||
|
target: opts.build?.target ?? ["chrome99", "firefox99", "safari15"],
|
||||||
},
|
},
|
||||||
plugins: opts.plugins ?? [],
|
plugins: opts.plugins ?? [],
|
||||||
staticDir: "",
|
staticDir: "",
|
||||||
|
|||||||
@@ -382,6 +382,7 @@ export async function getServerContext(opts: InternalFreshOptions) {
|
|||||||
jsxConfig,
|
jsxConfig,
|
||||||
opts.dev,
|
opts.dev,
|
||||||
opts.router ?? DEFAULT_ROUTER_OPTIONS,
|
opts.router ?? DEFAULT_ROUTER_OPTIONS,
|
||||||
|
opts.build.target,
|
||||||
snapshot,
|
snapshot,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -416,6 +417,7 @@ export class ServerContext {
|
|||||||
jsxConfig: JSXConfig,
|
jsxConfig: JSXConfig,
|
||||||
dev: boolean,
|
dev: boolean,
|
||||||
routerOptions: RouterOptions,
|
routerOptions: RouterOptions,
|
||||||
|
target: string | string[],
|
||||||
snapshot: BuildSnapshot | null = null,
|
snapshot: BuildSnapshot | null = null,
|
||||||
) {
|
) {
|
||||||
this.#routes = routes;
|
this.#routes = routes;
|
||||||
@@ -435,6 +437,7 @@ export class ServerContext {
|
|||||||
configPath,
|
configPath,
|
||||||
dev: this.#dev,
|
dev: this.#dev,
|
||||||
jsxConfig,
|
jsxConfig,
|
||||||
|
target,
|
||||||
});
|
});
|
||||||
this.#routerOptions = routerOptions;
|
this.#routerOptions = routerOptions;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,13 @@ export interface FreshOptions {
|
|||||||
* This can be an absolute path, a file URL or a relative path.
|
* This can be an absolute path, a file URL or a relative path.
|
||||||
*/
|
*/
|
||||||
outDir?: string;
|
outDir?: string;
|
||||||
|
/**
|
||||||
|
* This sets the target environment for the generated code. Newer
|
||||||
|
* language constructs will be transformed to match the specified
|
||||||
|
* support range. See https://esbuild.github.io/api/#target
|
||||||
|
* @default {"es2022"}
|
||||||
|
*/
|
||||||
|
target?: string | string[];
|
||||||
};
|
};
|
||||||
render?: RenderFunction;
|
render?: RenderFunction;
|
||||||
plugins?: Plugin[];
|
plugins?: Plugin[];
|
||||||
@@ -47,6 +54,7 @@ export interface InternalFreshOptions {
|
|||||||
manifest: Manifest;
|
manifest: Manifest;
|
||||||
build: {
|
build: {
|
||||||
outDir: string;
|
outDir: string;
|
||||||
|
target: string | string[];
|
||||||
};
|
};
|
||||||
render?: RenderFunction;
|
render?: RenderFunction;
|
||||||
plugins: Plugin[];
|
plugins: Plugin[];
|
||||||
|
|||||||
@@ -229,3 +229,34 @@ Deno.test(
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Deno.test("pass target options", async () => {
|
||||||
|
const fixture = path.join(Deno.cwd(), "tests", "fixture_build_target");
|
||||||
|
const out = await new Deno.Command(Deno.execPath(), {
|
||||||
|
args: [
|
||||||
|
"run",
|
||||||
|
"-A",
|
||||||
|
path.join(fixture, "dev.ts"),
|
||||||
|
"build",
|
||||||
|
],
|
||||||
|
env: {
|
||||||
|
GITHUB_SHA: "__BUILD_ID__",
|
||||||
|
DENO_DEPLOYMENT_ID: "__BUILD_ID__",
|
||||||
|
FRESH_TEST_TARGET: "es2015",
|
||||||
|
},
|
||||||
|
stdin: "null",
|
||||||
|
stdout: "piped",
|
||||||
|
stderr: "piped",
|
||||||
|
}).output();
|
||||||
|
|
||||||
|
const { stdout, stderr } = getStdOutput(out);
|
||||||
|
const txt = await Deno.readTextFile(
|
||||||
|
path.join(fixture, "_fresh", "island-counter_default.js"),
|
||||||
|
);
|
||||||
|
|
||||||
|
assertNotMatch(
|
||||||
|
txt,
|
||||||
|
/\?\?/,
|
||||||
|
`Asset contained ?? despite target es2015\n\n${stdout}\n${stderr}`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"lock": false,
|
||||||
|
"imports": {
|
||||||
|
"$fresh/": "../../",
|
||||||
|
"preact": "https://esm.sh/preact@10.15.1",
|
||||||
|
"preact/": "https://esm.sh/preact@10.15.1/",
|
||||||
|
"preact-render-to-string": "https://esm.sh/*preact-render-to-string@6.2.0",
|
||||||
|
"@preact/signals": "https://esm.sh/*@preact/signals@1.1.3",
|
||||||
|
"@preact/signals-core": "https://esm.sh/@preact/signals-core@1.2.3"
|
||||||
|
},
|
||||||
|
"compilerOptions": {
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
"jsxImportSource": "preact"
|
||||||
|
}
|
||||||
|
}
|
||||||
Executable
+9
@@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env -S deno run -A --watch=static/,routes/
|
||||||
|
|
||||||
|
import dev from "$fresh/dev.ts";
|
||||||
|
|
||||||
|
await dev(import.meta.url, "./main.ts", {
|
||||||
|
build: {
|
||||||
|
target: Deno.env.get("FRESH_TEST_TARGET"),
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// DO NOT EDIT. This file is generated by Fresh.
|
||||||
|
// This file SHOULD be checked into source version control.
|
||||||
|
// This file is automatically updated during development when running `dev.ts`.
|
||||||
|
|
||||||
|
import * as $0 from "./routes/index.tsx";
|
||||||
|
import * as $$0 from "./islands/Counter.tsx";
|
||||||
|
|
||||||
|
const manifest = {
|
||||||
|
routes: {
|
||||||
|
"./routes/index.tsx": $0,
|
||||||
|
},
|
||||||
|
islands: {
|
||||||
|
"./islands/Counter.tsx": $$0,
|
||||||
|
},
|
||||||
|
baseUrl: import.meta.url,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default manifest;
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export default function Counter(props: { text?: string }) {
|
||||||
|
const text = props.text ?? "check output";
|
||||||
|
return <h1>{text}</h1>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
/// <reference no-default-lib="true" />
|
||||||
|
/// <reference lib="dom" />
|
||||||
|
/// <reference lib="dom.iterable" />
|
||||||
|
/// <reference lib="dom.asynciterable" />
|
||||||
|
/// <reference lib="deno.ns" />
|
||||||
|
|
||||||
|
import { start } from "$fresh/server.ts";
|
||||||
|
import routes from "./fresh.gen.ts";
|
||||||
|
|
||||||
|
await start(routes);
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import Counter from "../islands/Counter.tsx";
|
||||||
|
|
||||||
|
export default function Home() {
|
||||||
|
return <Counter />;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user