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

Don't drop /*@__PURE__*/ comments #653

Closed
Djaler opened this issue Jan 7, 2021 · 5 comments
Closed

Don't drop /*@__PURE__*/ comments #653

Djaler opened this issue Jan 7, 2021 · 5 comments

Comments

@Djaler
Copy link
Contributor

Djaler commented Jan 7, 2021

Related to #221.

These comments should stay in the library build so client bundlers can respect them.

@evanw
Copy link
Owner

evanw commented Jan 7, 2021

This is already the case. These comments are not dropped:

$ echo '/*@__PURE__*/fn()' | ./esbuild 
/* @__PURE__ */ fn();

@Djaler
Copy link
Contributor Author

Djaler commented Jan 8, 2021

Sorry, I forgot to note that they are dropped if minify enabled

@Djaler
Copy link
Contributor Author

Djaler commented Jan 8, 2021

const { transformSync } = require('esbuild');

console.log(transformSync(
    `
    const foo = /*@__PURE__*/ bar();
    
    export default foo;`,
    { minify: true },
).code);

// produces: 
// const o=bar();export default o;

@evanw
Copy link
Owner

evanw commented Jan 8, 2021

It is expected behavior that they are dropped when minification is enabled. Minification is intended to produce production-ready assets to serve to users, and these comments would mean sending users many additional useless bytes. If you are generating code that is intended for another bundler to process, you can disable minification to preserve these comments and then enable minification in the other bundler so that the result is still minified.

@Djaler
Copy link
Contributor Author

Djaler commented Jan 8, 2021

Makes sense, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants