rollup 打包
发布于 3 年前 作者 gocpplua 3831 次浏览 来自 分享

一、rollup 概念

Rollup 是一个 JavaScript 模块打包器,可以将小块代码编译成大块复杂的代码,例如 library 或应用程序。

二、安装

npm install --global rollup

三、简单实例(对于NodeJS):

方式1
  1. 创建 main.ts
console.log('rollup')
  1. 打包
# compile to a CommonJS module ('cjs')
$ rollup main.ts --file main.js --format cjs
  1. 运行
node main.js
方式2
  1. 创建 main.ts
console.log('rollup')
  1. 创建rollup.config.js
// rollup.config.js
export default {
    input: 'main.ts',
    output: {
      file: 'main.js',
      format: 'cjs'
    }
  };
  1. 打包
rollup -c

备注:

  • 如果出错:Unexpected token (Note that you need plugins to import files that are not JavaScript)
  1. npm install rollup-plugin-typescript2
  2. rollup.config.js
import typescript from "rollup-plugin-typescript2";
export default {
    input: 'xrark.ts',
    output: {
      file: 'main.js',
      format: 'cjs'
    },
    plugins: [typescript()],
  };
10 回复

多补充些文字,你会发现更好玩

别用这些乱七八糟的垃圾来打包node.js

浪费了我一分钟

@nomagick 你是使用什么的?

@luojinxu520 刚刚开始学习,见谅了

WechatIMG955.png esbuild 也香

建议webpack吧,主流

@niexq 我看确实速度可以。 赞

@InCodingNowLiu webpack比较慢。 我现在是开发nodejs(typescript)服务器,需要打包成一个可执行文件。

回到顶部