如何知道客户端在响应过程中是环境还是阶段
如何知道客户端上的react app,当前的env是prod还是暂存?
在后端/节点js上,我们有process.env.STAGE_NAME
但是现在可以在客户端上使用。
这是package.json
。
我如何在客户端上获得该信息?
"scripts": {
"postinstall": "cd ./localDb && sls dynamodb install && cd ../",
"buildServer": "tsc -b ./server/tsconfig.json",
"buildClient": "next build ./client",
"build": "npm run buildServer && npm run buildClient",
"build:dev": "npm run buildServer && NODE_ENV=development npm run buildClient",
"dev": "node --inspect server/build/index.js",
"start": "NODE_ENV=production node server/build/index.js",
"testClient": "nyc --reporter=html --reporter=text mocha --timeout 15000 --reporter mochawesome --exit",
"testServer": "nyc --reporter=html --reporter=text mocha --timeout 15000 --reporter mochawesome --exit server/build/tests/*.js",
"lintServer": "tslint 'server/**/*.ts' --quiet --project server/tsconfig.json",
"lintClient": "eslint '**/*.{js,jsx}' --quiet",
"lint": "npm run lintClient && npm run lintServer",
"format": "prettier --write '**/*.{js,jsx,css,scss,ts}'",
"test": "npm run testClient && NODE_ENV=testing npm run testServer",
"local:db": "cd ./localDb && sls dynamodb start && dynamodb-admin"
},
回答如下:取决于您如何运行react应用以及您在package.json
中定义了什么
取决于您的package.json
:
用于测试环境的启动应用程序:npm test
用于产品环境的启动应用程序:npm start
如何知道客户端在响应过程中是环境还是阶段
如何知道客户端上的react app,当前的env是prod还是暂存?
在后端/节点js上,我们有process.env.STAGE_NAME
但是现在可以在客户端上使用。
这是package.json
。
我如何在客户端上获得该信息?
"scripts": {
"postinstall": "cd ./localDb && sls dynamodb install && cd ../",
"buildServer": "tsc -b ./server/tsconfig.json",
"buildClient": "next build ./client",
"build": "npm run buildServer && npm run buildClient",
"build:dev": "npm run buildServer && NODE_ENV=development npm run buildClient",
"dev": "node --inspect server/build/index.js",
"start": "NODE_ENV=production node server/build/index.js",
"testClient": "nyc --reporter=html --reporter=text mocha --timeout 15000 --reporter mochawesome --exit",
"testServer": "nyc --reporter=html --reporter=text mocha --timeout 15000 --reporter mochawesome --exit server/build/tests/*.js",
"lintServer": "tslint 'server/**/*.ts' --quiet --project server/tsconfig.json",
"lintClient": "eslint '**/*.{js,jsx}' --quiet",
"lint": "npm run lintClient && npm run lintServer",
"format": "prettier --write '**/*.{js,jsx,css,scss,ts}'",
"test": "npm run testClient && NODE_ENV=testing npm run testServer",
"local:db": "cd ./localDb && sls dynamodb start && dynamodb-admin"
},
回答如下:取决于您如何运行react应用以及您在package.json
中定义了什么
取决于您的package.json
:
用于测试环境的启动应用程序:npm test
用于产品环境的启动应用程序:npm start