feat: add initial plugin support (#512)
This commit adds initial support for fresh "plugins". These are bundles of functionality that can be added to a fresh plugin through a simple addition in the `main.ts` file. Right now plugins are only able to hook into the render steps. This means that they can inject styling and scripts. They can not yet hook into routing. Things that I think should be possible now: - styling integrations for twind, unocss, and probably a few other tools Things that are not possible yet: - google analytics middleware - database connectors - CMS connectors The routing additions to plugins can be added in a follow-up though.
This commit is contained in:
+10
-2
@@ -1,6 +1,6 @@
|
||||
import { BUILD_ID } from "./constants.ts";
|
||||
import { denoPlugin, esbuild, toFileUrl } from "./deps.ts";
|
||||
import { Island } from "./types.ts";
|
||||
import { Island, Plugin } from "./types.ts";
|
||||
|
||||
let esbuildInitialized: boolean | Promise<void> = false;
|
||||
async function ensureEsbuildInitialized() {
|
||||
@@ -23,10 +23,12 @@ async function ensureEsbuildInitialized() {
|
||||
export class Bundler {
|
||||
#importMapURL: URL;
|
||||
#islands: Island[];
|
||||
#plugins: Plugin[];
|
||||
#cache: Map<string, Uint8Array> | Promise<void> | undefined = undefined;
|
||||
|
||||
constructor(islands: Island[], importMapURL: URL) {
|
||||
constructor(islands: Island[], plugins: Plugin[], importMapURL: URL) {
|
||||
this.#islands = islands;
|
||||
this.#plugins = plugins;
|
||||
this.#importMapURL = importMapURL;
|
||||
}
|
||||
|
||||
@@ -39,6 +41,12 @@ export class Bundler {
|
||||
entryPoints[`island-${island.id}`] = island.url;
|
||||
}
|
||||
|
||||
for (const plugin of this.#plugins) {
|
||||
for (const [name, url] of Object.entries(plugin.entrypoints ?? {})) {
|
||||
entryPoints[`plugin-${plugin.name}-${name}`] = url;
|
||||
}
|
||||
}
|
||||
|
||||
const absWorkingDir = Deno.cwd();
|
||||
await ensureEsbuildInitialized();
|
||||
const bundle = await esbuild.build({
|
||||
|
||||
Reference in New Issue
Block a user