Work to reduce bundles size (prebundle modules)

This commit is contained in:
Zef Hemel
2022-04-13 14:46:52 +02:00
parent a24eaaf4b4
commit 31254d15e6
36 changed files with 431 additions and 179 deletions
+15 -2
View File
@@ -8,8 +8,14 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { Manifest } from "../types";
import YAML from "yaml";
import { preloadModules } from "../../common/preload_modules";
async function compile(filePath: string, functionName: string, debug: boolean) {
async function compile(
filePath: string,
functionName: string,
debug: boolean,
meta = true
) {
let outFile = "_out.tmp";
let inFile = filePath;
@@ -23,7 +29,7 @@ async function compile(filePath: string, functionName: string, debug: boolean) {
}
// TODO: Figure out how to make source maps work correctly with eval() code
let js = await esbuild.build({
let result = await esbuild.build({
entryPoints: [inFile],
bundle: true,
format: "iife",
@@ -32,8 +38,15 @@ async function compile(filePath: string, functionName: string, debug: boolean) {
sourcemap: false, //sourceMap ? "inline" : false,
minify: !debug,
outfile: outFile,
metafile: true,
external: preloadModules,
});
if (meta) {
let text = await esbuild.analyzeMetafile(result.metafile);
console.log("Bundle info for", functionName, text);
}
let jsCode = (await readFile(outFile)).toString();
await unlink(outFile);
if (inFile !== filePath) {