- 开源类库优先选择
- 以 ESM 标准为目标的构建工具
-
以命令行方式打包
安装 rollup
npm install -g rollup
创建 index.js 文件
import path from "path";
console.log("hello rollop", path.join("", "hello"));
打包
rollup -i index.js --file dist.js --format umd
新建 a.js 文件
export const funA = () => {
console.log("a");
};
export const funB = () => {
console.log("b");
};
index.js 引入 a.js
import { funA } from "./a";
funA();
console.log("hello rollup");
打包文件
rollup -i index.js --file dist.js --format es
输出代码,代码进行了合并,并且只打包了用到的代码 ```javascript const funA = () => { console.log(“a”); };
funA(); console.log(“hello rollop”); ```