React 构建与开发有很大不同

发布于 2025-01-13 07:43:57 字数 2042 浏览 0 评论 0原文

谢谢你想尝试帮助我!

当我构建 React Web 应用程序时,它看起来与开发模式非常不同。我使用 serve -s build 来观察应用程序的构建时间。但在我的在线 Digitalocean 服务器上,它看起来也不会与开发中的一样。所以它可能与 React 或者它的构建方式有关。 这是在开发模式下: 输入图片此处描述

这是构建时的情况: 输入图片这里的描述

所以看起来 CSS 或 Javacript 没有正确编译。 这是我的 package.json

{
  "name": "websitedominique",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@material-ui/core": "^4.12.3",
    "@material-ui/icons": "^4.11.2",
    "@mui/icons-material": "^5.2.1",
    "@mui/material": "^5.4.2",
    "@mui/styled-engine-sc": "^5.4.2",
    "@react-hook/mouse-position": "^4.1.3",
    "@rehooks/window-size": "^1.0.2",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "concurrently": "^7.0.0",
    "cors": "^2.8.5",
    "express": "^4.17.3",
    "framer-motion": "^4.1.17",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router": "^6.0.2",
    "react-router-dom": "^6.0.2",
    "react-scripts": "4.0.3",
    "styled-components": "^5.3.3",
    "swiper": "^6.8.4",
    "use-react-dimensions": "^2.0.1",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "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": {
    "nodemon": "^2.0.15"
  }
}

我希望有人可以帮助我。感谢您的帮助!

Thanks you want to try to help me!

When I build my React web app it looks very different from the development mode. I use serve -s build to watch when the app is build. But also on my online Digitalocean server, it won't look the same as in development. So it probably has something to do with React or how it was build.
This is in development mode:
enter image description here

This is when it is build:
enter image description here

So it looks CSS or Javacript did not compile correctly.
This is my package.json

{
  "name": "websitedominique",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.7.1",
    "@emotion/styled": "^11.6.0",
    "@material-ui/core": "^4.12.3",
    "@material-ui/icons": "^4.11.2",
    "@mui/icons-material": "^5.2.1",
    "@mui/material": "^5.4.2",
    "@mui/styled-engine-sc": "^5.4.2",
    "@react-hook/mouse-position": "^4.1.3",
    "@rehooks/window-size": "^1.0.2",
    "@testing-library/jest-dom": "^5.11.4",
    "@testing-library/react": "^11.1.0",
    "@testing-library/user-event": "^12.1.10",
    "concurrently": "^7.0.0",
    "cors": "^2.8.5",
    "express": "^4.17.3",
    "framer-motion": "^4.1.17",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router": "^6.0.2",
    "react-router-dom": "^6.0.2",
    "react-scripts": "4.0.3",
    "styled-components": "^5.3.3",
    "swiper": "^6.8.4",
    "use-react-dimensions": "^2.0.1",
    "web-vitals": "^1.0.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "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": {
    "nodemon": "^2.0.15"
  }
}

I Hope someone can help me with this. Thanks for all help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷血 2025-01-20 07:43:57

您应该在根目录中添加一个 .env 文件并添加:
REACT_APP_SC_DISABLE_SPEEDY=true

样式组件库使用称为“快速模式”的东西在生产中注入样式。你可以谷歌它以获取更多信息

you should add a .env file in your root and add:
REACT_APP_SC_DISABLE_SPEEDY=true

The Styled Components library uses something called the "Speedy mode" to inject styles on production. you can Google it for more info

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文