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. dockerfile - 為什么docker容器啟動不了?2. python - lxml.etree為什么會自動加上加上</i>?3. macos - MaxOS El Capitan本地Apache2.4停止服了,為什么 localhost 還可以訪問It Works ?4. docker容器呢SSH為什么連不通呢?5. JavaScript在全局對象中聲明變量,會成為一個全局對象的同名屬性而在函數中聲明變量則不會,為什么?6. java代碼如下,輸出結果中為什么s對象?7. node.js - 為什么npm安裝vue-cli會出現下面的錯誤??!!!?8. java - 匿名內部類和繼承類,在實現ClassLoader時為什么會有區別9. python - flask里寫完css為什么沒法實時更新?10. javascript - jquery中的$.post()為什么不能跨域提交數據呢?
