-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
37 lines (28 loc) · 856 Bytes
/
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
var through = require('through2');
var requirejs = require('requirejs');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;
// Consts
const PLUGIN_NAME = 'gulp-requirejs';
module.exports = function (opts) {
if (!opts) {
throw new PluginError(PLUGIN_NAME, 'Missing options array!');
}
if (!opts.baseUrl) {
throw new PluginError(PLUGIN_NAME, 'Pipeing dirs/files is not supported right now, please specify the base path for your script.');
}
var stream = through.obj(function (file, enc, callback) {
var optimize = function (illBeBack) {
opts.out = function (text) {
illBeBack(text);
stream.push(file);
return callback();
};
requirejs.optimize(opts);
};
return optimize(function (text) {
file.contents = Buffer(text);
});
});
return stream;
};