How to ignore grunt uglify files

Background

I just started using grunts about 30 minutes ago. So bear with me.

But I have a pretty simple script transition that will look at my js and then compress it all into a single file for me.

the code

"use strict"; module.exports = function (grunt) { // load all grunt tasks require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), uglify: { options: { beautify: true, report: 'gzip' }, build: { src: ['docroot/js/*.js', 'docroot/components/pages/*.js', 'docroot/components/plugins/*.js'], dest: 'docroot/js/main.min.js' } }, watch: { options: { dateFormat: function(time) { grunt.log.writeln('The watch finished in ' + time + 'ms at' + (new Date()).toString()); grunt.log.writeln('Waiting for more changes...'); } }, js: { files: '<%= uglify.build.src %>', tasks: ['uglify'] } } }); grunt.registerTask('default', 'watch'); } 

Question

My main.min.js is included in the compilation every time. The value of my min.js gets 2x, 4x, 8x, 16x, etc. Etc. Is it best to add an exception and ignore main.min.js ?

+47
javascript gruntjs uglifyjs
Aug 26 '13 at 22:19
source share
1 answer

At the end of the src array add

 '!docroot/js/main.min.js' 

This excludes him.! turns it into an exception.

http://gruntjs.com/api/grunt.file#grunt.file.expand

Ways to match patterns that start with! will be excluded from the returned array. Templates are processed in order, so the order of inclusion and exclusion is significant.

This does not apply to grunt uglify, but any task that uses the grunt convention to specify files will work this way.

As a general tip, although I would suggest placing the embedded files somewhere else besides your source files. Like in the root folder dist .

+111
Aug 27 '13 at 6:32
source share



All Articles