我可以告诉UglifyJS只压缩和压缩除了某些我只想连接的所有文件吗? [英] Can I tell UglifyJS to only compress and mangle all files except some which I only want concatenated?

查看:126
本文介绍了我可以告诉UglifyJS只压缩和压缩除了某些我只想连接的所有文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以指定和排列我想要压缩和损坏的文件(默认Uglify行为),还可以指定不应触及的文件列表,只需连接?

Is it possible to specify and array of files that I want compressed and mangled (default Uglify behavior), but also a list of files that should not be touched, just concatenated?

谢谢。

Thanks.

推荐答案

你可以用不同的方式解决这个问题。我发布了一个扩展示例来说明可以做什么:

You can solve this in different ways. I'm posting an extended example to illustrate what one can do:

uglify: {
    doAll: {
        options: {
            banner: '// <%= pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd HH:mm:ss") %>\n\n',
            mangle: {
                except: [ // mangle is true for all else besides the specified exceptions
                    'src/input-d.js',
                    'src/input-e.js',
                    'src/input-f.js'
                ]
            },
            preserveComments: 'some'
        },
        files: 'dest/output.min.js': [ // concatenation, uglification (mangle) with exceptions, block comments preserved, minification and a banner
            'src/input-a.js',
            'src/input-b.js',
            'src/input-c.js',
            'src/input-d.js',
            'src/input-e.js',
            'src/input-f.js'
        ]
    },
    concatenateOnly: {
        options: {
            compress: false,
            mangle: false,
            preserveComments: 'all'
        },
        files: 'dest/output.js': [ // only concatenation
            'src/input-a.js',
            'src/input-b.js',
            'src/input-c.js',
            'src/input-d.js',
            'src/input-e.js',
            'src/input-f.js'
        ]
    }
}

concatenateOnly 任务将完成您想要的任务,只能连接。你可以指定哪些文件将被连接在那里。您可以使用 watch concatenateAll doAll > c $ c>任务:

The concatenateOnly task would do exactly what you wanted, only concatenate. You could specify which files would be concatenated there. You could run both concatenateAll and doAll at the same time by using the watch task:

watch: {
    js: {
        files: ['config/*.js', 'app/js/**/*.js'],
        tasks: ['jshint', 'jasmine', 'uglify:concatenateOnly', 'uglify:doAll']
    }
}

...或者您可以通过组合一些我上面粘贴的设置,比如使用 options.mangle.except 来获得好处。

...or you could do a single task by combining some of the settings I pasted above, like using the options.mangle.except to your benefit.

这篇关于我可以告诉UglifyJS只压缩和压缩除了某些我只想连接的所有文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆