mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-49817 grunt: Refactor the uglify task
This is in preperation for the watch task and doing a few things: 1) Switch away from 'grunt.file.expandMapping' to the declarative syntax for doing the same thing, as recommended in docs: http://gruntjs.com/api/grunt.file#grunt.file.expandmapping 2) Factor the renaming function into shared function so it can be used from the watch task too. 3) Shared the file glob'ing pattern for match AMD js files between jshint and uglify task (this removes the node_modules exception.. we should add it to both if we need it). 4) Rename the task configuration - I am just doing this because it looks like 'dynamic_mappings' is some how magic config option when you look at the manual: http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically But in fact, it's just a task confguration name.
This commit is contained in:
parent
dbf6b40782
commit
5cc5f31101
44
Gruntfile.js
44
Gruntfile.js
@ -29,29 +29,39 @@ module.exports = function(grunt) {
|
||||
cwd = process.env.PWD || process.cwd(),
|
||||
inAMD = path.basename(cwd) == 'amd';
|
||||
|
||||
// Globbing pattern for matching all AMD JS source files.
|
||||
var amdSrc = [inAMD ? cwd + '/src/*.js' : '**/amd/src/*.js'];
|
||||
|
||||
/**
|
||||
* Function to generate the destination for the uglify task
|
||||
* (e.g. build/file.min.js). This function will be passed to
|
||||
* the rename property of files array when building dynamically:
|
||||
* http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically
|
||||
*
|
||||
* @param {String} destPath the current destination
|
||||
* @param {String} srcPath the matched src path
|
||||
* @return {String} The rewritten destination path.
|
||||
*/
|
||||
var uglify_rename = function (destPath, srcPath) {
|
||||
destPath = srcPath.replace('src', 'build');
|
||||
destPath = destPath.replace('.js', '.min.js');
|
||||
destPath = path.resolve(cwd, destPath);
|
||||
return destPath;
|
||||
};
|
||||
|
||||
// Project configuration.
|
||||
grunt.initConfig({
|
||||
jshint: {
|
||||
options: {jshintrc: '.jshintrc'},
|
||||
amd: {
|
||||
src: [inAMD ? cwd + '/src/*.js' : '**/amd/src/*.js']
|
||||
}
|
||||
amd: { src: amdSrc }
|
||||
},
|
||||
uglify: {
|
||||
dynamic_mappings: {
|
||||
files: grunt.file.expandMapping(
|
||||
['**/src/*.js', '!**/node_modules/**'],
|
||||
'',
|
||||
{
|
||||
cwd: cwd,
|
||||
rename: function(destBase, destPath) {
|
||||
destPath = destPath.replace('src', 'build');
|
||||
destPath = destPath.replace('.js', '.min.js');
|
||||
destPath = path.resolve(cwd, destPath);
|
||||
return destPath;
|
||||
}
|
||||
}
|
||||
)
|
||||
amd: {
|
||||
files: [{
|
||||
expand: true,
|
||||
src: amdSrc,
|
||||
rename: uglify_rename
|
||||
}]
|
||||
}
|
||||
},
|
||||
less: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user