sorrycc / ama

Ask me anything!
https://github.com/sorrycc/ama/issues?q=is%3Aissue+is%3Aclosed
31 stars 6 forks source link

Why the variable NODE_ENV is used in roadhog #11

Closed 951565664 closed 6 years ago

951565664 commented 6 years ago

I set NODE_ENV. ...But its value is always equal to ‘production‘

    "build": "cross-env NODE_ENV=production roadhog build",
    "build:dev": "cross-env NODE_ENV=development roadhog build",

I see the roadhog;s code , image

Why the variable NODE_ENV is used in roadhog, the variable NODE_ENV is often used to distinguish the test package and the formal package, if used in the roadhog, it will lead to users can not use NODE_ENV. Maybe you can use a custom variable like ROADHOG_NODE_ENV

sorrycc commented 6 years ago

It's a convention to set NODE_ENV to production in the build process. Libraries like react, redux will be based on this to remove debugging code for the production environment.

e.g.

If (process.env.NODE_ENV === 'production') {
   Console.log('debug code');
}

After build:

If (false) {
   Console.log('debug code');
}

After uglify:

So, if you want to use environment variables to distinguish the environment, you can pick another name, such as ROADHOG_ENV.