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

Import statements of externals are not merged #1218

Closed
nettybun opened this issue Apr 28, 2021 · 2 comments
Closed

Import statements of externals are not merged #1218

nettybun opened this issue Apr 28, 2021 · 2 comments

Comments

@nettybun
Copy link

nettybun commented Apr 28, 2021

Is there a reason why a bundle has a separate import statement for every file that uses the exact same external? If I have 4 files that do import { x } from "myexternal"; I end up with a bundle that has (only imports shown for brevity):

// src/a.ts
import {x as x3} from "myexternal";
// src/b.ts
import {x as x2} from "myexternal";
// src/c.ts
import {x as x1} from "myexternal";
// src/d.ts
import {x} from "myexternal";

Is this about side effects? I tried marking all uses of x as /* @__PURE__ */ but no change. I also tried an external defined in tsconfig.json's path field. I tried --minify too. Here's a minimal repro: https://github.com/heyheyhello/esbuild-merge-externals

Is there a way to just make this into:

import {x} from "myexternal";

I want all references to x in the entire codebase to be a single import statement since I'm passing this to an acorn AST parser after esbuild is done.

Thank you! 🌺

@evanw
Copy link
Owner

evanw commented Apr 28, 2021

The reason is that I'm working on a rewrite of the linker to address this and a lot of other issues but the rewrite hasn't landed yet. Closing as a duplicate of #475 since this has already been filed.

@evanw evanw closed this as completed Apr 28, 2021
@nettybun
Copy link
Author

Interesting, ok thanks. I'll try to use the threeShim that #475 suggests.

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