dilanx / craco

Create React App Configuration Override, an easy and comprehensible configuration layer for Create React App.
https://craco.js.org
Apache License 2.0
7.42k stars 501 forks source link

The npm script build command cannot modify NODE_ENV #477

Closed wangs1203 closed 1 year ago

wangs1203 commented 1 year ago

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

TouqeerH commented 1 year ago

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