在watch上更改grunt uglify配置选项

时间:2013-09-27 21:23:54

标签: gruntjs uglifyjs

我正在尝试更改'watch'上的默认uglify开发选项,但是它们没有设置。我打算在uglify任务中为'生产'添加更多子任务作为示例,它将使用默认选项,但是对于我的'dev'子任务,我想通过监视任务传递新选项。

module.exports = function(grunt) {

    // Project configuration.

    grunt.initConfig({

        // ...

        uglify: {
            // default options
            options: {
                banner: '<%= banner %>/* Built <%= grunt.template.today("yyyy/mm/dd") %> for <%= powerful.name %> */\n',
                preserveComments: 'some',
                report: 'min',
                mangle: {
                    except: ['jQuery', 'Backbone']
                }
            },
            dev: {
                // options were here...
                files: {
                    // Powerful Theme JS
                    '<%= powerful.jspath %>touch.min.js':
                    [
                        '<%= powerful.jspath %>libs/jquery.hammer.js',
                        '<%= powerful.jspath %>dev/touch.js'
                    ],
                    '<%= powerful.jspath %>768down.min.js':
                    [
                        '<%= powerful.jspath %>dev/768down.js'
                    ]
                }
            },
            production: {
                // production files here, use default options....
            }
        },

        watch: {
            js: {
                files: ['<%= themesPath %>/**/js/{dev,libs,bootstrap}/*.js'],
                tasks: ['uglify:dev'],
                options: {
                    nospawn:    true
                }
            }
        }
    });

    // ...

    grunt.event.on('watch', function(action, filepath) {
        grunt.config.set('uglify.dev.options', {
            banner: '/*! TESTING 123 */',
            preserveComments: 'all',
            report: false,
            compress: false,
            beautify: true
        });
    });

    grunt.registerTask('default', ['watch']);

};

0 个答案:

没有答案