照例先上官方文档: cn.vuejs.org/v2/guide/in…html
- | 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 | - | - | - |
完整版与运行时版的区别在于,运行时版不包含编译器vue
// 须要编译器
new Vue({
template: '<div>{{ hi }}</div>'
})
// 不须要编译器
new Vue({
render (h) {
return h('div', this.hi)
}
})
复制代码
若是在运行时版使用了template属性,会报一下错误vue-cli
[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
bash
module.exports = {
configureWebpack: {
resolve: {
alias: {
'vue$': 'vue/dist/vue'
}
}
}
}
复制代码