-
Notifications
You must be signed in to change notification settings - Fork 710
Description
What problem does this feature solve?
Hi, currently when bundling code that contains comments, those comments are preserved in the generated modules. In some cases this is fine, but when generating code for npm packages, we typically provide type definitions as well.
Since the rolldown-plugin-dts handles type generation and preserves comments in the .d.ts files, duplicating those comments in the modules is unnecessary. In fact, they only contribute to increased file size without providing additional value.
It would be great to have an option to disable comment preservation in the generated modules.
Just to clarify, I'm not referring to region comments like //#region and //#endregion, but rather to JSDoc comments.
As a reference, esbuild removes comments from output by default.
comments file
// comments.ts
/**
* This is a simple comment example.
*
* @default string
*/
export const foo = 'bar'esbuild
// build.ts
import { build } from 'esbuild'
await build({
entryPoints: ['comments.ts'],
bundle: true,
format: 'esm',
outdir: 'dist',
})output
// comments.ts
var foo = 'bar'
export { foo }rolldown
import { build } from 'rolldown'
await build({
input: 'comments.ts',
output: {
dir: 'dist',
format: 'esm',
},
})output
//#region comments.ts
/**
* This is a simple comment example.
*
* @default string
*/
const foo = 'bar'
//#endregion
export { foo }As mentioned, the rolldown-plugin-dts automatically preserves comments in the generated type definitions, so there's no need to include them in the production version of the module.
What does the proposed API look like?
Feel free to add the API you think would be most suitable for this, here is the simple example:
await build({
input: 'comments.ts',
output: {
comments: 'none' // Removes all comments
},
})'none'- removes all comments from the output'inline'- preserves comments marked with special tags (e.g., /*! ... */)'all'- keeps all comments, including JSDoc and regular inline comments (default value)