一、rollup 概念
Rollup 是一个 JavaScript 模块打包器,可以将小块代码编译成大块复杂的代码,例如 library 或应用程序。
二、安装
npm install --global rollup
三、简单实例(对于NodeJS):
方式1
- 创建 main.ts
console.log('rollup')
- 打包
# compile to a CommonJS module ('cjs')
$ rollup main.ts --file main.js --format cjs
- 运行
node main.js
方式2
- 创建 main.ts
console.log('rollup')
- 创建rollup.config.js
// rollup.config.js
export default {
input: 'main.ts',
output: {
file: 'main.js',
format: 'cjs'
}
};
- 打包
rollup -c
备注:
- 如果出错:Unexpected token (Note that you need plugins to import files that are not JavaScript)
- npm install rollup-plugin-typescript2
- rollup.config.js
import typescript from "rollup-plugin-typescript2";
export default {
input: 'xrark.ts',
output: {
file: 'main.js',
format: 'cjs'
},
plugins: [typescript()],
};
回复 (10)
I
多补充些文字,你会发现更好玩
N
别用这些乱七八糟的垃圾来打包node.js
L
浪费了我一分钟
G
引用 i5ting多补充些文字,你会发现更好玩
@i5ting 没明白
G
引用 nomagick别用这些乱七八糟的垃圾来打包node.js
@nomagick 你是使用什么的?
G
引用 luojinxu520浪费了我一分钟
@luojinxu520 刚刚开始学习,见谅了
N
esbuild 也香
I
建议webpack吧,主流
G
引用 niexqesbuild 也香
@niexq 我看确实速度可以。 赞
G
引用 InCodingNowLiu建议webpack吧,主流
@InCodingNowLiu webpack比较慢。 我现在是开发nodejs(typescript)服务器,需要打包成一个可执行文件。
参与回复
登录后即可参与回复。登录