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. 引入traits后,為什么index得是空的呢?2. javascript - 為什么會打印兩次啊?3. javascript - 為什么react需要key屬性標識元素,vue卻不需要呢4. python - 為什么寫了換行語句,結果還是沒有換行?5. ruby - 為什么無法啟動Rails呢?6. 為什么全是css 不用js寫呢7. css - rem布局的時候 為什么多行文字的時候現在的文字大小不一樣??8. java - ConcurrentHashMap中的get()方法為什么可以不加鎖?9. 請教:ajax提交數據為什么傳不到控制器呢?10. mysql 為什么主鍵 id 和 pid 都市索引, id > 10 走索引 time > 10 不走索引?
