webpack-dev-server是启动一个本地的服务,html-webpack-plugin是一个插件,用来使用html的模板html
编辑package.json文件:node
"scripts": {webpack
"dev": "webpack-dev-server --config ./webpack.dev.config.js --mode development"
}es6
在项目的根目录下建立.babelrcweb
{npm
"presets": ["es2015", "latest"], "plugins": []
}json
在webpack.dev.config.js种添加内容浏览器
const path = require("path"); const HtmlWebpackPlugin = require("html-webpack-plugin"); module.exports = { entry: './src/index.js',// 入口文件 output: { path: __dirname, filename: './release/bundle.js' }, plugins: [ new HtmlWebpackPlugin({ template: './index.html' }) ], devServer: { contentBase: path.join(__dirname,'./release'), //运行的目录 open: true, // 自动刷新浏览器 port: 9002 // 端口号 } }