替换Gruntfile.js中的字符串

时间:2016-11-29 20:49:40

标签: javascript gruntjs environment-variables yeoman

IMP:我的Grunt文件如下所示,现在我想从环境变量更新附加到apiEndpoint键的URL。

例如:创建一个shell脚本文件并插入环境变量所需的网址

如果有人帮助我,我会很高兴的。提前致谢

代码:

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'
                    }
                }
            }
        }

    });

};

0 个答案:

没有答案