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 // 端口號 } }