Webpack 2 實作筆記 (4) — Webpack Dev Server

如何使用 Webpack Dev Server 讓你的專案可以跑在本地的伺服器上。

Webpack 2 with Webpack Dev Server

安裝 webpack-dev-server

$ yarn add -D webpack-dev-server

設定 package.json,把 dev 改成:

"scripts": {
"dev": "webpack-dev-server",
"build": "webpack -p"

執行 yarn run dev,結果出現錯誤:

Error: `output.path` needs to be an absolute path or `/`.

output 的路徑要設成絕對路徑,參考 webpack 官方文件,改成:

output: {
path: path.resolve(__dirname, 'dist'),
filename: 'app.bundle.js'

再執行 yarn run dev,就可以到 localhost:8080 瀏覽頁面。

Like what you read? Give Salt a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.