hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
901 stars 57 forks source link

/custom not working #55

Closed electerious closed 7 years ago

electerious commented 7 years ago

I've trouble getting the envify/custom version working. The following code bundles without errors, but still contains process.env.NODE_ENV. Nothing has been replaced:

const envify = require('envify/custom')

/* browserify() */.transform(envify({

    NODE_ENV: 'production'

}))/* .bundle() */

The normal module however works fine.

const envify = require('envify')

process.env.NODE_ENV = 'production'

/* browserify() */.transform(envify)/* .bundle() */

Is there a difference between setting process.env.NODE_ENV = 'production' and passing NODE_ENV: 'production' to the custom module?


Node v6.7.0 envify v4.0.0

All tests are passing on my setup.

electerious commented 7 years ago

It's because this is missing in the documentation. It would have saved me some hours: https://github.com/hughsk/envify/pull/44

kryten87 commented 7 years ago

Just to make it perfectly clear what's going on here (and for the reference of anyone else who goes hunting for this in the future):

bundle.transform(envify({ NODE_ENV: 'production' }));

will "envify" your code but will not touch any packages imported from node_modules.

bundle.transform(envify({ NODE_ENV: 'production' }), { global: true });

will "envify" both your code and packages from node_modules.

Thanks to @electerious for finding this and @MohsenEkhtiari for submitting a patch.