Rollup

Rollup 可以将我们自己编写的 Javascript 代码(通过插件可以支持更多语言,如 Tyepscript)与第三方模块打包在一起,形成一个文件,该文件可以是一个库(Library)或者一个应用(App),在打包过程中可以应用各类插件实现特定功能。下图揭示了 Rollup 的运行机制:

Rollup执行流程

Rollup 默认采用 ES 模块标准,我们可以通过 rollup-plugin-commonjs 插件使之支持 CommonJS 标准。

插件

Rollup 官方提供了用于构建的插件:rollup-plugin

插件说明
aliasDefine and resolve aliases for bundle dependencies
auto-installAutomatically install dependencies that are imported by a bundle
babelCompile your files with Babel
beepSystem beeps on errors and warnings
bubleCompile ES2015 with buble
commonjsConvert CommonJS modules to ES6
data-uriImport modules from Data URIs
dsvConvert .csv and .tsv files into JavaScript modules with d3-dsv
htmlCreate HTML files to serve Rollup bundles
imageImport JPG, PNG, GIF, SVG, and WebP files
injectScan modules for global variables and injects import statements where necessary
jsonConvert .json files to ES6 modules
legacyAdd export declarations to legacy non-module scripts
multi-entryUse multiple entry points for a bundle
node-resolveLocate and bundle third-party dependencies in node_modules
replaceReplace strings in files while bundling
runRun your bundles in Node once they're built
stripRemove debugger statements and functions like assert.equal and console.log from your code
sucraseCompile TypeScript, Flow, JSX, etc with Sucrase
typescriptIntegration between Rollup and Typescript
urlImport files as data-URIs or ES Modules
virtualLoad virtual modules from memory
wasmImport WebAssembly code with Rollup
yamlConvert YAML files to ES6 modules

参考资料