问题
Our team's project is entirely es6 modules (ESM) internally, but has dependencies that have not yet made esm versions.
We've created various solutions, but they are definitely not modern, mainstream solutions. By this I mean Rollup workflows which convert legacy formats to esm. Or equivalent.
So here's the question: are there now Rollup converters/plugins which can let us bundle all, or at least most, legacy formats into esm? I.e. convert commonJS, iife, umd, amd, (and other) library formats into esm, or can at least be bundled into an esm bundle?
回答1:
There are plugins that are designed to do this:
- https://github.com/rollup/rollup-plugin-commonjs
- https://github.com/rollup/rollup-plugin-legacy
- https://github.com/piuccio/rollup-plugin-amd
The CommonJS plugin should cover UMD as well. They're not caveat-free — AMD is very hard to convert to ESM in some cases, and you can do some fairly nasty stuff with CommonJS that is hard to recreate (bundlers like webpack get around it by effectively simulating a Node environment), but they handle the common cases.
For the rest, if the maintainers won't accept PRs that add an ESM build alongside the default one (some won't, frustratingly), you might have to fork — depends on what you depend on :)
来源:https://stackoverflow.com/questions/52068933/can-rollup-plugins-convert-the-majority-of-legacy-libraries-to-es6-modules