javascript - webpack-dev-server 沒有做到即時刷新,為什麼
某草草
某草草 2017-05-16 13:39:51
0
2
574

npm start 的時候打開 http://localhost:8080/ 修改js檔案 並沒有做到即時刷新為什麼?
換了連接埠還是一樣, 沒有即時刷新 手動刷新也沒有變化

目錄結構

#webpack.config.js

const path = require('path');
const webpack = require("webpack");

module.exports = {
    entry: './src/index.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'foo.bundle.js',
        publicPath: './dist'
    },
    module: {
        rules: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: /node_modules/
            }
        ]
    },
    devServer: {
        contentBase: "./",
        historyApiFallback: true,
        hot:true,
        inline: true // 实时刷新
    },
    plugins: [
        new webpack.HotModuleReplacementPlugin()
    ]
};

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.24.1",
    "babel-loader": "^7.0.0",
    "babel-preset-es2015": "^6.24.1",
    "css-loader": "^0.28.0",
    "webpack": "^2.4.1",
    "webpack-dev-server": "^2.4.4"
  }
}

已解決

//修改
//publicPath: './dist' =>  publicPath: '/dist'
某草草
某草草

全部回覆(2)
为情所困

publicPath 路徑問題,把點去掉/dist,或使用绝对路径publicPath: 'http://127.0.0.1:8080/examples/build

大家讲道理

沒有刷新還是沒有即時刷新?有沒有啟用nginx反向代理?

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!