nb的vue - vue各种版本

2,182 阅读1分钟

照例先上官方文档: cn.vuejs.org/v2/guide/in…

- UMD CommonJS ES Module (基于构建工具使用) ES Module (直接用于浏览器)
完整版 vue.js vue.common.js vue.esm.js vue.esm.browser.js
只包含运行时版 vue.runtime.js vue.runtime.common.js vue.runtime.esm.js -
完整版 (生产环境) vue.min.js - - vue.esm.browser.min.js
只包含运行时版 (生产环境) vue.runtime.min.js - - -

完整版与运行时版的区别在于,运行时版不包含编译器

// 需要编译器
new Vue({
  template: '<div>{{ hi }}</div>'
})

// 不需要编译器
new Vue({
  render (h) {
    return h('div', this.hi)
  }
})

如果在运行时版使用了template属性,会报一下错误

[Vue warn] : You are using the runtime-only build of Vue where the template option is not available. Either pre-compile the templates into render functions, or use the compiler-included build.

使用import默认引入的是运行时版,可以通过import Vue form 'vue/dist/vue'解决

在通过vue-cli create生成的项目中可以新建vue.config.js

module.exports = {
    configureWebpack: {
        resolve: {
            alias: {
                'vue$': 'vue/dist/vue'
            }
        }
    }
}