77 lines
1.9 KiB
TypeScript
77 lines
1.9 KiB
TypeScript
import * as esbuild from "npm:esbuild";
|
|
import * as fg from "npm:fast-glob";
|
|
import { denoPlugins } from "jsr:@luca/esbuild-deno-loader";
|
|
|
|
async function bundleSharedObject() {
|
|
await esbuild.build({
|
|
plugins: [
|
|
...denoPlugins(),
|
|
],
|
|
entryPoints: [
|
|
"../shared/utils/index.ts",
|
|
],
|
|
outfile: "./public/js/shared.bundle.js",
|
|
bundle: true,
|
|
format: "esm",
|
|
minify: true,
|
|
});
|
|
}
|
|
|
|
await bundleSharedObject();
|
|
|
|
async function bundle() {
|
|
const entryPoints = fg.default.sync([
|
|
"./src/client_js/*.ts",
|
|
"!./src/client_js/shared.bundle.ts",
|
|
]);
|
|
|
|
async function bundleClientJS() {
|
|
await esbuild.build({
|
|
plugins: [
|
|
...denoPlugins(),
|
|
],
|
|
entryPoints: entryPoints,
|
|
outbase: "./src/client_js",
|
|
outdir: "./public/js",
|
|
bundle: false,
|
|
format: "esm",
|
|
minify: true,
|
|
});
|
|
}
|
|
|
|
await bundleClientJS();
|
|
|
|
const bundledFiles = fg.default.sync([
|
|
"./public/js/*.js",
|
|
"!./public/js/shared.bundle.js",
|
|
]);
|
|
|
|
for (const file of bundledFiles) {
|
|
const content = await Deno.readTextFile(file);
|
|
|
|
const staticImportRegex =
|
|
/(import\s*[^'"]+from\s*['"])([^'"]+?)(\.ts)(['"])/g;
|
|
|
|
const dynamicImportRegex =
|
|
/(import\(\s*['"])([^'"]+?)(\.ts)(['"]\s*\))/g;
|
|
|
|
let updatedContent = content.replace(
|
|
staticImportRegex,
|
|
(_, p1, p2, p3, p4) => {
|
|
return `${p1}${p2}.js${p4}`;
|
|
},
|
|
);
|
|
|
|
updatedContent = updatedContent.replace(
|
|
dynamicImportRegex,
|
|
(_, p1, p2, p3, p4) => {
|
|
return `${p1}${p2}.js${p4}`;
|
|
},
|
|
);
|
|
|
|
await Deno.writeTextFile(file, updatedContent);
|
|
}
|
|
}
|
|
|
|
export default bundle;
|