Grunt concat在观察任务期间没有工作

时间:2014-01-10 02:16:01

标签: gruntjs

如果我运行'grunt concat',它会根据Grunt文件编译我的JS文件(第82行)。但是,当我正在做'咕噜咕噜'时,它并没有连接起来(第107行)。

从我所看到的情况来看,我的文件还可以,但我对咕噜很新,所以很想看看你们是否能看到问题。

这是我的完整Grunt文件......

    // All scripts to be included in project go here
    var _SCRIPTS = [
      'js/prefixfree.js',
      'js/jquery-1-10-2.js',
      'js/ie-detect.js',
      'js/application.js'
    ];

    var _PORT = 7777;

    module.exports = function(grunt) {

      // load all grunt tasks
      require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

      // Project configuration.
      grunt.initConfig({

        pkg: grunt.file.readJSON('package.json'),

        connect: {
          server: {
            options: {
              port: _PORT,
              base: 'prototype'
            }
          }
        },

        htmlvalidation: {
          options: {

          },
          files: {
            src: ['prototype/*.php']
          },
        },

        jshint: {
          beforeconcat: _SCRIPTS,
          afterconcat: ['js/main.js']
        },

        csslint: {
          check: {
            src: ['css/*.css']
          },
          strict: {
            options: {
              import: 2
            },
            src: ['css/*.css']
          },
          lax: {
            options: {
              import: false
            },
            src: ['css/*.css']
          }
        },

        compass: {
          dev: {
            options: {
              config: 'config.rb',
              force: false
            }
          }
        },

        uglify: {
          options: {
            banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
          },
          dist: {
            files: {
              'js/main.js': ['js/main.js']
            }
          }
        },

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

        cssmin: {
          add_banner: {
            options: {
              banner: '/* <%= pkg.name %> - v<%= pkg.version %> - ' +
              '<%= grunt.template.today("yyyy-mm-dd") %> */',
            },
            files: {
              'css/style.css': ['css/style.css']
            }
          }
        },

        watch: {
          concat: {
            files: ['js/**/*.js', '!js/main.js'],
            tasks: 'concat',
            options: {
              spawn: false,
            },
          },
          sass: {
            files: ['sass/**/*.scss'],
            tasks: ['compass:dev'],
            options: {
              spawn: false,
            },
          },

          /* watch and see if our javascript files change, or new packages are installed */

          /* watch our files for change, reload */
          livereload: {
            files: ['*.html', 'css/*.css', 'img/*', 'js/*.js'],
            options: {
              livereload: true
            }
          },
        }

      });

      // Default task (Watch)
      grunt.registerTask('default', ['watch']);
      // grunt.registerTask('default', [  'preprocess:dev', 'watch']);

      // Watch with localhost (For Static Templates)
      grunt.registerTask('watch_with_server', [ 'connect:server', 'watch']);

      // TESTING

        // Run all tests
        grunt.registerTask('allTests', [ 'jshint:beforeconcat', 'concat', 'jshint:afterconcat', 'cssLint', 'htmlvalidation']);

        // JS Testing
        grunt.registerTask('jsHint', ['jshint:beforeconcat', 'concat', 'jshint:afterconcat']);

        // CSS Testing csslint
        grunt.registerTask('cssLint', ['csslint:check']);
        grunt.registerTask('cssLintLax', ['csslint:lax']);
        grunt.registerTask('cssLintStrict', ['csslint:strict']);

        // HTML Vaidation
        grunt.registerTask('htmlTest', [ 'htmlvalidation']);
        grunt.registerTask('printenv', function () { console.log(process.env); });

      // Concat and uglify js and minify css for release
      grunt.registerTask('release', [ 'concat:dist', 'uglify', 'cssmin']);

    };

非常感谢

2 个答案:

答案 0 :(得分:0)

我设法通过在监视任务中移动'livereload' 'concat'来实现它。不知道为什么这会有所作为,但它正在发挥作用!

如果有人知道为什么会影响它,我很想知道。

答案 1 :(得分:0)

添加此内容并查看:

livereload: {
     files: ['*.html', 'css/*.css', 'img/*', 'js/*.js'],
     options: {
         livereload: true
     }
},
options: {
    livereload: true
},
files: '<%= options.watch.files %>',//might have to change this line
tasks: ['default', 'notify:watch']
相关问题