简体   繁体   English

webpack 服务器 React js 中的道具值未更新

[英]Props values are not updating in webpack server React js

Whenever I try to pass or update the props value from parent to child I need to restart the webpack server everytime.每当我尝试将 props 值从父级传递或更新到子级时,我每次都需要重新启动 webpack 服务器。 I don't know why props value are not getting updating after saving the file.我不知道为什么保存文件后 props 值没有更新。

Here is my package.json file这是我的 package.json 文件

{
  "name": "react-hooks",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "webpack-dev-server .",
    "build": "Webpack .",
    "test": "test"
  },
  "author": "Rasith",
  "license": "MIT",
  "devDependencies": {
    "@babel/cli": "^7.17.10",
    "@babel/core": "^7.17.10",
    "@babel/plugin-transform-runtime": "^7.17.10",
    "@babel/preset-env": "^7.17.10",
    "@babel/preset-react": "^7.16.7",
    "@babel/runtime": "^7.17.9",
    "babel-eslint": "^10.1.0",
    "babel-loader": "^8.2.5",
    "webpack": "^5.72.1",
    "webpack-cli": "^4.9.2",
    "webpack-dev-server": "^4.9.0"
  },
  "dependencies": {
    "axios": "^0.27.2",
    "react": "^18.1.0",
    "react-dom": "^18.1.0"
  }
}

This is my webpack.config.js file这是我的 webpack.config.js 文件

const path = require("path");

module.exports={

    mode: "development", 
    entry: "./index.js", 
    output: {

        path: path.resolve(__dirname, "public"),
        filename: "main.js"
    },

    target: "web",
    devServer: {
        port: "9500",
        static: ["./public"],
        open: true,
        hot: true ,
        liveReload: true
    },
    resolve: {

        extensions: ['.js','.jsx','.json'] 
    },
    module:{

        rules: [
            {
                test: /\.(js|jsx)$/,   
                exclude: /node_modules/, 
                use:  'babel-loader'
            }
        ]
    }
}

babel.rc file babel.rc 文件

{

    "presets": [
        "@babel/preset-env", //compiling ES2015+ syntax
        "@babel/preset-react" //for react
    ],
    "plugins": [
        "@babel/plugin-transform-runtime"
    ]
}

which dependency or modules is missing in the files.文件中缺少哪些依赖项或模块。 please help me on this developers.请帮我解决这个问题。 Thanks谢谢

You probably need the HMR plugin.您可能需要 HMR 插件。

Add this entry to your webpack config:将此条目添加到您的 webpack 配置中:

plugins: [
  new webpack.HotModuleReplacementPlugin({
   multiStep: true
  })
]

https://webpack.js.org/plugins/hot-module-replacement-plugin/ https://webpack.js.org/plugins/hot-module-replacement-plugin/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM