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
Ability to output mjs extension when -d is specified #6222
Comments
Hey @tbranyen! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Would #6221 work for you? |
No, my source isn't |
Are you trying to have two copies of every file? In that case, a find and copy would probably be better than running babel twice: babel lib -d dist/node && find ./dist/node -name "*.js" -exec bash -c 'cp "$1" "${1/.js/.mjs}"' -- {} \; I'm cool with having an |
Two copies of every file is the only way to support new Node ESM and legacy CJS. Unfortunate and hopefully temporary. |
@ljharb said we should support multi-build so maybe we figure out a way to incorporate these ideas together somehow. (Like if you wanted to output a es5, mjs/modules, esnext folder(s) |
I think a whole tool built around multiple build targets could be really cool. Not sure it'd make sense for My vote for this would probably be to do #6242 and default Thoughts? |
I think it should be Although some libraries use rollup, so we could add it to rollup/ the rollup plugin too
Ok although we also added that |
Here is how I have it working with the CLI: {
"build": "npm run build:main && npm run build:module",
"build:main": "babel src --out-dir lib/main --config-file ./babelrc.main.json",
"build:module": "babel src --out-dir lib/module --config-file ./babelrc.module.json --keep-file-extension"
} The source files have The only difference between IMO Rollup is the wrong tool for packages; dependencies should be imported not bundled. It would be great if the Babel CLI handled this common use case with less complex config. |
The primary use case for "Properly", currently, means that your The instant node supports It's very important that prior to this point, it be easy for babel-cli to handle this use case by default. |
That's fair. I should clarify that my concern is more that the |
The |
We use TypeScript as well. Multiple build targets sound really nice. I really want to use the same config everywhere and just change the module format and I would like to use |
I too think this use case (foo.js => babel => foo.jsm) is so core as to be a pretty sensible thing to support even if the babel cli does not support more generalized functionality like multiple build targets or arbitrary file renaming. |
Here's what I'm doing right now, utilizing https://www.npmjs.com/package/renamer: "scripts": { An earlier poster did something similar with find, but Windows isn't going to have find. |
from looking at the code I have found using --keep-file-extension solves this issue for my use case at least. |
@AaronNGray that flag was brought up last year, you'll find it in the very comments you're responding to. The use case is taking any input and outputting as |
PR open at #9144 |
Feature request:
Recommendation from Node core is to output mjs alongside js files so that the package.json
main
field can be ambiguous. Since babel only outputs.js
files when used with the-d
directory flag, it becomes complicated to make this work. I'd like to see an option available to specify the extension the same as with parsing/consuming mjs.Current Behavior
This is the most elegant solution I've found so far, which involves building all files into a temporary directory, renaming all the files to mjs, copying them into the
dist/node
destination, and then removing the temp directory.Possible Solution
My suggestion would be to add a new CLI flag option to specify the output extension. This will allow developers to easily support both Node-based ESM/CJS.
babel lib -d dist/node --ext ".mjs"
Context
I'm trying to figure out how to build a library that will be ready to take advantage of the new Node ESM semantics.
Your Environment
The text was updated successfully, but these errors were encountered: