Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vue2的独立构建与运行时构建的差别 #5

Open
zhaoqize opened this issue Nov 29, 2017 · 0 comments
Open

Vue2的独立构建与运行时构建的差别 #5

zhaoqize opened this issue Nov 29, 2017 · 0 comments

Comments

@zhaoqize
Copy link
Owner

zhaoqize commented Nov 29, 2017

其实这个问题在你使用vue-cli构建项目的时候是不会出现的,因为你在创建项目的构建过程中已经让你勾选了,然后会写入webpack.config.js中。

image

这就在这,会让你选择Vue的构建方式。

image

如果你勾选Runtime + Compiler就会出现如上的配置。

其实这里涉及到一个概念:

  • 独立构建:含义是,拥有完整的模版编译功能运行时调用功能
  • 运行时构建:含义是,只拥有完整的运行时调用功能

image

为什么会有这种区分呢?

  • 第一,因为Vue使用/运行过程分为两个阶段,第一阶段是将模版进行编译(如单个vue文件中的template)为渲染函数(render),第二阶段是将实际函数的调用阶段。
  • 第二,因为自Vue2.x开始,Vue开始支持SSR(服务端渲染),而服务端是没有DOM这些概念的。所以导致了从Vue2.x后会有分包的问题。

下面是官方话术:

  1. 独立构建包括编译和支持 template 选项。 它也依赖于浏览器的接口的存在,所以你不能使用它来为服务器端渲染。
  2. 运行时构建不包括模板编译,不支持 template 选项。运行时构建,可以用 render 选项,但它只在单文件组件中起作用,因为单文件组件的模板是在构建时预编译到 render 函数中,运行时构建只有独立构建大小的 30%,只有 16Kb min+gzip 大小。

所以两者最大的区别也就出来了

  1. 独立构建包括编译和支持 template 选项
  2. 运行时构建不包括模板编译,不支持 template 选项
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant