0
votes

Throughout the course of my project development I wish to combine JS and CSS files into global.js and global.css files and then minify them into global.min.js and global.min.css using gruntjs and use these minified files in my project.

But everytime I run the commands it cancats/combines the files and adds the combined codes to the global files(Causing redundancy) instead of replacing those global files with the new combined codes. Is there any option for it or any other plugin to prevent that?

module.exports = function(grunt) {

// 1. All configuration goes here 
grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    concat: {   
        dist: {
            src: [
                'js/**/*.js',
                'js/*.js'
            ],
            dest: 'js/global.js',
        }
    },


    uglify: {
        build: {
            src: 'js/global.js',
            dest: 'js/global.min.js'
        }
    },

    cssmin: {
      combine: {
        files: {
          'css/global.css': ['css/*.css','css/**/*.css']
        }
      },

       minify: {
        src: 'css/global.css',
        dest: 'css/global.min.css'
      }
    },     


});

// 3. Where we tell Grunt we plan to use this plug-in.
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-watch');

// 4. Where we tell Grunt what to do when we type "grunt" into the terminal.
grunt.registerTask('default', ['concat', 'uglify', 'cssmin']);

};
1
Can you generate the combined and minified files in a separate directory to the files that they are made up from?Luke Woodward
@LukeWoodward, oops! that must be it :D! Lemme do that!user2587132
@LukeWoodward, yes that was it, Thanks and a happy new year!!!user2587132
Glad that helped. I'll write it up as an answer.Luke Woodward

1 Answers

1
votes

Generate the combined and minified files in a separate directory to the files that they are made up from.