可以汇总插件会将大多数旧版库转换为es6模块吗? [英] Can Rollup & Plugins convert the majority of legacy libraries to es6 modules?

查看:97
本文介绍了可以汇总插件会将大多数旧版库转换为es6模块吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们团队的项目在内部完全是es6模块(ESM),但是具有尚未建立esm版本的依赖项.

Our team's project is entirely es6 modules (ESM) internally, but has dependencies that have not yet made esm versions.

我们已经创建了各种解决方案,但它们绝对不是现代的主流解决方案.我的意思是将原始格式转换为esm的汇总工作流.或等价物.

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.

所以这是问题:现在是否有汇总转换器/插件可以让我们将所有或至少大多数旧格式捆绑到esm中? IE.将commonJS,iife,umd,amd和其他库格式转换为esm,或者至少可以捆绑成esm捆绑包?

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?

推荐答案

有专门用于执行此操作的插件:

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

CommonJS插件也应涵盖UMD.它们并非没有警告-在某些情况下,AMD很难转换为ESM,并且您可以使用CommonJS做一些相当讨厌的事情,这些事情很难重新创建(像webpack这样的捆绑包可以通过有效地模拟Node环境来解决).但是他们可以处理常见的情况.

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.

在其他情况下,如果维护者不接受将ESM版本与默认版本一起添加的PR(有些人不会,令人沮丧的是),那么您可能不得不分叉-取决于您所依赖的:)

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 :)

这篇关于可以汇总插件会将大多数旧版库转换为es6模块吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆