安装webpack-dev-server
- npm install web-dev-server --save-dev
- 配置文件webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
var webpack=require("webpack");
module.exports =
{
entry:
{
"index":[__dirname+'/src/jssrc/index.js',,'webpack-dev-server/client?http://127.0.0.1:8080']
},
output: {
publicPath: "http://127.0.0.1:8080/",
path: __dirname+'/src/webapp/js', //输出文件夹
filename:'[name].js' //最终打包生成的文件名(just 文件名,不带路径的哦)
},
/*devServer:{
historyApiFallback:true,
hot:true,
inline:true,
progress:true,
port:9090 //端口你可以自定义
},*/
resolve: {
alias: {
vue: 'vue/dist/vue.js'
}
},
externals: {
},
module:{
loaders:[
{test:/\.js$/,loader:"babel",query:{compact:true}},
{test:/\.vue$/,loader:"babel!vue", exclude: "/node_modules/"}
]
},
plugins:[
new HtmlWebpackPlugin({
// filename: __dirname+'/src/webapp/index.html',//目标文件
filename:"index.html",//使用webpack-dev-server时配置
template: __dirname+'/src/html/index.html',//模板文件
inject:'body',
hash:true,
chunks:["index"]
})
]
}
评论区