我正在尝试使用Webpack开发构建一个Vue 项目。一旦我在文件中添加标签,我就会在浏览器中收到一条错误消息。script
App.vue
Unexpected token export
//App.vue
<template>
<p style="background-color:blue,">Hello World!</p>
</template>
<!-- works perfectly fine without this script tag -->
<script>
export default {
name : 'app'
}
</script>
<style>
h1 {
color : white;
background-color : darkgreen
}
</style>
webpack 配置:
//webpack.config.js
const HTMLPlugin = require('html-webpack-plugin')
const webpack = require('webpack')
//
const BabelLoader = {
loader : 'babel',
test : /\.js$/,
exclude : /node_modules/,
query : {
presets : [ 'es2015', 'stage-2'],
plugins: [ 'transform-runtime' ]
}
}
const VueLoaderConfig = {
loader : 'vue',
test : /\.vue$/,
exclude : /node_module/
}
//
const HTMLPluginConfig = new HTMLPlugin({
template : './src/index.html'
})
const CommonsChunkConfig = new webpack.optimize.CommonsChunkPlugin({
name : [ 'vendor', 'bootstrap' ]
})
//
const config = {
// ENTRY
entry : {
app : './src/app.js',
vendor : [ 'vue' ]
},
// OUTPUT
output : {
filename : '[name].[chunkhash].js',
path : __dirname + '/dist'
},
// PLUGINS
plugins : [
HTMLPluginConfig,
CommonsChunkConfig
],
// MODULE
module : {
loaders : [
BabelLoader,
VueLoaderConfig
]
}
}
//
module.exports = config
入口点——app.js
//app.js
import Vue from 'vue'
//
import App from './App.vue'
//
new Vue({
el : '#app',
...App
})
笔记:
- 在我在文件中添加
<script>
标签之前,它工作得很好。App.vue
请告诉我我可能会错过什么。
提前致谢。