Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Env is undefined in grunt tasks #38

Open
mturnwall opened this issue Jan 11, 2016 · 2 comments
Open

Env is undefined in grunt tasks #38

mturnwall opened this issue Jan 11, 2016 · 2 comments

Comments

@mturnwall
Copy link

I have this env task:

env: {
    dev: {
        NODE_ENV: 'dev',
        DEST: '<%= config.dev %>'
    },
    dist: {
        NODE_ENV: 'dist',
        DEST: '<%= config.dist %>'
    }
},

Along with a simply task to test that process.env.DEST is getting set correctly.

grunt.registerTask('testEnv', function(){
  console.log(process.env.DEST);
});

When I run it I get the expected output of dev.

Running "env:dev" (env) task

Running "testEnv" task
dev

Done, without errors.

Now if I use process.env.DEST inside another grunt task I get the value as undefined.

Running tasks: env:dev, testEnv, concat:preload

Running "env:dev" (env) task
Verifying property env.dev exists in config...OK
File: [no files]
Options: (none)

Running "testEnv" task
dev

Running "concat:preload" (concat) task
Verifying property concat.preload exists in config...OK
Files: app/scripts/preload/modernizr.js -> undefined/scripts/preload.js
Options: separator="\n", banner="", footer="", stripBanners=false, process=false, sourceMap=false, sourceMapName=undefined, sourceMapStyle="embed"
Reading app/scripts/preload/modernizr.js...OK
Writing undefined/scripts/preload.js...OK
File undefined/scripts/preload.js created.

Done, without errors.

You can see the undefined in this line Files: app/scripts/preload/modernizr.js -> undefined/scripts/preload.js. It's a simple concat task where I want the output to be different dependent on the environment I set.

concat: {
    baseDir: '<%= config.app %>/scripts',
    preload: {
        src: ['<%= concat.baseDir %>/preload/*.js'],
        dest: process.env.DEST + '/scripts/preload.js'
    },
    libs: {
        src: ['<%= concat.baseDir %>/libs/*.js'],
        dest: process.env.DEST + '/scripts/vendors.js'
    }
},

I've been at this for a day now and have no clue what I'm doing wrong. Any help would be greatly appreciated.

@davegreenwp
Copy link

@mturnwall did you ever get to the bottom of this?

@jennasalau
Copy link

Bugger.. this is a bug.. I was hoping it was just me doing something silly :(

My work around was to not use this plugin but instead add a npm script

NODE_ENV=production grunt build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants