Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var gutil = require('gulp-util'),
requirejs = require('requirejs'),
PluginError = gutil.PluginError,
File = gutil.File,
es = require('event-stream')
es = require('event-stream'),
fs = require("fs");

// Consts
const PLUGIN_NAME = 'gulp-requirejs';
Expand Down Expand Up @@ -30,27 +31,45 @@ module.exports = function(opts) {

// just a small wrapper around the r.js optimizer, we write a new gutil.File (vinyl) to the Stream, mocking a file, which can be handled
// regular gulp plugins (i hope...).

// try {
optimize(opts, function(text) {
_s.write(new File({
path: _fName,
contents: new Buffer(text)
}));

optimize(opts, function(text, buildText) {
var newFile = new File({
path: _fName,
contents: new Buffer(text)
});
// } catch (err) {
// _s.emit('error', err);
// }
newFile.buildResponse = buildText;
_s.write(newFile);
});




// return the stream for chain .pipe()ing
return _s;
}

// a small wrapper around the r.js optimizer
function optimize(opts, cb) {
opts.out = cb;
var scriptName = opts.out,
buildResponse = false;

var callbackIfBuildResponse = function(text) {
if(buildResponse) {
cb(text, buildResponse);
} else {
process.nextTick(function() {
callbackIfBuildResponse(text);
})
}
}
opts.out = callbackIfBuildResponse;
opts.optimize = 'none';
requirejs.optimize(opts);
requirejs.optimize(opts, function(br) {
if(br) {
buildResponse = br.replace("FUNCTION", scriptName);
}
}, function(err) {
if(err) {
buildResponse = "error";
}
});
}
11 changes: 5 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
"repository": "git://github.com/robinthrift/gulp-requirejs.git",
"author": "Robin Thrift <thrift.d.robin@googlemail.com> (http://webbrickworks.com/)",
"main": "./index.js",
"keywords": [
],
"keywords": [],
"dependencies": {
"gulp-util": "~2.2.5",
"requirejs": "2.1.8",
"event-stream": "~3.0.20"
"event-stream": "^3.0.20",
"gulp-util": "^2.2.20",
"requirejs": "^2.1.8"
},
"devDependencies": {
"mocha": "*",
Expand All @@ -29,4 +28,4 @@
"url": "http://github.com/robinthrift/gulp-requirejs/raw/master/LICENSE"
}
]
}
}