npm run build不更新react组件

时间:2019-01-03 14:22:11

标签: node.js reactjs node-sass-chokidar

我有一个带有以下package.json的react项目:

    {
  "name": "commonsensev2.0",
  "version": "0.1.0",
  "private": true,
  "homepage": "http://localhost:9080/server/react",
  "dependencies": {
    "all": "0.0.0",
    "axios": "^0.18.0",
    "babel-polyfill": "^6.26.0",
    "chart.js": "^2.7.3",
    "moment": "^2.23.0",
    "node-sass-chokidar": "0.0.3",
    "npm-run-all": "^4.1.5",
    "popper.js": "^1.14.6",
    "react": "^16.7.0",
    "react-bootstrap": "^0.31.5",
    "react-bootstrap-table": "^4.3.1",
    "react-chartjs2": "^1.2.1",
    "react-dom": "^16.7.0",
    "react-localize-redux": "^2.17.5",
    "react-moment": "^0.7.9",
    "react-redux": "^5.1.1",
    "react-router-dom": "^4.3.1",
    "react-scripts": "1.0.14",
    "redux": "^3.7.2"
  },
  "scripts": {
    "build-css": "node-sass-chokidar src/sass/App.scss -o src/css/",
    "watch-css": "npm run build-css && node-sass-chokidar src/sass/App.scss -o src/css/ --watch --recursive",
    "start-js": "react-scripts start",
    "start": "npm-run-all -p watch-css start-js",
    "build": "npm run build-css && react-scripts build",
    "postbuild": "((ROBOCOPY build ../react /MIR) ^& if %ERRORLEVEL% lss 8 set ERRORLEVEL = 0)",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "bootstrap-toggle": "^2.2.2",
    "datatables.net": "^1.10.19",
    "numeral": "^2.0.6"
  }
}

当我执行npm run build时,我看不到html页上的更改,我使用节点8.11.1降级了它,因为我发现某个地方可能是它不起作用的原因,我也使用了“ node- sass-chokidar”:“ 0.0.3” 后端是一个Java服务器

2 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,我在本地环境中删除了旧的构建文件夹,然后再次运行npm run build以生成一个新的构建文件夹。

答案 1 :(得分:0)

这里只是一个疯狂的猜测,但我认为您正在执行错误的命令。因为build通常是当您出于某种目的(例如将其放置在服务器上)构建代码时。

您需要做的是npm run start,因为它有watch,可以监视更改和更新。

一件小事,我将start脚本重命名为devserve。一般来说,我会说更多使用。