feat: use import maps instead of deps files (#209)

This commit updates fresh to use import maps instead of deps files in generated projects.
This commit is contained in:
Luca Casonato
2022-05-23 19:35:15 +02:00
committed by GitHub
parent fd1346ed6b
commit 80598d07fd
71 changed files with 188 additions and 141 deletions
+4 -2
View File
@@ -21,11 +21,13 @@ async function ensureEsbuildInialized() {
}
export class Bundler {
#importMapURL: URL;
#islands: Island[];
#cache: Map<string, Uint8Array> | Promise<void> | undefined = undefined;
constructor(islands: Island[]) {
constructor(islands: Island[], importMapURL: URL) {
this.#islands = islands;
this.#importMapURL = importMapURL;
}
async bundle() {
@@ -52,7 +54,7 @@ export class Bundler {
absWorkingDir,
outfile: "",
platform: "neutral",
plugins: [denoPlugin()],
plugins: [denoPlugin({ importMapURL: this.#importMapURL })],
splitting: true,
target: ["chrome96", "firefox95", "safari14"],
treeShaking: true,
+4 -1
View File
@@ -69,6 +69,7 @@ export class ServerContext {
app: AppModule,
notFound: UnknownPage,
error: ErrorPage,
importMapURL: URL,
) {
this.#pages = pages;
this.#islands = islands;
@@ -78,7 +79,7 @@ export class ServerContext {
this.#app = app;
this.#notFound = notFound;
this.#error = error;
this.#bundler = new Bundler(this.#islands);
this.#bundler = new Bundler(this.#islands, importMapURL);
this.#dev = typeof Deno.env.get("DENO_DEPLOYMENT_ID") !== "string"; // Env var is only set in prod (on Deploy).
}
@@ -88,6 +89,7 @@ export class ServerContext {
static async fromManifest(manifest: Manifest): Promise<ServerContext> {
// Get the manifest' base URL.
const baseUrl = new URL("./", manifest.baseUrl).href;
const importMapURL = new URL("./import_map.json", manifest.baseUrl);
// Extract all routes, and prepare them into the `Page` structure.
const pages: Page[] = [];
@@ -254,6 +256,7 @@ export class ServerContext {
app,
notFound,
error,
importMapURL,
);
}
+1 -1
View File
@@ -30,4 +30,4 @@ const esbuild: typeof esbuildWasm = Deno.run === undefined
? esbuildWasm
: esbuildNative;
export { esbuild, esbuildWasm as esbuildTypes };
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.4.3/mod.ts";
export { denoPlugin } from "https://deno.land/x/esbuild_deno_loader@0.5.0/mod.ts";