0

I was looking into the possibility of building a webapp that conditionally loads groups of scripts based on the screen size and/or client of the user, because there may be some UX or client specific code that I might load based on this information.

I saw another question that showed how to have files minified separately (see link), but I wasn't sure if there was an option to take all scripts in group A, B, and C and minify them separately to groupA.min.js, groupB.min.js, and groupC.min.js. Is this possible? Thanks, - Daniel

Example:

uglify: {
  dist: {
    files: {
        'dist/shared.min.js': 'src/shared/*', //would recurse shared directory and concatenate/minify all JS in subdirectories
        'dist/desktop.min.js': 'src/platform/desktop/*',
        'dist/mobile.min.js': 'src/platform/mobile/*',
        'dist/ios.min.js': 'src/platform/ios/*',
        'dist/android.min.js': 'src/platform/android/*'
    }
  }
}
Community
  • 1
  • 1
Daniel
  • 1,789
  • 17
  • 15

1 Answers1

1

Something along these lines should work according to the docs, which I've partly butchered:

grunt.initConfig({
  concat: {
    groupA: {
      // concat task "groupA" target options and files go here.
      dist: {
        // the files to concatenate
        src: ['src/groupA/*.js'],
        // the location of the resulting JS file
        dest: 'dist/groupA.concat.js'
      }
    },
    groupB: {
      // concat task "groupB" target options and files go here.
    },
  },
  uglify: {
    groupA: {
      // uglify task "groupA" target options and files go here.
    },
    groupB: {
      // uglify task "groupB" target options and files go here.
    },
  },
});

Then you can run specific task with grunt concat:groupA or grunt concat:groupB.

user115014
  • 922
  • 14
  • 23