使用vue-cli3初始化运行项目的时候会出现这样的问题:
[Vue warn]: You are using the runtime-only build of Vue where the template compiler is not available. Either pre-compile the templates into render functions, or use the compiler-included build.
解释:脚手架3引入vue的时候是vue.runtime.esm.js文件,但真正用到的是vue.esm.js,所以需要在webpack中配置
一般在根目录下新建文件vue.config.js,里面添加如下代码,就可以解决这个问题:
const path = require('path')
function resolve (dir) {
return path.join(__dirname, '..', dir)
}
module.exports={
configureWebpack: {
resolve: {
extensions: ['.js', '.vue', '.json'],
alias: {
'vue$': 'vue/dist/vue.esm.js',
'@': resolve('src'),
}
}
},
}