2

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

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']);

};
4

0 回答 0