Npm 使用 React/TypeScript 进行开发构建吗?

huangapple go评论76阅读模式
英文:

Npm build development build with react/typescript?

问题

我创建了一个TypeScript React应用程序:

npx create-react-app my-app --template typescript

如果我输入"npm start",它会创建一个开发服务器并生成开发用的JavaScript文件。但对我来说不太适用,因为我想从自己的Golang服务器上提供我的项目。我发现"npm run build"适用于这个目的,因为它创建了运行项目所需的静态JavaScript文件。但它总是创建一个生产构建,如何创建一个开发构建(不进行缩小等)?我找不到答案。

以下是我的package.json,如果有帮助的话:

{
  "name": "mui-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.10.6",
    "@emotion/styled": "^11.10.6",
    "@material-ui/core": "^4.12.4",
    "@mui/icons-material": "^5.11.11",
    "@mui/material": "^5.11.11",
    "@mui/styled-engine-sc": "^5.11.11",
    "@mui/x-data-grid": "^6.0.0",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "@types/jest": "^27.0.1",
    "@types/node": "^16.7.13",
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "@types/react-table": "^7.7.14",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "react-table": "^7.8.0",
    "styled-components": "^5.3.8",
    "typescript": "^4.4.2",
    "web-vitals": "^2.1.0"
  },
  "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"
    ]
  }
}
英文:

I created a TypeScript React app:

npx create-react-app my-app --template typescript

If I type "npm start" it creates a development server and creates development javascript files. But it is not good for me, because I want to serve my project from my own golang server. I found out "npm run build" is good for this purpose, because it creates the static javascript files what are necesary for running the project from my own server. But it is always creates a production build, how can I build a development build (no minifying etc)? I just could not find an answer to this.

Here is my package.json if it helps:

{
  "name": "mui-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@emotion/react": "^11.10.6",
    "@emotion/styled": "^11.10.6",
    "@material-ui/core": "^4.12.4",
    "@mui/icons-material": "^5.11.11",
    "@mui/material": "^5.11.11",
    "@mui/styled-engine-sc": "^5.11.11",
    "@mui/x-data-grid": "^6.0.0",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^13.0.0",
    "@testing-library/user-event": "^13.2.1",
    "@types/jest": "^27.0.1",
    "@types/node": "^16.7.13",
    "@types/react": "^18.0.0",
    "@types/react-dom": "^18.0.0",
    "@types/react-table": "^7.7.14",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-scripts": "5.0.1",
    "react-table": "^7.8.0",
    "styled-components": "^5.3.8",
    "typescript": "^4.4.2",
    "web-vitals": "^2.1.0"
  },
  "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"
    ]
  }
}

答案1

得分: 1

你可以使用选项 --no-minify 来获得你想要的结果,因此你可以尝试:

npm run build --no-minify

如果你想获取更多选项,你可以使用以下命令查看文档:

npm run build --help
英文:

You can get what you want with the option --no-minify, so you can try :

npm run build --no-minify

If you want more options, you can take a look at the documentation with this command :

npm run build --help

huangapple
  • 本文由 发表于 2023年3月7日 00:28:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/75653358.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定