Parcel: Add comment header to bundle

Created on 24 Dec 2018  Β·  6Comments  Β·  Source: parcel-bundler/parcel

❔ Question

Hi. How can I provide a comment header in the final bundle output?

πŸ”¦ Context

I would like to point users to where they can see the original GitHub project.

This is also a legal requirement to include proper license headers on external modules. I tried using "@preserve" JSDoc, and while terser does seem to include it sometimes, it's tucked away in a module (which is in random order in the final output), and it doesn't seem to consistently be kept in the output, bizarrely enough.

πŸ’» Code Sample

None.

🌍 Your Environment

| Software | Version(s) |
| ---------------- | ---------- |
| Parcel | 1.10.0
| Node | v10.0.0
| npm/Yarn | npm v6.5.0
| Operating System | Windows 10

Question Stale

All 6 comments

Pretty sure it's not an issue to have license headers above the actual licensed code instead of on top of the bundle. Pretty sure terser doesn't remove license headers by default and neither does parcel.

terser will remove all comments by default unless you pass { "output": { "comments": "some" } }.

Since each module by default is on its own newline from what I can tell, the module's license header can get lost down at the bottom. And the newline after the license header appears to be stripped (probably a terser bug). So it just becomes very difficult to see.

Try to find the license header in this: http://noclip.website/main.cdfad9f2.js

@magcius Thought the original issue was about license headers of libraries, but bundler licenses makes sense. Although not sure how this should be implemented.

@DeMoorJasper Is there interest from the maintainers to add a comment header to the bundle? I would be happy to take this on, as I'm hitting this issue in processing/p5.js#3431. I think it would be relatively straightforward.

I think we could add the option in as 'bundleHeader' (or maybe 'banner' like rollup?), which would be an optional string.

https://github.com/parcel-bundler/parcel/blob/eb759a44fdad1f158ff315f653ade89dafa843ef/packages/core/parcel-bundler/src/Bundler.js#L91

and write in the bundle somewhere near

https://github.com/parcel-bundler/parcel/blob/eb759a44fdad1f158ff315f653ade89dafa843ef/packages/core/parcel-bundler/src/packagers/Packager.js#L17-L26

This would let us write the same string at the top of every package file type, and require no modification of plugins to support.

@outofambit yes feel free to work on this issue. It’ll be necessary at some point

Sent with GitHawk

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.

Was this page helpful?
0 / 5 - 0 ratings