问题
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.
回答1:
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'
]
}
}
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']
}
}
...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.
回答2:
I believe that you'll need two arrays, one with the list of files to be compressed and mangled and another to be concatenated.
The compressed and mangled array will be used on Uglify.
The concatenated array will be used on Grunt Contrib Concat.
来源:https://stackoverflow.com/questions/22534524/can-i-tell-uglifyjs-to-only-compress-and-mangle-all-files-except-some-which-i-on