javascript - [WDS] Disconnected! 一直重復出現。
問題描述
題主最近剛接觸webpack,今天嘗試下配置webpack的HMR,一直在chrome的控制臺重復出現[WDS] Disconnected!的警告,截圖如下:google了很多方法都找不到原因,所以才來請教下大家。附上代碼結構:
package.json
{ 'name': 'vue-timer', 'version': '1.0.0', 'description': 'a timer based on vue', 'main': 'main.js', 'scripts': { 'test': 'echo 'Error: no test specified' && exit 1', 'start': 'webpack-dev-server --hot --inline' }, 'author': 'Albert', 'license': 'ISC', 'dependencies': { 'vue': '^2.3.3' }, 'devDependencies': { 'babel-core': '^6.24.1', 'babel-loader': '^7.0.0', 'babel-preset-env': '^1.4.0', 'css-loader': '^0.28.1', 'eslint': '^3.19.0', 'eslint-config-airbnb-base': '^11.2.0', 'eslint-plugin-import': '^2.2.0', 'html-webpack-plugin': '^2.28.0', 'style-loader': '^0.17.0', 'stylus': '^0.54.5', 'stylus-loader': '^3.0.1', 'webpack': '^2.5.1', 'webpack-dev-server': '^2.4.5' }}
webpack.config.js
const path = require(’path’);const webpack = require(’webpack’);const HtmlWebpackPlugin = require(’html-webpack-plugin’);module.exports = { devtool: ’eval-source-map’, entry: path.resolve(__dirname, ’src/app/main.js’), output: { path: path.resolve(__dirname, ’src/public’), filename: ’bundle.js’, publicPath: ’/’, }, module: { rules: [ {test: /.js$/,exclude: /node_modules/,loader: ’babel-loader’, }, {test: /.css$/,loader: ’style-loader!css-loader’, }, {test: /.styl$/,loader: ’stylus-loader’, }, ], }, plugins: [ new HtmlWebpackPlugin({ template: path.resolve(__dirname, ’src/app/index.html’), hash: true, }), new webpack.HotModuleReplacementPlugin(), new webpack.NamedModulesPlugin(), ], resolve: { alias: { vue$: ’vue/dist/vue.common.js’, }, }, devServer: { historyApiFallback: true, publicPath: ’/’, },};
奇怪的是在IE11里我就沒看到這種警告,chrome里就一直有,版本是58.0.3029.110
問題解答
回答1:出現問題的原因還是沒找到,但是hot reload問題自己解決了。只需要在入口JS里加上如下代碼就可以了:
if (module.hot) { module.hot.accept();}回答2:
Webpack 的 HMR 功能,是通過 WebSocket 實現的推送 JSON Patch,同時需要第三方庫支持。
IE11 似乎并不支持 WebSocket 因此沒有這樣的警告。Chrome 下你使用 Vue 出現這個問題,原因應該在于你沒有引入 Vue 的 HMR 插件,也就是需要再安裝一個 vue-hot-reload-api。
具體解決方案可以參考我寫的一篇博文:http://ewind.us/2017/webpack-...
相關文章:
1. node.js - webpack-dev-server正常運行,webpack打包卻出錯,怎么辦?2. mysql 5個left關鍵 然后再用搜索條件 幾千條數據就會卡,如何解決呢3. javascript - webpack編譯后的文件不生效,未編譯的文件生效4. java - ehcache緩存用的是虛擬機內存么?5. 這是什么情況???6. thinkphp3 count()方法必須加上字段?7. 怎么php怎么通過數組顯示sql查詢結果呢,查詢結果有多條,如圖。我要forsearch里面echo8. 輸入地址報以下截圖錯誤,怎么辦?9. android - 哪位大神知道java后臺的api接口的對象傳到前端后輸入日期報錯,是什么情況?求大神指點10. python中return 語句與 分支語句連用問題
