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
Worker bundles #431
Comments
An idea WRT to the extension stuff: Instead of having stuff like |
Wouldnt it be too free-form though? It would also enforce people to use those |
I opened (and linked) an issue on the Cloudflare wrangler2 cli repo to open discussion on how library authors should denote that a bundle is "workers" compatible. |
Maybe? I think the Re the general thing though, I don't really think we need to solve this in Preconstruct super urgently. Given the browser bundles for Emotion are just more optimised, they don't use Node specific things, we could just add an @nicksrandall re your PR, I imagine we'd want to use conditional exports, not a new top-level |
@mitchellhamilton You're totally right that the "worker" top level keyword makes little sense since bundlers don't support that value. I've extended the PR to include support for package exports with custom conditionals (including "browser" and "worker"). |
I think that I like the
Right, we don't need to fix this right away in Preconstruct but as show-cased, by the example here, this gets unwieldy pretty fast - so I would really like to avoid this being a manual addition to Emotion. |
To fix compatibility with workers, for example Cloudflare Workers, preconstruct needs to output bundles for workers target. This would fix emotion-js/emotion#2554 (comment)
There is no special top-level package.json for workers though - the only thing that is close to being treated as a "standard" is
package.json#exports.worker
. Webpack supports such a thing, see here and, in general, different tools can be configured to "consume" custom conditions frompackage.json#exports
- for instance, in Rollup one could define those with an option for@rollup/plugin-node-resolve
, like this:exportConditions: ['worker']
. Some more context can be found hereWe know that
exports
is quite dangerous, so this would have to be added very carefully. I'm not proposing to add any form of esm/cjs compat throughexports
. It would just be great if we could figure out a combination of conditions used there that wouldn't change anything for existing users but which would enable new use cases.I think it would be great if preconstruct could support some special replacement strings, instead of
process.env.NODE_ENV
ortypeof document
(well, since I'm talking about a minor version - a new thing would have to be supported in addition to the old things). Stuff likeimport.meta.preconstruct.target
could be supported.On top of that it feels like, due to the static nature of ESM imports, it might not be enough to rely on "runtime" checks for all use cases. I propose to support additional suffixes on filenames that would act as aliases - for example
index.worker.js
could be picked with a priority, overindex.js
, when bundling for a worker target. This could be achieved withresolveId
hook in RollupThe text was updated successfully, but these errors were encountered: