반응형
.env.[localhost|development|production] 파일로 분리되어 각각의 파일안에 정의하고
REACT_APP_SERVER_LOCATION="DEV"
package.json에서 --config webpack.[localhost|development|production].js 를 설정하면
{
"name": "asc_portal",
"version": "0.1.0",
"private": true,
"scripts": {
"start:webapp:local": "curl -X POST localhost:8090/language/info > src/language.json | npx --max_old_space_size=4096 webpack serve --mode development --env PRODUCT=portal TITLE=\"# LOCAL\" --config webpack.localhost.js",
"build:webapp:development": "curl -X POST https://csportaltest.lge.com/api/language/info > src/language.json | npx webpack --mode development --env PRODUCT=portal TITLE=\"# DEV\" --config webpack.development.js",
"build:webapp:production": "curl -X POST https://csportaltest.lge.com/api/language/info > src/language.json | npx webpack --mode production --env PRODUCT=portal TITLE=\"LG CS Portal\" --config webpack.production.js",
"start": "react-scripts start",
"build": "npx webpack --mode production --env PRODUCT=portal TITLE=\"LG CS Portal\" --config webpack.production.js",
"build:dev": "env-cmd -f .env.test react-scripts build",
"build:2nd": "env-cmd -f .env.test.2nd react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
.env.[개발환경]안에 정의한 변수명 process.env.REACT_APP_SERVER_LOCATION 으로 사용가능
[mocaKey] package.json안에서 set REACT_APP_VERSION=dev 지정하면 process.env.REACT_APP_VERSION변수로 사용
"scripts": {
"start": "set HTTPS=true&&react-scripts start",
"start:beta": "set HTTPS=true&&set REACT_APP_VERSION=beta&&react-scripts start",
"start:dev": "set HTTPS=true&&set REACT_APP_VERSION=dev&&react-scripts start",
"hot": "react-app-rewired start",
"build": "react-scripts build",
"build:beta": "set REACT_APP_VERSION=beta&&react-scripts build",
"build:dev": "set REACT_APP_VERSION=dev&&react-scripts build",
"test": "react-scripts test --watchAll=false",
"test:verbose": "react-scripts test --verbose",
"test:report": "react-scripts test --verbose 2> report.txt",
"test:coverage": "react-scripts test --coverage --watchAll=false",
"eject": "react-scripts eject",
"cypress:open": "cypress open",
"cypress": "cypress run --browser=chrome",
"cypress:test": "set START_SERVER_AND_TEST_INSECURE=1&&start-server-and-test start:dev https-get://localhost:3000 cypress"
},
let LEVEL = process.env.REACT_APP_VERSION;
LEVEL = LEVEL || dev;
if (LEVEL !== dev) {
console.log = function() {};
console.warn = function() {};
console.debug = function() {};
}
반응형
'js' 카테고리의 다른 글
변수의 true/false를 이용한 react 조건부 rendering (0 error case) (0) | 2022.08.31 |
---|---|
csv file download 구현 (0) | 2022.08.18 |
js array 중복제거 (0) | 2022.08.08 |
moment (0) | 2022.07.25 |
마우스 클릭 못하도록 막는 법: 마우스 가져가도 커서 활성화 안되도록 (0) | 2022.07.11 |