源码构建-基于Rollup

# 源码构建-基于Rollup

根据 format 构建格式可分为三个版(再根据有无 compiler ,每个版本中又可以再分出二个版本)

cjs:表示构建出来的文件遵循 CommonJS 规范

  • Runtime Only
  • Runtime + Compiler

es:构建出来的文件遵循 ES Module 规范

  • Runtime Only
  • Runtime + Compiler

umd:构建出来的文件遵循 UMD 规范

  • Runtime Only
  • Runtime + Compiler

# Runtime Only

通常需要借助如 webpack 的 vue-loader 工具把 .vue 文件编译成JavaScript,因为是在编译阶段做的,所以它只包含运行时的 Vue.js 代码,因此代码体积也会更轻量。

# Runtime + Compiler

我们如果没有对代码做预编译,但又使用了 Vue 的 template 属性并传入一个字符串,则需要在客户端编译模板。Vue.js 2.0 中,最终渲染都是通过 render 函数,如果写 template 属性,则需要编译成 render 函数,那么这个编译过程会发生运行时,所以需要带有编译器的版本。

上次更新: 2022/7/4 下午9:00:37