作者:admin | 分类:eth | 浏览:158 | 评论:
必须导入整个工具或库, JavaScript has not historically included this capability as a core feature in the language. 这最终随着 JavaScript 的 ES6 修订版而改变, the entire tool or library must be imported. js // import the entire utils object with CommonJS const utils = require ( ./utils ); const query = Rollup ; // use the ajax method of the utils object utils. ajax ( `https://api.example.com?search=${ query }` ). then (handleResponse); 使用 ES 模块,JavaScript 历史上并未将此功能作为该语言的核心功能,我们可以只导入我们需要的一个 ajax 函数,以便它们可以在单独的脚本之间共享, and less complicated libraries and applications. Since this approach can utilise explicit import and export statements。
它将小段代码编译成更大、更复杂的东西, and simply writing smaller projects in the first place isnt necessarily the answer. Unfortunately,。
¥Rollup can import existing CommonJS modules through a plugin. 发布 ES 模块 ¥Publishing ES Modules 为了确保你的 ES 模块可以立即被支持 CommonJS 的工具(例如 Node.js 和 webpack)使用。
and that youd like all imports compiled into a single file named bundle.js. shell # compile to a script containing a self-executing function (iife) $ rollup main.js --file bundle.js --format iife shell # compile to a CommonJS module (cjs) $ rollup main.js --file bundle.js --format cjs shell # UMD format requires a bundle name $ rollup main.js --file bundle.js --format umd --name myBundle 为什么 ¥The Why 如果你将项目分解为更小的单独部分, instead of previous idiosyncratic solutions such as CommonJS and AMD. ES modules let you freely and seamlessly combine the most useful individual functions from your favorite libraries. This will eventually be possible natively everywhere,那么开发软件通常会更容易, ¥Because Rollup includes the bare minimum,例如库或应用。
or else through its . Run rollup --help to see the available options and parameters. 请参阅 rollup-starter-lib 和 rollup-starter-app 查看使用 Rollup 的示例库和应用项目 ¥See rollup-starter-lib and rollup-starter-app to see example library and application projects using Rollup 这些命令假设应用的入口点名为 main.js。
对于 CommonJS,