Skip to content

Commit

Permalink
feat: support plugins on configuration for the build
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca committed Sep 27, 2023
1 parent 553e46f commit 1798172
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/cli/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import byteSizeToString from "../utils/byte-size-to-string";
import precompressAssets from "../utils/precompress-assets";
import getEntrypoints from "../utils/get-entrypoints";
import getImportableFilepath from "../utils/get-importable-filepath";
import getConstants from "../constants";

const srcDir = getRootDir("development");
const pagesDir = path.join(srcDir, "pages");
const apiDir = path.join(srcDir, "api");
const { SRC_DIR, CONFIG } = getConstants();
const pagesDir = path.join(SRC_DIR, "pages");
const apiDir = path.join(SRC_DIR, "api");
let outdir = getRootDir("production");
const outAssetsDir = path.join(outdir, "public");
const inAssetsDir = path.join(srcDir, "public");
const inAssetsDir = path.join(SRC_DIR, "public");
const pagesEntrypoints = getEntrypoints(pagesDir);
const apiEntrypoints = getEntrypoints(apiDir);
const middlewarePath = getImportableFilepath("middleware", srcDir);
const layoutPath = getImportableFilepath("layout", srcDir);
const i18nPath = getImportableFilepath("i18n", srcDir);
const middlewarePath = getImportableFilepath("middleware", SRC_DIR);
const layoutPath = getImportableFilepath("layout", SRC_DIR);
const i18nPath = getImportableFilepath("i18n", SRC_DIR);
const entrypoints = [...pagesEntrypoints, ...apiEntrypoints];

if (middlewarePath) entrypoints.push(middlewarePath);
Expand All @@ -32,12 +33,15 @@ if (entrypoints.length === 1) {
outdir = path.join(outdir, subfolder);
}

console.log("🚀 Building your app...\n");

const { success, logs, outputs } = await Bun.build({
entrypoints,
outdir,
root: srcDir,
root: SRC_DIR,
minify: true,
splitting: true,
plugins: [...CONFIG.plugins ?? []],
});

if (!success) {
Expand Down
5 changes: 4 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import importFileIfExists from "./utils/import-file-if-exists";
import { Configuration } from "./types";

const rootDir = getRootDir();
const srcDir = getRootDir("development");
const PAGE_404 = "/_404";
const PAGE_500 = "/_500";
const I18N_CONFIG = await importFileIfExists("i18n", rootDir);
const CONFIG_DIR = path.join(rootDir, "..");
const CONFIG_DIR = path.join(srcDir, "..");
const CONFIG = (await importFileIfExists("brisa.config", CONFIG_DIR)) ?? {};

const defaultConfig = {
trailingSlash: false,
assetPrefix: "",
plugins: [],
};

const constants = {
Expand All @@ -22,6 +24,7 @@ const constants = {
IS_PRODUCTION: process.env.NODE_ENV === "production",
PORT: parseInt(process.argv[2]) || 3000,
ROOT_DIR: rootDir,
SRC_DIR: srcDir,
ASSETS_DIR: path.join(rootDir, "public"),
PAGES_DIR: path.join(rootDir, "pages"),
I18N_CONFIG,
Expand Down
3 changes: 3 additions & 0 deletions src/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BunPlugin } from "bun";

export interface RequestContext extends Request {
context: Map<string, any>;
route?: MatchedRoute;
Expand All @@ -18,6 +20,7 @@ export type Type = string | number | ComponentType | Promise<ComponentType>;
export type Configuration = {
trailingSlash?: boolean;
assetPrefix?: string;
plugins?: BunPlugin[];
basePath?: string;
};

Expand Down

0 comments on commit 1798172

Please sign in to comment.