webpack配置
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry:'./src/index.js',
output:{
path:path.resolve(__dirname, 'dist'),
filename:'bundle.js'
},
// plugins: [new HtmlWebpackPlugin()]
}
目录结构
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Webpack App</title>
</head>
<body>
<div id="main">
<h3>{{message}}</h3>
</div>
<script type="text/javascript" src="bundle.js"></script>
</body>
</html>
index.js
import Vue from 'vue';
var MainCtrl = new Vue({
el:'#main',
data:{
message:'Hello World'
}
})
浏览器报错
试试这个
官网的解释是:
运行时构建不包含模板编译器,因此不支持 template 选项,只能用 render 选项,但即使使用运行时构建,在单文件组件中也依然可以写模板,因为单文件组件的模板会在构建时预编译为 render 函数。运行时构建比独立构建要轻量30%,只有 17.14 Kb min+gzip大小。
就我的理解就是,你要编译这个
template
文件,然后运行时构建呢,你没有模板编译器这个玩意儿,因为你现在是独立构建,所以你得加上这么个东西,告诉它,我会用到你这个模板编译器