Last active
August 29, 2015 14:27
-
-
Save nowri/0741923b772d4d5ae76a to your computer and use it in GitHub Desktop.
react-jade amd-export gulp-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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