2016-08-04 74 views
0

我的grunt文件中的任務運行時沒有錯誤,但我要求它創建的文件沒有被編譯。如果我簡單地運行'grunt',它們會被創建,但如果我使用'grunt watch'並保存一個文件,它不會更新。Grunt Watch沒有創建保存文件

特別是我正在處理文件'script/src/latestNews.js',所以保存這個應該與其他人一起連接以創建'script/dist/main.js'。但它不會繼續像創建'dist/build.min.js'一樣。

module.exports = function (grunt) { 

    // Project configuration. 
    grunt.initConfig({ 
     pkg: grunt.file.readJSON('package.json'), 

     uglify: { 

      options: { 
       mangle: false 
      }, 

      target: { 
       files: { 
        'script/dist/main.min.js':'script/dist/main.js' 
       } 
      }, 

      build: { 
       files: { 
        'script/dist/build.min.js':'script/dist/build.min.js' 
       } 
      } 

     }, 

     concat: { 
      options: { 
       stripBanners: true, 
       banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + 
       '<%= grunt.template.today("yyyy-mm-dd") %> */', 
      }, 

      srcJS: { 
       src: ['script/src/menu.js', 
         'script/src/custom_plugins.js', 
         'script/src/banner.js', 
         'script/src/latestNews.js', 
         'script/src/officers.js', 
         'script/src/eventsCalendar.js', 
         'script/src/combinedSocialMedia.js', 
         'script/src/haveYourSay.js', 
         'script/src/photoGallery.js', 
         'script/src/countdown.js' 
        ], 
       dest: 'script/dist/main.js' 
      }, 

      css: { 
       src: ['style/libs/bootstrap.min.css', 
         'style/libs/bootstrap-theme.min.css', 
         'style/src/css/*'], 
       dest: 'style/dist/build.min.css' 
      }, 

      build: { 
       src: ['script/libs/jquery.easing.min.js', 
         'script/dist/main.js', 
         'script/libs/bootstrap.min.js', 
         'script/libs/velocity.min.js', 
         'script/libs/date.js', 
         'script/libs/jquery.timeago.js', 
         'script/libs/owl.carousel.min.js' 
         ], 
       dest: 'script/dist/build.min.js' 
      } 

     }, 

     jshint: { 

      main: 'script/dist/main.js' 

     }, 

     watch: { 

      js: { 
       files: 'script/src/*', 
       tasks: ['concat:srcJS', 'uglify:target', 'jshint:main', 'copy:js'] 
      }, 

      css: { 
       files: 'style/src/css/*', 
       tasks: ['copy:css'] 
      }, 

      less: { 
       files: 'style/src/less/*', 
       tasks: ['less', 'copy:css'] 
      }, 

      html: { 
       files: '*.html', 
       tasks: ['validation', 'bootlint'] 
      } 

     }, 

     clean: { 
      js: [ 
       'script/dist/main.min.js', 
       'dist/build.min.js', 
       'dist/build.min.css' 
      ] 
     }, 

     copy: { 
      css: { 
       files: [ 

        { expand: true, 'src' : 'style/src/css/main.css', 
        'dest' : 'style/dist/', flatten: true, 
        rename: function(dest, src) { 
         return dest + src.replace('main','build.min'); 
        } 
        }, 

        { expand: true, 'src' : 'style/dist/build.min.css', 
        'dest' : 'dist/', flatten: true }, 

       ] 
      }, 

      js: { 
       files: [ 
        { expand: true, 'src' : 'script/dist/build.min.js', 
        'dest' : 'dist/', flatten: true } 
       ] 
      } 
     }, 

     validation: { 
      options: { 
       reset: grunt.option('reset') || false, 
       stoponerror: true, 
       relaxerror: ['Bad value X-UA-Compatible for attribute http-equiv on element meta.'] //ignores these errors 
      }, 
      files: { 
       src: ['homepage.html'] 
      } 
     }, 

     bootlint: { 
      options: { 
       stoponerror: false, 
       relaxerror: ['E001', 'E003', 'E031', 'W001', 'W002', 'W003', 'W005', 'W007', 'W009', 'E013'] 
      }, 
      files: ['homepage.html'], 
     }, 

     less: { 
      build: { 
       options: { 
        paths: ["style/src/less"], 
        cleancss: true, 
        compress: true 
       }, 
       files: { 
        "style/src/css/main.css": "style/src/less/main.less" 
       } 
      } 
     } 

    }); 

    // Load the plugin that provides the "uglify" task. 
    grunt.loadNpmTasks('grunt-contrib-concat'); 
    grunt.loadNpmTasks('grunt-contrib-uglify'); 
    grunt.loadNpmTasks('grunt-contrib-jshint'); 
    grunt.loadNpmTasks('grunt-contrib-watch'); 
    grunt.loadNpmTasks('grunt-contrib-copy'); 
    grunt.loadNpmTasks('grunt-contrib-clean'); 
    grunt.loadNpmTasks('grunt-contrib-less'); 
    grunt.loadNpmTasks('grunt-html-validation'); 
    grunt.loadNpmTasks('grunt-bootlint'); 

    // Default task(s). 
    //grunt.registerTask('default', ['concat:srcJS','concat:css','uglify','jshint:main']); 
    grunt.registerTask('default', [ 
           'validation', 
           'bootlint', 
           'concat:srcJS', 
           'jshint:main', 
           'uglify:target', 
           'clean', 
           'concat:build', 
           'uglify:build', 
           'less', 
           'copy' 
           ]); 
    }; 

回答

1

看起來您的watch:js任務運行的任務陣列看起來簡單地缺少了一些關鍵任務。具體而言,您沒有運行concat:builduglify:build任務。

你的任務的當前數組: ['concat:srcJS', 'uglify:target', 'jshint:main', 'copy:js']

完成/固定任務的數組: ['concat:srcJS', 'uglify:target', 'jshint:main', 'concat:build', 'uglify:build', 'copy:js']

與我提供的應該解決您的問題修復替換當前的陣列。

相關問題