热模块更换"[HMR] 正在等待来自 WDS 的更新信号..."永远,如何启用热模块更换?



热模块更换'[HMR]正在等待WDS的更新信号…'永远,如何启用热模块更换或从Webpack开发服务器发送信号?

我希望启用热模块更换。因此,我在webpack.config.js.中设置了hot: true

我被卡住了

[HMR]正在等待WDS的更新信号。。。

我希望看到

[HMR]正在等待WDS的更新信号
[WDS]热模块更换已启用。

我尝试了webpack serve --hot --inline命令,但一无所获。。。

webpack.config.js

// Paths
const path = require('path');
const srcPath = path.join(__dirname, 'src');
const distPath = path.join(__dirname, 'dist');
const publicPath = path.join(__dirname, 'public');
// Plugins...
// Modules
module.exports = {
mode: 'development',
entry: path.join(srcPath, 'index.tsx'),
output: {
path: distPath,
filename: 'bundle.js',
},
module: {
rules: [
// TypeScript
{
test: /.(j|t)sx?$/,
exclude: /node_modules/,
use: ['babel-loader']
},
},
// resolves...
devServer: {
contentBase: distPath,
historyApiFallback: true,
hot: true,
inline: true,
writeToDisk: true
},
// plugins...

.babelrc

// .babelrc
{
"presets": [
"@babel/preset-env", 
"@babel/preset-react",
"@babel/preset-typescript"
],
"plugins": [
"react-hot-loader/babel"
]
}

App.tsx
我使用"react hot loader"。

import { hot } from 'react-hot-loader/root';
// some codes
export default hot(App);

如果我更改代码"webpack dev-server"显示

i<wdm:编译>
/src/App.tsx 1.62 KiB[builded][code generated]
i"wdm":编译成功。

这是package.json

{
"name": "app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.1.2",
"@testing-library/user-event": "^12.2.2",
"@types/jest": "^26.0.15",
"@types/node": "^12.19.5",
"@types/react": "^16.9.56",
"@types/react-dom": "^16.9.9",
"react": "^17.0.1",
"react-dom": "^17.0.1",
"react-scripts": "4.0.0",
"typescript": "^4.0.5",
"web-vitals": "^0.2.4"
},
"scripts": {
"start": "webpack serve",
"build": "webpack",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.7",
"@babel/preset-react": "^7.12.7",
"@babel/preset-typescript": "^7.12.7",
"@hot-loader/react-dom": "^17.0.0",
"awesome-typescript-loader": "^5.2.1",
"babel-loader": "^8.1.0",
"clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^6.3.2",
"fork-ts-checker-webpack-plugin": "^6.0.3",
"html-webpack-plugin": "^5.0.0-alpha.14",
"image-minimizer-webpack-plugin": "^1.0.0",
"imagemin-gifsicle": "^7.0.0",
"imagemin-mozjpeg": "^9.0.0",
"imagemin-pngquant": "^9.0.1",
"imagemin-svgo": "^8.0.0",
"raw-loader": "^4.0.2",
"react-hot-loader": "^4.13.0",
"sass": "^1.29.0",
"sass-loader": "^10.1.0",
"ts-loader": "^8.0.11",
"url-loader": "^4.1.1",
"webpack": "^5.6.0",
"webpack-cli": "^4.2.0",
"webpack-dev-server": "^3.11.0"
}
}

有一个错误https://github.com/webpack/webpack-dev-server/issues/2758当将browserslistwebpack-dev-serverwebpack一起使用时,您可以将target: 'web'设置为解决该问题,直到webpack-dev-server v4退出。

相关内容

  • 没有找到相关文章

最新更新