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

Unnecessary Helpers? #206

Closed
evanplaice opened this issue Jun 30, 2020 · 2 comments
Closed

Unnecessary Helpers? #206

evanplaice opened this issue Jun 30, 2020 · 2 comments

Comments

@evanplaice
Copy link

I'm using ESBuild to bundle ESM -> ESM bundle and it includes the following

let __defineProperty = Object.defineProperty;
let __markAsModule = (target) => {
  return __defineProperty(target, "__esModule", {value: true});
};
let __export = (target, all) => {
  __markAsModule(target);
  for (let name in all)
    __defineProperty(target, name, {get: all[name], enumerable: true});
};

AFAIK, pure ESM -> ESM transform shouldn't require anything additional to work. Is this unnecessary bloat?

I'm using the following settings

esbuild --format=esm --bundle src/wc-blink.js --outfile=index2.js
@evanw
Copy link
Owner

evanw commented Jun 30, 2020

Thanks for calling this out. I had also noticed this recently and it's been on my list of things to fix, but I might as well fix it now.

This is a result of cross-contamination between dependencies for ES6 namespace exports and ES6 entry point exports. ES6 namespace exports (the ns object from import * as ns from 'path') are always generated for every file but are removed by tree shaking if they are unused. The same code that generates ES6 namespace exports also generates the exports for entry points when using the esm format because the two tasks are very similar. They were accidentally sharing the same dependency list instead of maintaining two separate dependency lists.

I'll get this fixed soon.

@evanw evanw closed this as completed in 56d71a4 Jun 30, 2020
@evanplaice
Copy link
Author

Awesome! I just started using ESBuild so I wasn't sure if this was necessary or extra. I'll keep an eye out for the fix.

BTW, great job on ESBuild 👍. Bundling is shockingly fast. I can't wait to update all of my projects to use it.

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