Skip to content

Instantly share code, notes, and snippets.

@nowri
Last active August 29, 2015 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nowri/0741923b772d4d5ae76a to your computer and use it in GitHub Desktop.
Save nowri/0741923b772d4d5ae76a to your computer and use it in GitHub Desktop.
react-jade amd-export gulp-plugin
var gutil = require('gulp-util');
var through = require('through2');
var jade = require('react-jade');
var ext = gutil.replaceExtension;
module.exports = function (outputFileName) {
function transform(file, enc, cb) {
var jadePath = file.path;
file.path = ext(file.path, '.js');
if(file.isStream()){
return cb(new PluginError('gulp-jade', 'Streaming not supported'));
}
if(file.isBuffer()){
try {
var compiled;
compiled = 'define(["react"], function(React){ return ' + jade.compileFileClient(jadePath, {globalReact:true}) + '});';
file.contents = new Buffer(compiled);
} catch(e) {
return cb(new PluginError('gulp-jade', e));
}
}
cb(null, file);
}
return through.obj(transform);
};
{
"name": "gulp-react-jade-amd",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"gulp-util": "^3.0.6",
"react": "^0.13.3",
"react-jade": "^2.4.0",
"through2": "^2.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment