What is the problem this feature would solve?
Currently, bundling a full-stack app into a single-file executable is cumbersome when you need to include a large number of assets. bun build --compile entrypoint dir/**/* only embeds non-JS/TS assets. The documentation sadly also acknowledges this.
There's no way to programmatically embed an arbitrary file at build time and have it appear in bun.embeddedFiles, even if you explicitly want to embed a .ts file as raw data.
What is the feature you are proposing to solve the problem?
Add an embeddedFiles option to Bun.build that accepts a list of file paths. Each file is embedded as raw data in the standalone executable and appears in Bun.embeddedFiles regardless of file type.
await Bun.build({
entrypoints: ["./src/index.ts"],
compile: {
embeddedFiles: [
"./src/templates/email.html",
"./src/schema.ts",
"./config/defaults.json",
],
},
outfile: "./my-app",
});
At runtime:
for (const file of Bun.embeddedFiles) {
console.log(file.name); // "src/templates/email.html", "src/schema.ts", ...
const text = await file.text();
}
What alternatives have you considered?
Currently, I have been using a workaround to generate a virtual file using the files option which reads the directory and generates import file from 'path' with { type: 'file'}, and build my own array for emulating embeddedFiles but I'll very much love to avoid that.
What is the problem this feature would solve?
Currently, bundling a full-stack app into a single-file executable is cumbersome when you need to include a large number of assets.
bun build --compile entrypoint dir/**/*only embeds non-JS/TS assets. The documentation sadly also acknowledges this.There's no way to programmatically embed an arbitrary file at build time and have it appear in bun.embeddedFiles, even if you explicitly want to embed a .ts file as raw data.
What is the feature you are proposing to solve the problem?
Add an
embeddedFilesoption to Bun.build that accepts a list of file paths. Each file is embedded as raw data in the standalone executable and appears inBun.embeddedFilesregardless of file type.At runtime:
What alternatives have you considered?
Currently, I have been using a workaround to generate a virtual file using the
filesoption which reads the directory and generatesimport file from 'path' with { type: 'file'}, and build my own array for emulatingembeddedFilesbut I'll very much love to avoid that.