javascript - webpack-dev-server 沒有做到實時刷新,為什么
問題描述
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’
問題解答
回答1:publicPath 路徑問題,把點去掉/dist,或使用絕對路徑publicPath: ’http://127.0.0.1:8080/examples/build
回答2:沒有刷新還是沒有實時刷新?有沒有啟用nginx反向代理?
相關文章:
1. html - 為什么 Button在布局的最下方,綁定的事件無法被觸發,而在中間就可以觸發Button所綁定的事件?2. javascript - 為什么使用art-template后,模板里面讀取不到數據的長度3. javascript - map 渲染img標簽時,會出現圖片中間會以逗號分隔。是因為什么?4. 為什么瀏覽器 運行不出來 ?是哪里出了問題呢?5. html5 - 剛接觸H5,為什么我覺得很多標簽都沒什么用呢?6. java - 為什么在foreach中remove最后一個元素會報錯?7. python - 為什么match匹配出來的結果是<_sre.SRE_Match object; span=(0, 54), match=’’>8. linux - 為什么我在mysql的my.cnf下找不到bind-address?9. 為什么我提交數據他就刷新了10. css3 - 為什么 QQ 瀏覽器都不支持自己的官方主頁,這不是給自己一記響亮的耳光?

網公網安備