-
Notifications
You must be signed in to change notification settings - Fork 361
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
Babel targets configuration for browser and node builds #982
Comments
Mayne check my previus question |
Thanks @multivoltage. I understand that
I am trying to do 1, but I hit some sort of babel misconfiguration. I have no idea on how to do 2 so that it works reliably. Sure modern PS: Do I understand correctly from the |
It seems the solution is to give up on custom configurations and let ...
"type": "module",
"source": "src/foo.js", // your source code
"exports": {
"node": {
"require": "./dist/node/foo.cjs",
"default": "./dist/node/foo.modern.js",
},
"default": "./dist/web/foo.modern.js"
},
"main": "./dist/node/foo.cjs", // where to generate the CommonJS bundle
"module": "./dist/web/foo.js", // where to generate the ESM bundle
... The reason my example usage crashes is that
Ideally, I think there should be a tool similar to |
Another solution seems to be to explicitly rely on ...
"presets": [
[
"@babel/preset-env",
{
"targets": [
"defaults",
"maintained node versions"
]
}
]
],
"plugins": [
"@babel/plugin-transform-for-of"
]
... PS: And if you use destructuring, |
For a while I have been using the following
babel
preset for production bundles:This configuration seems to be incompatible with
microbundle
as it generates errors such asunknown Statement of type "ForOfStatement"
when the source containsfor (... of ...)
statements. Using"presets": ["@babel/preset-env"]
without specifying targets works. However, I am concerned about the compatibility achieved by such "default" builds.What is the proper way to use
microbundle
to build for both the browser and for node? What's the correct babel configuration to use? I am fine with having one build for the browser and another for Node, but how should one definepackage.json
exports in that case?I do realize
microbundle
probably does the correct thing by default, but I am a bit skeptical given the existence of the--target
CLI flag, for which little documentation exists.The text was updated successfully, but these errors were encountered: