0

IMP: My Grunt file looks as follows, Now I would like to update URL attached to apiEndpoint key from environment variable.

For example: create a shell script file and insert the url that is needed from environment variable

I would be glad if someone helps me out. Thanks in advance

Code:

module.exports = function (grunt) {

    // Time how long tasks take. Can help when optimizing build times
    require('time-grunt')(grunt);

    // Automatically load required Grunt tasks
    require('jit-grunt')(grunt, {
        ngconstant: 'grunt-ng-constant'
    });


    // Define the configuration for all the tasks
    grunt.initConfig({

        // Project settings
        yeoman: appConfig,


        ngconstant: {
            // Options for all targets
            options: {
                space: '  ',
                wrap: '"use strict";\n\n {\%= __ngModule %}',
                name: 'appConfig',
            },
            // Environment targets
            development: {
                options: {
                    dest: '<%= yeoman.app %>/scripts/config.js'
                },
                constants: {
                    ENV: {
                        name: 'development',
                        apiEndpoint: 'https://blabla.com/v1/login'
                    }
                }
            },
            production: {
                options: {
                    dest: '<%= yeoman.dist %>/scripts/config.js'
                },
                constants: {
                    ENV: {
                        name: 'production',
                        apiEndpoint: 'https://blabla.com/v1/login'
                    }
                }
            }
        }

    });

};
  • 1
    You don't even need a shell script to take modify your configuration based on environment variables. http://stackoverflow.com/questions/13989978/accessing-the-process-environment-from-a-grunt-template – 0xcaff Nov 29 '16 at 21:32
  • so you mean process.env.DEST is an environment variable that he called within the file? In that case how does the grunt file know process.env.DEST is an environment variable? Do we need any additional plugins for it? – docdHangover Nov 30 '16 at 08:38
  • In addition, does the .env file have content like **DEST='hello.com'**, Sorry for my naive question but I don't clearly understand whatever is in the link provided. Can you provide me a basic example please – docdHangover Nov 30 '16 at 08:46

0 Answers0