简体   繁体   中英

process.env is an empty object

I am using Gulp / Browserify / Node on Windows, and I want to only include debugging information when in development.

I have a dependant task that is being run before anything else

gulp.task('set-dev-node-env', function() {
    process.env.NODE_ENV = 'development'
}

Yet when I try and access this in my code I am finding process.env is an empty object.

console.log("process.env",process.env)

在此处输入图片说明

How can I get this to work?

I found a solution was to use envify

var envify = require('envify/custom')

and add it as a transform on my browserify() call

.transform(envify({
                NODE_ENV: 'development'
            }))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM