-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support different export globalNames for multiple entry files in IIFE format #1764
Comments
You can easily do this by just building each entry point individually. You can also easily do this by just assigning to import * as something from './this-file'
window.something = something However, you have to be careful about loading multiple entry points from the same code base on the same page. Some modules are designed to be only instantiated once, and loading them multiple times can lead to weird and subtle bugs (for example: graphql/graphql-js#1479). |
Thanks for your reply,my current solution is indeed to build them separately, but the current API supports simultaneous compilation of multiple entry files, it should improve some performance, right? for example,I think the shared dependencies should not to be compiled again? Of course it's fast enough for now. I am writing a front-end devServer based on esbuild with Golang APIs, especially compiling multiple Vue SFC files,
So I CANNOT control the esm code generated from the pre-compiled SFCs.in the output IIFE format,the SFC component becomes unaccessible without globalName to export. Thats why I need to set a unique globalName for each entry files. The only thing I can do during the build process is:
Maybe you can consider adding something like globalNameAdvance []string to support this in the future?This can also solve the confusion caused by a single globalName can be set when there are multiple entry files… |
For what it's worth I found myself needing this today and I'm in a similar situation to sean220 where I can't simply add For my use case, simply allowing the same For now I've been lucky in that I load JS from the front end myself, so I've been able to set a global name that I can replace in the Before hacking in this workaround I had many individual builds running for no other reason than to set |
When compiling multiple entry files, only one globalName can be set in build options, which will cause variable naming conflicts. Is it possible to make improves as follows?
1)adding an additional globalName field to the api.EntryPoint struct.
2)change the opt GlobalName’s type from string to []string.
That each compiled file can have a different globalName in IIFE format is very useful for compiling multiple components with their own unique export names in a single building process.
The text was updated successfully, but these errors were encountered: