Skip to content

Instantly share code, notes, and snippets.

@thathurtabit
Last active December 19, 2015 02:29
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 thathurtabit/5883676 to your computer and use it in GitHub Desktop.
Save thathurtabit/5883676 to your computer and use it in GitHub Desktop.
Gruntfile.js for a small LESS-based project
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
//Read the package.json (optional)
pkg: grunt.file.readJSON('package.json'),
// Metadata.
meta: {
basePath: '',
srcPath: 'js/',
deployPath: 'deploy/'
},
// ==================================
// TASKS CONFIG
// COPY FILES FROM SOURCE TO DEPLOY - https://github.com/gruntjs/grunt-contrib-copy
// don't include '!X'
copy: {
deploy: {
expand: true,
src: ["*", "css/*.css", "img/*", "css/fonts/*", "js/*/**", "!css/less", "!css/main.css", '!js/*.js', "!node_modules", "!Gruntfile.js", "!package.json", "!deploy", "!doc", "!src" ],
dest: 'deploy/'
}
},
// LESS - https://github.com/gruntjs/grunt-contrib-less
less: {
deploy: {
options: {
yuicompress: true
},
files: [
{ src: ["css/less/bootstrap.less"], dest: "css/bootstrap.css"},
{ src: ["css/less/responsive.less"], dest: "css/bootstrap-responsive.css"},
],
}
},
// UGLIFY - https://github.com/gruntjs/grunt-contrib-uglify
uglify: {
deploy: {
files: [
{ src: ["js/script.js"], dest: "deploy/js/script.js"},
{ src: ["js/plugins.js"], dest: "deploy/js/plugins.js"},
],
}
},
// JSHINT - https://github.com/gruntjs/grunt-contrib-jshint
jshint: {
deploy: {
all: ['js/**/*.js', 'js/*.js']
}
},
// CONNECT - Create server - https://github.com/gruntjs/grunt-contrib-connect
connect: {
server: {
options: {
port: 8080,
base: 'deploy'
}
}
},
// WATCH FILES & FOLDERS - https://github.com/gruntjs/grunt-contrib-watch
// Executes the listed targets on file save
// Watches folders for file changes and then runs the specified tasks
watch: {
uglify: {
files: ["js/script.js", "js/plugins.js"],
tasks: ['uglify:deploy'],
options: {
//interrupt: true
}
},
jshint: {
files: ['js/**/*.js', 'js/*.js'],
tasks: ['jshint:deploy'],
options: {
//interrupt: true
}
},
less: {
files: 'css/less/*.less',
tasks: ['less:deploy'],
options: {
//interrupt: true
}
},
copy: {
files: ["*", "css/*.css", "img/*", "css/fonts/*", "js/*/**", "!css/less", "!css/main.css", '!js/*.js', "!node_modules", "!Gruntfile.js", "!package.json", "!deploy", "!doc", "!src" ],
tasks: ['copy:deploy'],
options: {
//interrupt: true,
//nospawn: true // commented out to make sure files are being copied to deploy on change
}
}
}
});
// These plugins provide necessary tasks.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-connect');
// Resigster tasks in order
// Make sure WATCH is last
grunt.registerTask('default', [ 'jshint', 'less', 'copy', 'uglify', 'connect', 'watch']);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment