167 lines
6.5 KiB
JavaScript
167 lines
6.5 KiB
JavaScript
module.exports = function(grunt) {
|
|
"use strict";
|
|
// Configuration
|
|
grunt.initConfig({
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
compass: {
|
|
config: 'config.rb'
|
|
},
|
|
jshint: {
|
|
options: {
|
|
strict: true
|
|
},
|
|
all:['GruntFile.js','src/js/*.js']
|
|
},
|
|
uglify: {
|
|
options: {
|
|
sourceMap: function(script){
|
|
return 'src/source_maps/' + script + '.map';
|
|
},
|
|
sourceMapRoot: '/carson/',
|
|
sourceMappingURL: function(script) {
|
|
//return '../src/source_maps/' + script.replace(/^.+\//, "") + '.map';
|
|
return '../src/source_maps/' + script + '.map';
|
|
}
|
|
},
|
|
src: {
|
|
files: [{
|
|
expand: true,
|
|
cwd: 'src/js/',
|
|
src: ['**/*.js'],
|
|
dest: 'js/',
|
|
//ext: '.min.js', //commenting out for now
|
|
}]
|
|
},
|
|
jqueryTouchSwipe: {
|
|
files: {
|
|
'js/jquery.touchSwipe.js': 'bower_components/jquery-touchswipe/jquery.touchSwipe.js'
|
|
}
|
|
},
|
|
modernizr: {
|
|
files: [{ // Dictionary of files
|
|
expand: true, // Enable dynamic expansion.
|
|
cwd: 'bower_components/modernizr', // Src matches are relative to this path.
|
|
src: ['**/*.js'], // Actual pattern(s) to match.
|
|
dest: 'js/', // Destination path prefix.
|
|
ext: '.js' // Dest filepaths will have this extension.
|
|
}]
|
|
},
|
|
respond: {
|
|
files: [{ // Dictionary of files
|
|
expand: true, // Enable dynamic expansion.
|
|
cwd: 'bower_components/respond', // Src matches are relative to this path.
|
|
src: ['**/*.js'], // Actual pattern(s) to match.
|
|
dest: 'js/', // Destination path prefix.
|
|
ext: '.js' // Dest filepaths will have this extension.
|
|
}]
|
|
}
|
|
},
|
|
copy: {
|
|
all: {
|
|
files: [{
|
|
expand: true,
|
|
cwd: 'src/raster',
|
|
src: ['**/*.jpg', '**/*.png'],
|
|
dest: 'img/',
|
|
}]
|
|
}
|
|
},
|
|
svgmin: { // Task
|
|
options: { // Configuration that will be passed directly to SVGO
|
|
plugins: [{
|
|
removeViewBox: false
|
|
}]
|
|
},
|
|
all: { // Target
|
|
files: [{ // Dictionary of files
|
|
expand: true, // Enable dynamic expansion.
|
|
cwd: 'src/svg', // Src matches are relative to this path.
|
|
src: ['**/*.svg'], // Actual pattern(s) to match.
|
|
dest: 'img/', // Destination path prefix.
|
|
//ext: '.svg' // Dest filepaths will have this extension.
|
|
}]
|
|
}
|
|
},
|
|
svg2png: { // Task
|
|
all: { // Target
|
|
files: [{ // Dictionary of files
|
|
expand: true, // Enable dynamic expansion.
|
|
//cwd: 'src/svg' // Do not use, svg2png applies the cwd to the dest folder as well
|
|
src: ['src/svg/**/*.svg'], // Actual pattern(s) to match.
|
|
dest: 'img/' // Destination path prefix.
|
|
}]
|
|
},
|
|
},
|
|
smushit: {
|
|
path: {
|
|
src: 'img/'
|
|
}
|
|
},
|
|
watch: {
|
|
options: {
|
|
nospawn: true
|
|
},
|
|
js: {
|
|
files: ['src/js/**/*.js'],
|
|
tasks: ['uglify:src']
|
|
},
|
|
copy: {
|
|
files: ['src/raster/**/*.jpg', 'src/raster/**/*.png'],
|
|
tasks: ['copy', 'smushit']
|
|
},
|
|
svg: {
|
|
files: ['src/svg/**/*.svg'],
|
|
tasks: ['svgmin']
|
|
},
|
|
smushit: {
|
|
files: ['img/**/*.png', 'img/**/*.jpg'],
|
|
tasks: ['smushit']
|
|
},
|
|
sass: {
|
|
files: ['src/sass/**/*.scss'],
|
|
tasks: ['compass'],
|
|
options: {
|
|
nospawn: true
|
|
}
|
|
}
|
|
}
|
|
|
|
});
|
|
// Plugins
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
|
grunt.loadNpmTasks('grunt-contrib-compass');
|
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
|
grunt.loadNpmTasks('grunt-svgmin');
|
|
grunt.loadNpmTasks('grunt-svg2png');
|
|
grunt.loadNpmTasks('grunt-smushit');
|
|
|
|
// Tasks
|
|
grunt.registerTask('default',['jshint','uglify']);
|
|
grunt.registerTask('vector',['svgmin']);
|
|
grunt.registerTask('png',['svg2png', 'smushit']);
|
|
grunt.registerTask('raster',['copy', 'smushit']);
|
|
grunt.registerTask('image',['vector', 'svg2png', 'raster']);
|
|
grunt.event.on('watch', function(action, filepath, target) {
|
|
//change the ource and destination in the uglify task at run time so that it affects the changed file only
|
|
var destFilePath;
|
|
if(target == "js") {
|
|
destFilePath = filepath.replace(/src\/(.+)$/, '$1');
|
|
grunt.config('uglify.src.src', filepath);
|
|
grunt.config('uglify.src.dest', destFilePath);
|
|
} else if(target == "copy") {
|
|
destFilePath = filepath.replace(/src\/raster\/(.+)$/, 'img/$1');
|
|
grunt.config('copy.all.src', filepath);
|
|
grunt.config('copy.all.dest', destFilePath);
|
|
grunt.config('smushit.path.src', destFilePath);
|
|
} else if (target == "svg") {
|
|
destFilePath = filepath.replace(/src\/svg\/(.+)$/, 'img/$1');
|
|
grunt.config('svgmin.all.src', filepath);
|
|
grunt.config('svgmin.all.dest', destFilePath);
|
|
} else if (target == "smushit") {
|
|
grunt.config('smushit.path.src', filepath);
|
|
}
|
|
});
|
|
};
|