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. 为什么我写的PHP不行2. delete关键字删除元素的时候,它的值是默认为什么类型呢?可以默认是为0嘛?3. java - 为什么hibernate查询表集报错?4. 前端 - css3中,这样的代码为什么会显示成图片?5. html - 为什么BeautifulSoup find_all 返回的list都不是按照网页显示顺序排序的?6. css3 - 手机网页中用css写1px的描边,为什么需要加一句overflow:hidden才能真正显示1px?7. 为什么点击登陆没反应8. java - 为什么说String的拼接会产生很多的无用对象呢?9. html5 - canvas中的mousedrag事件,为什么鼠标拖出canvas,然后再次移入canvas,drag事件还触发10. javascript - 为什么动态创建<script>标签加载外链JS文件时是异步加载?

网公网安备