181 lines
7.4 KiB
JavaScript
181 lines
7.4 KiB
JavaScript
module.exports = function (grunt) {
|
|
'use strict';
|
|
// Configuration
|
|
grunt.initConfig({
|
|
pkg: grunt.file.readJSON('package.json'),
|
|
compass: {
|
|
config: 'config.rb'
|
|
},
|
|
jshint: {
|
|
options: grunt.file.readJSON('.jshintrc'),
|
|
files: ['src/js/**/*.js']
|
|
},
|
|
uglify: {
|
|
options: {
|
|
sourceMap: function (script) {
|
|
return 'src/source_maps/' + script + '.map';
|
|
},
|
|
sourceMapRoot: '/whitemill/',
|
|
// in a live environment when website is in www.[name].com, use the below sourceMapRoot if sourceMaps are still needed
|
|
//sourceMapRoot: '/',
|
|
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', '!rjs/**/*.js'],
|
|
dest: 'js/',
|
|
//ext: '.min.js', //commenting out for now
|
|
}]
|
|
},
|
|
modernizr: {
|
|
files: [{ // Dictionary of files
|
|
expand: true, // Enable dynamic expansion.
|
|
cwd: 'bower_components/modernizr', // Src matches are relative to this path.
|
|
src: ['**/*.js', '!**/grunt*', '!test/**/*.js'], // Actual pattern(s) to match.
|
|
dest: 'js/libs/' // Destination path prefix.
|
|
//ext: '.js' // Dest filepaths will have this extension.
|
|
}],
|
|
options: {
|
|
sourceMappingURL: function (script) {
|
|
//return '../src/source_maps/' + script.replace(/^.+\//, "") + '.map';
|
|
return '../../src/source_maps/' + script + '.map';
|
|
}
|
|
}
|
|
},
|
|
respond: {
|
|
files: [{ // Dictionary of files
|
|
expand: true, // Enable dynamic expansion.
|
|
cwd: 'bower_components/respond', // Src matches are relative to this path.
|
|
src: ['respond.src.js', '!test/**/*.js', '!cross-domain/**/*.js'], // Actual pattern(s) to match.
|
|
dest: 'js/libs/' // Destination path prefix.
|
|
//ext: '.js' // Dest filepaths will have this extension.
|
|
}],
|
|
options: {
|
|
sourceMappingURL: function (script) {
|
|
//return '../src/source_maps/' + script.replace(/^.+\//, "") + '.map';
|
|
return '../../src/source_maps/' + script + '.map';
|
|
}
|
|
}
|
|
},
|
|
requirejs: {
|
|
files: [{ // Dictionary of files
|
|
expand: true, // Enable dynamic expansion.
|
|
cwd: 'bower_components/requirejs', // Src matches are relative to this path.
|
|
src: ['require.js'], // Actual pattern(s) to match.
|
|
dest: 'js/libs/' // Destination path prefix.
|
|
//ext: '.js' // Dest filepaths will have this extension.
|
|
}],
|
|
options: {
|
|
sourceMappingURL: function (script) {
|
|
//return '../src/source_maps/' + script.replace(/^.+\//, "") + '.map';
|
|
return '../../src/source_maps/' + script + '.map';
|
|
}
|
|
}
|
|
}
|
|
},
|
|
requirejs: {
|
|
compile: {
|
|
options: {
|
|
mainConfigFile: 'src/js/rjs/config.js'
|
|
//name: 'main',
|
|
//baseUrl: 'src/js/',
|
|
//out: 'js/requirejs.js'
|
|
//baseUrl: 'js',
|
|
//paths: {
|
|
// jquery: 'https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min',
|
|
//}
|
|
}
|
|
}
|
|
},
|
|
svgmin: { // Task
|
|
options: { // Configuration that will be passed directly to SVGO
|
|
plugins: [{
|
|
removeViewBox: false
|
|
}]
|
|
},
|
|
dist: { // 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.
|
|
}]
|
|
}
|
|
},
|
|
smushit: {
|
|
path: {
|
|
src: 'img/'
|
|
}
|
|
},
|
|
watch: {
|
|
options: {
|
|
nospawn: true
|
|
},
|
|
js: {
|
|
files: ['src/js/**/*.js', '!src/js/rjs/**/*.js'],
|
|
tasks: ['uglify:src']
|
|
},
|
|
requirejs: {
|
|
files: ['src/js/rjs/**/*.js'],
|
|
tasks: ['requirejs']
|
|
},
|
|
svg: {
|
|
files: ['src/svg/**/*.svg'],
|
|
tasks: ['svgmin']
|
|
},
|
|
img: {
|
|
files: ['img/**/*.png', 'img/**/*.jpg'],
|
|
tasks: ['smushit']
|
|
},
|
|
sass: {
|
|
files: ['src/sass/**/*.scss'],
|
|
tasks: ['compass'],
|
|
options: {
|
|
nospawn: true
|
|
}
|
|
},
|
|
}
|
|
|
|
});
|
|
// Plugins
|
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
|
grunt.loadNpmTasks('grunt-contrib-compass');
|
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
|
grunt.loadNpmTasks('grunt-svgmin');
|
|
grunt.loadNpmTasks('grunt-smushit');
|
|
|
|
grunt.loadNpmTasks('grunt-contrib-requirejs');
|
|
|
|
// Tasks
|
|
grunt.registerTask('default', ['jshint', 'uglify', 'requirejs']);
|
|
grunt.registerTask('image', ['smushit', 'svgmin']);
|
|
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 === 'svg') {
|
|
destFilePath = filepath.replace(/src\/svg\/(.+)$/, 'img/$1');
|
|
grunt.config('svgmin.dist.src', filepath);
|
|
grunt.config('svgmin.dist.dest', destFilePath);
|
|
|
|
} else if (target === 'markdown') {
|
|
destFilePath = filepath.replace(/src\/markdown\/([^.]+).+$/, 'application/views/pages/$1.php');
|
|
grunt.config('markdown.dist.src', filepath);
|
|
grunt.config('markdown.dist.dest', destFilePath);
|
|
|
|
} else if (target === 'img') {
|
|
grunt.config('smushit.path.src', filepath);
|
|
}
|
|
});
|
|
};
|