Skip to content

Instantly share code, notes, and snippets.

@Linch1
Last active July 1, 2021 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linch1/d64c6ef5f0595f32dfc1af1332246696 to your computer and use it in GitHub Desktop.
Save Linch1/d64c6ef5f0595f32dfc1af1332246696 to your computer and use it in GitHub Desktop.

Minify and concat css/js with grunt

Sources

Installation

  • npm install -g grunt-cli
  • npm i --save grunt-contrib-concat
  • npm i --save grunt-contrib-uglify
  • npm i --save grunt-contrib-cssmin

Setup

  • touch Gruntfile.js
module.exports = function( grunt ){
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
		uglify: {
			options: {
				banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n'
			},
			dist: {
				files: {
					'public/js/<%= pkg.name %>.min.js': ['public/js/*']
				}
			}
    	},
        concat: {
            css: {
                src: ['public/css/*'],
                dest: 'public/css/main.css'
            }
        },
        cssmin: {
            minify: {
              expand: true,
              src: ['public/css/main.css', '*.min.css'],
              dest: '',
              ext: '.css'
            }
        }
	});
	grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-cssmin');
	grunt.registerTask('default', ['uglify', 'concat', 'cssmin']);
}

Run

  • grunt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment