Grunt手表没有发现变化

时间:2015-08-11 22:13:13

标签: javascript gruntjs watch

我的第一个Gruntfile正在处理uglifying文件,concat和imagemin。当我从CL运行grunt时,它正常运行并且看起来很好但是,当我更改并保存文件时,它并没有被" watch"捕获,它仍在运行。任何帮助将不胜感激,因为我的代码看起来与我能找到的每个在线示例相同,我看不到任何错误。

这是我的服务器目录的结构,它包含我所有的.js文件:

├── build
│   ├── production.js
│   └── production.min.js
├── config
│   ├── authStore.js
│   └── passport.js
├── db
│   ├── db.js
│   └── schema.sql
├── models
│   ├── taskModel.js
│   └── userModel.js
├── requestHandler
│   └── userHandler.js
├── routes.js
├── server.js
└── views
    └── index.ejs

这是我的Grunt文件:

module.exports = function (grunt){
  grunt.initConfig({
  pkg: grunt.file.readJSON('package.json'),

  cssmin: {
    target: {
      files: [{
        expand: true,
        cwd: 'client/css/',
        src: ['*.css'],
        dest: 'client/css/',
        ext: '.min.css'
      }]
    }
  },

  concat: {
    dist: {
      src: [
      'server/**/*.js',
      ],
      dest: 'server/build/production.js',
    },
    dist: {
      src: [
      'client/js/*.js',
      ],
      dest: 'client/build/production.js',
    }
  },

  uglify: {
    build: {
      src: 'server/build/production.js',
      dest: 'server/build/production.min.js'
    },
    build: {
      src: 'client/build/production.js',
      dest: 'client/build/production.min.js'
    }
  },

  imagemin: {
    dynamic: {
      files: [{
        expand: true,
        // cwd: 'client/img/',
        src: ['client/img/*.jpg'],
        dest: 'client/img/build'
      }]
    }
  },

  watch: {
    options: {
      livereload: true,
    },
    scripts: {
      files: [
        'client/js/*.js',
        'server/**/*.js'
      ],
      tasks: [
        'concat',
        'uglify'
      ],
      options: {
        spawn: false,
      },
    }

  },

 }) //Closes initConfig

  //Tell grunt to use these plugins
  grunt.loadNpmTasks('grunt-contrib-imagemin');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-concat');
  grunt.loadNpmTasks('grunt-contrib-cssmin');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-jshint');

  grunt.registerTask('server-dev', function (target) {
  // Running nodejs in a different process and displaying output on the main console
  var nodemon = grunt.util.spawn({
       cmd: 'grunt',
       grunt: true,
       args: 'nodemon'
  });
  nodemon.stdout.pipe(process.stdout);
  nodemon.stderr.pipe(process.stderr);

  grunt.task.run([ 'watch' ]);
});



  //what happens when you type grunt in CL

  grunt.registerTask('default', ['cssmin', 'uglify', 'imagemin', 'concat', 'watch']);//'watch'
  grunt.registerTask('build', ['concat']);
  //grunt.registerTask('default', ['mochaTest']);
};

0 个答案:

没有答案
相关问题