-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
42 lines (32 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var PLUGIN_NAME = 'gulp-simple-requirejs',
path = require('path'),
gutil = require('gulp-util'),
requirejs = require('requirejs');
module.exports = function (opts) {
var stream = require('event-stream').through(),
fileName = opts.out,
rjsCb = function (text, sourceMapText) {
var output = fileName,
mapOutput = output + '.map';
if (sourceMapText) {
stream.write(new gutil.File({
path: mapOutput,
contents: new Buffer(sourceMapText)
}));
text += '//# sourceMappingURL=' + path.basename(mapOutput);
}
stream.write(new gutil.File({
path: output,
contents: new Buffer(text)
}));
stream.end();
},
errCb = function (err) {
console.error(err);
stream.emit('error', new gutil.PluginError(PLUGIN_NAME, err,{showStack: true}));
stream.end();
};
opts.out = rjsCb;
requirejs.optimize(opts, null, errCb);
return stream;
};