【问题标题】:Making changes to app after deploy to heroku and running npm build部署到 heroku 并运行 npm build 后对应用程序进行更改
【发布时间】:2020-04-05 06:43:59
【问题描述】:

我将我的 REACT 应用程序部署到 Heroku 并且一切正常,但是我如何在本地运行它并进行更改?当我使用 npm start 时,它会在端口 8080(这是教程告诉我要使用的端口)上启动,但不会在 3000 上启动。当我到达 localhost:8080 时,我的网站就在那里,但我所做的任何更改都不会显示刷新后。

我只想在本地进行更改,然后将更改重新部署到 Heroku。

    Here is my server.js 

    const express = require('express');
const favicon = require('express-favicon');
const path = require('path');
const port = process.env.PORT || 8080;
const app = express();
app.use(favicon(__dirname + '/build/favicon.ico'));
// the __dirname is the current directory from where the script is running
app.use(express.static(__dirname));
app.use(express.static(path.join(__dirname, 'build')));
app.get('/ping', function (req, res) {
    return res.send('pong');
});
app.get('/*', function (req, res) {
    res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
app.listen(port);

Here is my package.json

    {
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@material-ui/core": "^4.9.9",
    "@material-ui/icons": "^4.9.1",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.5.0",
    "@testing-library/user-event": "^7.2.1",
    "aphrodite": "^2.4.0",
    "express": "^4.17.1",
    "express-favicon": "^2.0.1",
    "path": "^0.12.7",
    "react": "^16.13.1",
    "react-animate-on-scroll": "^2.1.5",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "node server.js",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

【问题讨论】:

    标签: reactjs heroku deployment


    【解决方案1】:

    您在本地所做的任何更改都无法单独反映在服务器中。

    每次制作新版本时,您必须使用 git 将更改部署到服务器或仅部署 build 文件夹。

    【讨论】:

    • 但是我如何再次在本地运行项目以便我可以看到更改然后重新部署到 Heroku?
    • 我不明白。你一开始是怎么部署的??您必须先检查一下,对吗?
    猜你喜欢
    • 1970-01-01
    • 2021-03-18
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 2015-07-02
    • 1970-01-01
    • 1970-01-01
    • 2017-05-15
    相关资源
    最近更新 更多