Skip to content

Commit 6e5cc50

Browse files
committed
Slight changes to the rjs task, moving config to gruntfile
1 parent a211792 commit 6e5cc50

File tree

2 files changed

+30
-19
lines changed

2 files changed

+30
-19
lines changed

tasks/h5bp.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ module.exports = function(grunt) {
3232
grunt.registerTask('default', 'build:default');
3333
grunt.registerTask('reload', 'default connect watch:reload');
3434

35+
// XXX move targets to the gruntfile? easier for user to tweak build profiles
3536
var targets = {
3637
default: 'concat css min img rev usemin manifest',
3738
text: 'concat css min rev usemin manifest',

tasks/rjs.js

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,35 @@
1-
var fs = require('fs'),
2-
path = require('path'),
3-
rjs = require('requirejs');
1+
var path = require('path'),
2+
rjs = require('requirejs');
43

54
module.exports = function(grunt) {
6-
grunt.task.registerMultiTask('rjs', 'Optimizes javascript that actually is built with requirejs.', function () {
7-
this.requiresConfig('rjs');
5+
grunt.task.registerTask('rjs', 'Optimizes javascript that actually is built with requirejs.', function () {
6+
this.requiresConfig(this.name);
7+
grunt.helper('rjs:optimize:js', grunt.config(this.name), this.async());
8+
});
89

9-
grunt.helper('rjs:optimize:js', this.data, this.async());
10-
});
10+
grunt.registerHelper('rjs:optimize:js', function(options, cb) {
11+
if(!cb) { cb = options; options = {}; }
12+
grunt.log.subhead('Options:');
13+
grunt.helper('inspect', options);
1114

12-
grunt.registerHelper('rjs:optimize:js', function(file, options, cb) {
13-
if(!cb) { cb = options; options = {}; }
14-
options.baseUrl = './';
15-
options.appDir = 'js';
16-
options.dir = grunt.config('output')+options.appDir;
17-
options.modules = [{
18-
name: file
19-
}];
20-
rjs.optimize(options, function() {
21-
cb();
22-
});
23-
});
15+
var originals = options.modules.map(function(m) {
16+
return {
17+
name: m.name,
18+
body: grunt.file.read(path.join(options.baseUrl, options.appDir, m.name + '.js'))
19+
};
20+
});
21+
22+
rjs.optimize(options, function() {
23+
originals.forEach(function(m) {
24+
var filepath = path.join(options.dir, m.name + '.js');
25+
grunt.log
26+
.writeln('rjs optimized module ' + m.name)
27+
.writeln('>> ' + filepath);
28+
grunt.helper('min_max_info', grunt.file.read(filepath), m.body);
29+
});
30+
31+
cb();
32+
});
33+
});
2434

2535
};

0 commit comments

Comments
 (0)