Skip to content

Commit 3b6df56

Browse files
author
Robin Thrift
committed
init commit with working code
0 parents  commit 3b6df56

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

index.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var gutil = require('gulp-util'),
2+
requirejs = require('requirejs'),
3+
PluginError = gutil.PluginError,
4+
File = gutil.File,
5+
es = require('event-stream');
6+
7+
// Consts
8+
const PLUGIN_NAME = 'gulp-requirejs';
9+
10+
11+
module.exports = function(opts) {
12+
13+
'use strict';
14+
15+
if (!opts) {
16+
throw PluginError(PLUGIN_NAME, 'Missing options array!');
17+
}
18+
19+
if (!opts.out && typeof opts.out !== 'string') {
20+
throw PluginError(PLUGIN_NAME, 'Only single file outputs are supported right now, please pass a valid output file name!');
21+
}
22+
23+
if (!opts.baseUrl) {
24+
throw PluginError(PLUGIN_NAME, 'Piping dirs/files is not supported right now, please specify the base path for your script.');
25+
}
26+
27+
// create the stream and save the file name (opts.out will be replaced by a callback function later)
28+
var _s = es.pause(),
29+
_fName = opts.out;
30+
31+
// 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
32+
// regular gulp plugins (i hope...).
33+
optimize(opts, function(text) {
34+
_s.write(new File({
35+
path: _fName,
36+
contents: new Buffer(text)
37+
}));
38+
});
39+
40+
// return the stream for chain .pipe()ing
41+
return _s;
42+
}
43+
44+
// a small wrapper around the r.js optimizer
45+
function optimize(opts, cb) {
46+
opts.out = cb;
47+
opts.optimize = 'none';
48+
requirejs.optimize(opts);
49+
}

package.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "gulp-requirejs",
3+
"description": "Builds projects using require.js's optimizer",
4+
"version": "0.1.0",
5+
"homepage": "http://github.com/robinthrift/gulp-requirejs",
6+
"repository": "git://github.com/robinthrift/gulp-requirejs.git",
7+
"author": "Robin Thrift <thrift.d.robin@googlemail.com> (http://webbrickworks.com/)",
8+
"main": "./index.js",
9+
"keywords": [
10+
"gulpplugin"
11+
],
12+
"dependencies": {
13+
"gulp-util": "~2.2.5",
14+
"requirejs": "2.1.8",
15+
"event-stream": "~3.0.20"
16+
},
17+
"devDependencies": {
18+
"mocha": "*",
19+
"should": "*"
20+
},
21+
"scripts": {
22+
"test": "mocha"
23+
},
24+
"engines": {
25+
"node": ">= 0.4.0"
26+
},
27+
"licenses": [
28+
{
29+
"type": "MIT",
30+
"url": "http://github.com/robinthrift/gulp-requirejs/raw/master/LICENSE"
31+
}
32+
]
33+
}

0 commit comments

Comments
 (0)