Can Rollup & Plugins convert the majority of legacy libraries to es6 modules?

喜欢而已 提交于 2019-12-08 02:27:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!