Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support banner in Bun.build #14330

Closed
synthlace opened this issue Oct 3, 2024 · 1 comment · Fixed by #14370
Closed

Support banner in Bun.build #14330

synthlace opened this issue Oct 3, 2024 · 1 comment · Fixed by #14370
Labels
enhancement New feature or request good first issue Something that would be good for new contributors

Comments

@synthlace
Copy link

What is the problem this feature would solve?

I need functionality that allows me to prepend text to a bundled file.
This text is often called a banner, the minify option should ignore this text as it may contain comments.

In my case, a banner is metablock that is required by userscript.

Current workaround
await Bun.build({
  entrypoints: ["./src/index.tsx"],
  outdir: "./dist",
  minify: true,
});

const metablock = `\
// ==UserScript==
// @key value
// ==/UserScript==
\n`;

await appendMetablock("./dist/index.js", metablock);

async function appendMetablock(path: string, metablock: string) {
  const file = Bun.file(path);
  const fileText = await file.text();

  let newContent = metablock + fileText;
  await Bun.write(path, newContent);
}

TODO comment:

// TODO: banner

Similar issue: #6119

Originated from discord help channel

What is the feature you are proposing to solve the problem?

New argument for Bun.build named banner or preamble (ref terser).
Passed text should be ignored by minify parameter and affect only entrypoints.

What alternatives have you considered?

No response

@synthlace synthlace added the enhancement New feature or request label Oct 3, 2024
@paperdave paperdave added the good first issue Something that would be good for new contributors label Oct 3, 2024
@7heMech
Copy link

7heMech commented Oct 5, 2024

Fixed by #14370

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Something that would be good for new contributors
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants