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
Add --out-file-extension option to babel-cli #9144
Add --out-file-extension option to babel-cli #9144
Conversation
It might be nicer to allow the config itself specify an output extension - then we could run twice, one with each config, to output for each extension (each of which has a different set of target environments) |
@ljharb I think so too so that you could use a single cli command and change the output extension based on some environment variable. I think this is a better starting point though since |
Small nit in the PR description:
Shouldn't the filenames be |
6b4ca53
to
cce3797
Compare
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/11285/ |
Yeah, it should throw. WDYT about naming it |
cce3797
to
e12d5e5
Compare
9c84bae
to
d5dc562
Compare
@nicolo-ribaudo Done d5dc562. Initially forgot to add a trailing newline to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that it is working anyway?
I would love to see this PR merged since it will allow us to remove ugly shell scripts from our ATM we have a choice of either waiting until this feature gets merged or drop |
d5dc562
to
34db0a0
Compare
Is there something blocking a merge? Really looking forward to this shipping; so we can output separate {
"prepare:mjs": "BABEL_ESM=1 babel src -d . --out-file-extension .mjs",
"prepare:cjs": "babel src -d . --out-file-extension .cjs"
} |
34db0a0
to
dfa4a31
Compare
use existing methods from path module
dfa4a31
to
1415c95
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Docs is needed anyway.
Webpack 4 automatically prioritizes
foo.mjs
overfoo.js
when resolvingimport foo from './foo'
. With this change we can publish a flat package with esmodules and commonjs side by side that allows imports such asimport foo from package/bar
that webpack can easily tree shake with help of esmodules.Settled on
out-file-extension
to be consistent with other flags (out-dir
,out-file
etc.)Alternatives for flag name:
--output-file-extension
--with-file-extension
Should I add a warning if both
--keep-file-extension
and--use-file-extension
are used?It throws now