简体   繁体   English

Uglify无法与Grunt Watch一起使用

[英]Uglify not working with Grunt Watch

I have a pretty basic setup with sass, watch and uglify but for some reason I can't get watch to detect when a js file is saved. 我使用sass,watch和uglify进行了非常基本的设置,但是由于某种原因,我无法通过watch来检测何时保存js文件。 It works fine for SCSS/CSS (compiles and reloads.) If I run 'grunt uglify' it bundles my JS files, and if watch is running (in another console instance) it will detect it and trigger the reload. 它对于SCSS / CSS正常工作(编译和重新加载。)如果我运行“ grunt uglify”,它将捆绑我的JS文件,并且如果watch在运行(在另一个控制台实例中),它将检测到它并触发重新加载。

I've tried lots of combinations and I have a feeling it's something really dumb I'm doing/not doing but I'm just not seeing it. 我尝试了很多组合,但我感觉这是我在做/不做的事情,但是我只是看不到它而已。

my gruntfile.js: 我的gruntfile.js:

module.exports = function(grunt) {
  grunt.registerTask('default', ['sass', 'uglify']);
  grunt.initConfig({
    sass: {
      dist: {
        options: {
          style: 'expanded'
        },
        files: { 'fivesixtwo.com/src/FiveSixTwo.com/wwwroot/css/main.css': 'fivesixtwo.com/src/FiveSixTwo.com/wwwroot/css/main.scss' }
      }
    },
    uglify: {
      my_target: {
        files: {
          'fivesixtwo.com/src/FiveSixTwo.com/wwwroot/js/site.js': [
            'fivesixtwo.com/src/FiveSixTwo.com/wwwroot/lib/jquery/dist/jquery.js',
            'fivesixtwo.com/src/FiveSixTwo.com/wwwroot/lib/*.js'
          ]
        }
      }
    },
    watch: {
      options: {
        livereload: 35729,
      },
      html: {
        files: ['fivesixtwo.com/src/FiveSixTwo.com/Views/*.cshtml'],
      },
      sass: {
        options: {
          livereload: false
        },
        files: ['fivesixtwo.com/src/FiveSixTwo.com/wwwroot/css/*.scss'],
        tasks: ['sass']
      },
      css: {
        files: ['fivesixtwo.com/src/FiveSixTwo.com/wwwroot/css/main.css'],
        tasks: []
      },
      scripts: {
        files: ['fivesixtwo.com/src/FiveSixTwo.com/wwwroot/js/site.js'],
        tasks: ['uglify']
      }
    }
  });

  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-contrib-sass');
  grunt.loadNpmTasks('grunt-contrib-uglify');

};

Look at your watch config: 查看您的手表配置:

scripts: {
    files: ['fivesixtwo.com/src/FiveSixTwo.com/wwwroot/js/site.js'],
    tasks: ['uglify']
}

You are only watching for a single js files changes called site.js . 您仅在观察一个名为site.js js文件更改。 To watch all your sources use this config: 要观看所有来源,请使用以下配置:

scripts: {
    files: ['fivesixtwo.com/src/FiveSixTwo.com/wwwroot/lib/*.js'],
    tasks: ['uglify']
}

Use the same pattern as in the uglify config. 使用与uglify配置中相同的模式。 I assumed you are not going to modify jquery itself. 我以为您不会修改jquery本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM