Last active
December 17, 2015 23:59
-
-
Save thathurtabit/5693602 to your computer and use it in GitHub Desktop.
My basic Gruntfile.js - used to copy files form development to deploy, set-up sass/compass, uglify js, jshint, compress css and watch all files / folders.
This file contains hidden or 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/fonts/*", "js/*/**", "!css/scss", 'js/*.js', "!node_modules", "!Gruntfile.js", "!package.json", "!deploy", "!doc", "!src" ], | |
dest: 'deploy/' | |
} | |
}, | |
// COMPASS / SASS - https://github.com/gruntjs/grunt-contrib-compass | |
compass: { // Task | |
deploy: { // Target options | |
options: { | |
sassDir: 'css/scss', | |
cssDir: 'css', | |
fontsDir: 'css/fonts', | |
outputStyle: 'compressed', | |
noLineComments: true | |
} | |
} | |
}, | |
// MINIFY - https://github.com/gruntjs/grunt-contrib-uglify | |
uglify: { | |
deploy: { // Target options | |
options: { | |
banner: '/*! <%= pkg.name %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") %>\n' + '* Copyright (c) <%= grunt.template.today("yyyy") %> ' | |
}, | |
my_target: { | |
files: { | |
'js/main.js': ['js/main.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: { | |
jshint: { | |
files: ['js/**/*.js', 'js/*.js'], | |
tasks: ['jshint:deploy'], | |
options: { | |
interrupt: true | |
} | |
}, | |
compass: { | |
files: 'css/scss/*.scss', | |
tasks: ['compass:deploy'], | |
options: { | |
interrupt: true | |
} | |
}, | |
copy: { | |
files: ["*", "css/*", "css/fonts/*", "js/*/**", 'js/*.js', "!css/scss", "!node_modules", "!Gruntfile.js", "!package.json", "!deploy", "!doc", "!src" ], | |
tasks: ['copy:deploy'], | |
options: { | |
interrupt: true, | |
nospawn: true | |
} | |
} | |
} | |
}); | |
// These plugins provide necessary tasks. | |
grunt.loadNpmTasks('grunt-contrib-uglify'); | |
grunt.loadNpmTasks('grunt-contrib-compass'); | |
grunt.loadNpmTasks('grunt-contrib-copy'); | |
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', [ 'compass', 'jshint', 'copy', 'uglify', 'connect', 'watch']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment