【问题标题】:grunt: how to detect if file is saved to uglify all of my js filesgrunt:如何检测文件是否被保存以丑化我所有的 js 文件
【发布时间】:2015-08-13 11:28:29
【问题描述】:

我正在尝试检测是否保存了某些 js 来丑化我的 js 文件或我的 css 文件。

我在 GruntFile.js 中有这段代码:

/// <binding ProjectOpened='uglify' />
module.exports = function (grunt) {
    grunt.initConfig({

        uglify: {
            bundle: {
                files: { 'Scripts/boooo.min.js': 'Scripts/bootstrap.js' }
            }
        },
        watch: {
            js: {
                files: ['Scripts/**/*.js'],
                tasks: ['uglify']
            }
        }
    });

    // Next one would load plugins
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-watch');


    // Here is where we would define our task
    grunt.registerTask('default', ['watch:js']);


};  

我的任务运行器资源管理器是:

我的包json是:

{
  "name": "something",
  "version": "1.0.0",
  "description": "test",
  "main": "index.html",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "grunt": "^0.4.5",
    "grunt-bower-task": "^0.4.0",
    "grunt-contrib-copy": "^0.8.0",
    "grunt-contrib-uglify": "^0.9.1",
    "grunt-contrib-watch": "^0.6.1",
    "install": "^0.1.8",
    "jshint-stylish": "^2.0.1",
    "npm": "^2.13.4"
  }
}

如何检测是否保存?

【问题讨论】:

    标签: gruntjs task-runner-explorer


    【解决方案1】:
    module.exports = function (grunt) {
        grunt.initConfig({
            pkg: grunt.file.readJSON('package.json'),
            watch: {
                scripts: {
                    files: ['scripts/**/*.js'],
                    tasks: ['uglify']
                }
            },
            uglify: {
                my_target: {
                    options: {
                        beautify: false
                    },
                    files: {
                        '/Scripts/app.min.js': ['scripts/**/*.js']
                    }
                }
            }
        });
    
        grunt.loadNpmTasks('grunt-contrib-watch');
        grunt.loadNpmTasks('grunt-contrib-uglify');
    
        grunt.registerTask('default', ['uglify:my_target', 'watch']);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-12
      • 1970-01-01
      相关资源
      最近更新 更多