webpack 编译成功 打开index.html出现错误:
编译成功提示:
webpack.config.js
var path = require('path');
module.exports = {
entry: path.resolve(__dirname, '../app/index/index.js'),
output: {
path: path.resolve(__dirname, '../public/static'),
publicPath: 'static/',
filename: '[name].[hash].js',
chunkFilename: '[id].[chunkhash].js'
},
resolve: {
extensions: ['', '.js', '.vue'],
},
module: {
loaders: [
{
test: /\.vue$/,
loader: 'vue' ,
exclude: /node_modules/
},
{
test: /\.js$/,
loader: 'babel?presets=es2015',
exclude: /node_modules/
}
]
}
}
index.js
import Vue from 'Vue'
import Favlist from './components/Favlist'
new Vue({
el: '#app',
components: { Favlist }
})
Favlist.vue
<template>
<div>{{ msg }}</div>
</template>
<script>
export default {
data () {
return {
msg: 'Hello World!!!'
}
}
}
</script>
<style>
html{
background: red;
}
</style>
应该是
es2015
的presets没有生效,建议babel的配置放在项目根目录的.babelrc
中。可以看看这篇文章