更新Grunt模板使用的变量

时间:2015-04-01 20:28:43

标签: gruntjs grunt-contrib-watch

我正在使用Grunt模板,但想知道如何更新使用的变量。请查看以下示例。

(function () {
    "use strict";

    module.exports = function(grunt) {

        grunt.initConfig({

            directory: 'deploy', // I want to be able to update this

            concat: {
                options: {
                    separator: ';\n\n',
                    banner: '/*! Last edited: <%= grunt.template.today("yyyy-mm-dd") %> */\n /* DO NOT EDIT THIS FILE DIRECTLY */\n\n'
                },
                js_site: {
                    src: '<%= directory %>/assets/js/src/*.js',
                    dest: '<%= directory %>/assets/js/site.js',
                },
                js_vendor: {
                    src: '<%= directory %>/assets/js/vendor/*.js',
                    dest: '<%= directory %>/assets/js/vendor.js',
                }
            },

        });


        grunt.loadNpmTasks('grunt-contrib-concat');

        grunt.registerTask('watch', function() {

            var args    = process.argv;
            var dir     = args[args.indexOf('--dir') + 1];

            // Now update the directory variable above

        });
    };

})();

1 个答案:

答案 0 :(得分:0)

这应该有效:

(function () {
    "use strict";

    module.exports = function(grunt) {

        grunt.initConfig({

            directory: 'deploy', // I want to be able to update this

            concat: {
                options: {
                    separator: ';\n\n',
                    banner: '/*! Last edited: <%= grunt.template.today("yyyy-mm-dd") %> */\n /* DO NOT EDIT THIS FILE DIRECTLY */\n\n'
                },
                js_site: {
                    src: '<%= directory %>/assets/js/src/*.js',
                    dest: '<%= directory %>/assets/js/site.js',
                },
                js_vendor: {
                    src: '<%= directory %>/assets/js/vendor/*.js',
                    dest: '<%= directory %>/assets/js/vendor.js',
                }
            },

        });


        grunt.loadNpmTasks('grunt-contrib-concat');

        grunt.registerTask('watch', function() {

            var args    = process.argv;
            var dir     = args[args.indexOf('--dir') + 1];

            // Now update the directory variable above
            grunt.config.set('directory', dir);
        });
    };

})();