To quote the top of the readme for @rollup/plugin-babel
:
If you’re using Babel to transpile your ES6/7 code and Rollup to generate a standalone bundle, you have a couple of options:
- run the code through Babel first, being careful to exclude the module transformer, or
- run the code through Rollup first, and then pass it to Babel.
By default, using the recommended option babelHelpers: "bundled"
, @rollup/plugin-babel
appears to be running Babel during the build process, as each file is read. I would like to implement the second option, let Rollup bundle the files, then pass the bundle to Babel for transpilation. But I don’t see a way to do it.
It occurs to me that I could write a Rollup plugin that runs Babel in a buildEnd
hook. But:
- How do I prevent Babel from running during the build?
- How do I run Babel from inside that hook function?
The plugin readme makes it sound so simple, but it never describes how to implement it. How can I accomplish this?