2015-04-01 3 views
0

Я использую шаблоны Grunt, но задаюсь вопросом, как я могу обновить используемую переменную. Пожалуйста, ознакомьтесь с приведенным ниже примером.Обновление переменной, используемой шаблоном 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 

     }); 
    }; 

})(); 

ответ

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); 
     }); 
    }; 

})(); 
+0

Когда я бегу 'хрюкать смотреть --dir PHASE1', он просто говорит: "Бег "смотреть" задача Done, без ошибок. и выходит из командной строки вместо фактического просмотра. Знаешь, что случилось? –

 Смежные вопросы

  • Нет связанных вопросов^_^