Skip to content

透過環境變數知道目前是否為 webpack-dev-server

Published: at 09:03 AM (1 min read)

在過 webpack 時可以檢查 WEBPACK_DEV_SERVER 是否為 true

if (process.env.WEBPACK_DEV_SERVER) {
  // 目前為 webpack-dev-server 做 serve
}

以上程式碼可以判斷是否為 webpack-dev-server 在 serve 網頁 (通常為開發模式)

藉此變數可以套用一些僅開發時才需執行的流程(e.g. HMR)

參考資料:

https://github.com/webpack/webpack-dev-server/pull/1929


Previous Post
[mac] mysql2 gem: Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
Next Post
[XSS] web security wargame (上)