feat: read standalone targets from data-targets#17482
feat: read standalone targets from data-targets#17482nicolo-ribaudo merged 2 commits intobabel:mainfrom
data-targets#17482Conversation
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/60651 |
|
commit: |
|
I'm afraid this still won't work out of the box. |
|
I wonder if we could do some basic user agent sniffing, defaulting to "current browser"? |
In Babel 8 we bumped the default targets to In the migration docs, we can put that if you want the old Babel 7 standalone behaviour, you can specify
I thought about it before, but the MDN docs (source) explicitly disapproves this approach, as browsers could pretend to be other browsers. |
9ff012c to
ffed727
Compare
|
Docs PR is ready, PTAL: babel/website#3130 |
ffed727 to
3383f4e
Compare
|
@JLHwung could you already prepare the backport PR? |
Thanks for the heads up, I do not recall that I have prepared a backport, will do it now. |
In this PR babel-standalone will read
browserstargets from thedata-targetsattribute. E.g. to transform the script to chrome 84 or above:In Babel 7, although there is no easy way to customize the
targetsoption in the script tag, the output will run on most browsers anyway, aligning with the goal of standalone: It works out of the box.However, in Babel 8, we have changed the default targets to the browserslist's
defaults. In the migration docs we suggest users to specify thetargetsoption directly, which should be feasible forbabel-coreusers or downstream tool users. But for standalone users, they don't have an easy access to most Babel options. Hence this is what this PR is for.