Skip to content

Instantly share code, notes, and snippets.

@laterbreh
Created June 11, 2016 06:03
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 laterbreh/3af9a227b955e296810d51ac99ae4dc0 to your computer and use it in GitHub Desktop.
Save laterbreh/3af9a227b955e296810d51ac99ae4dc0 to your computer and use it in GitHub Desktop.
Easy Grunt Tutorial
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
css: {
src: [
'css/*' //What folder to look at for your css files
],
dest: 'combined.css' //Where or what to name your concat css
},
js : {
src : [
'js/**/*.js', //src to look for your js. This is set assuming you have deeper folders than just /js
'!js/Whatever' //Replace this if you want to exclude directories or files
],
dest : 'combined.js' //same as css example
}
},
uglify: {
js: {
files: {
'combined.js': ['combined.js'] //set directory etc and name
}
}
},
watch: {
files: ['css/*', 'js/**/*'],
tasks: ['concat', 'uglify']
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-cssmin');
//grunt.loadNpmTasks("grunt-remove-logging");
grunt.registerTask('default', [ 'concat:css', 'concat:js', 'uglify:js' ]); //This sets up everything to fire.
};
{
"name": "Whatever you want",
"title": "Concat, Uglify, Minify, Watch for css js",
"version": "1.0.0",
"devDependencies": {
"grunt": "0.4.1",
"grunt-contrib-concat": "0.1.3",
"grunt-contrib-cssmin": "0.6.1",
"grunt-contrib-uglify": "0.2.0",
"grunt-contrib-watch": "0.5.3",
"grunt-remove-logging": "^0.2.0",
"grunt-remove-logging-calls": "^0.1.2"
}
}
This is your ez pz way to get started using grunt. The goal of this gist is to set-up BASIC Concatenation of js, uglify, and minify of assets that you may send into production.
1. npm install grunt-cli -g
2. choose the folder you want to run your grunt from
3. Create the package.json
4. npm install
5. edit to suit your needs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment