Skip to content

Env is undefined in grunt tasks #38

@mturnwall

Description

@mturnwall

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions