dilanx / craco

Create React App Configuration Override, an easy and comprehensible configuration layer for Create React App.

Home Page:https://craco.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The npm script build command cannot modify NODE_ENV

wangs1203 opened this issue · comments

What's happening
The npm script build command cannot modify NODE_ENV

What should happen
"build:dev": "dotenv -e .env.development craco build" or "build:dev": "cross-env NODE_ENV=development craco build"
NODE_ENV should be development

packages/craco/src/scripts/build.ts this file

import type { BaseContext } from '@craco/types';

process.env.NODE_ENV = 'production'; // This line kills the ENV

import { findArgsFromCli } from '../lib/args';

CRACO version
7.0.0

craco sets NODE_ENV as production to generate an optimized build. You should be able to use a custom variable here.
PS: custom variables require REACT_APP as prefix to work i.e. REACT_APP_PROJECT_ENV