Skip to content

Instantly share code, notes, and snippets.

@nowri
Last active August 29, 2015 14:27
Show Gist options
  • Save nowri/0741923b772d4d5ae76a to your computer and use it in GitHub Desktop.
Save nowri/0741923b772d4d5ae76a to your computer and use it in GitHub Desktop.

Revisions

  1. nowri revised this gist Aug 12, 2015. 1 changed file with 2 additions and 6 deletions.
    8 changes: 2 additions & 6 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,7 @@ var through = require('through2');
    var jade = require('react-jade');
    var ext = gutil.replaceExtension;
    module.exports = function (outputFileName) {
    /*
    transform関数:ファイル毎に呼び出される
    */

    function transform(file, enc, cb) {
    var jadePath = file.path;
    file.path = ext(file.path, '.js');
    @@ -24,8 +22,6 @@ module.exports = function (outputFileName) {
    }
    cb(null, file);
    }
    /*
    through2オブジェクトを生成してreturn
    */

    return through.obj(transform);
    };
  2. nowri revised this gist Aug 12, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion package.json
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    {
    "name": "react-jade-amd",
    "name": "gulp-react-jade-amd",
    "version": "1.0.0",
    "description": "",
    "main": "index.js",
  3. nowri revised this gist Aug 12, 2015. No changes.
  4. nowri created this gist Aug 12, 2015.
    31 changes: 31 additions & 0 deletions index.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    var gutil = require('gulp-util');
    var through = require('through2');
    var jade = require('react-jade');
    var ext = gutil.replaceExtension;
    module.exports = function (outputFileName) {
    /*
    transform関数:ファイル毎に呼び出される
    */
    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);
    }
    /*
    through2オブジェクトを生成してreturn
    */
    return through.obj(transform);
    };
    17 changes: 17 additions & 0 deletions package.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    {
    "name": "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"
    }
    }