Last active
December 19, 2015 02:29
-
-
Save thathurtabit/5883676 to your computer and use it in GitHub Desktop.
Gruntfile.js for a small LESS-based project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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