diff --git a/gulp/tasks/6to5ify.js b/gulp/tasks/6to5ify.js new file mode 100644 index 0000000..87b2630 --- /dev/null +++ b/gulp/tasks/6to5ify.js @@ -0,0 +1,53 @@ +var through = require("through"); +var path = require("path"); +var to5 = require("6to5-core"); +var _ = require("lodash"); + +var browserify = module.exports = function (filename, opts) { + return browserify.configure(opts)(filename); +}; + +browserify.configure = function (opts) { + opts = opts || {}; + if (opts.sourceMap !== false) opts.sourceMap = "inline" ; + if (opts.extensions) opts.extensions = to5._util.arrayify(opts.extensions); + if (opts.ignore) opts.ignore = to5._util.regexify(opts.ignore); + if (opts.only) opts.only = to5._util.regexify(opts.only); + + return function (filename) { + if ((opts.ignore && opts.ignore.test(filename)) || + (opts.only && !opts.only.test(filename)) || + !to5.canCompile(filename, opts.extensions)) { + return through(); + } + + if (opts.sourceMapRelative) { + filename = path.relative(opts.sourceMapRelative, filename); + } + + var data = ""; + + var write = function (buf) { + data += buf; + }; + + var end = function () { + var opts2 = _.clone(opts); + opts2.filename = filename; + + try { + var out = to5.transform(data, opts2).code; + } catch(err) { + stream.emit("error", err); + stream.queue(null); + return; + } + + stream.queue(out); + stream.queue(null); + }; + + var stream = through(write, end); + return stream; + }; +}; diff --git a/gulp/tasks/browserify.js b/gulp/tasks/browserify.js index 0f45499..c635525 100644 --- a/gulp/tasks/browserify.js +++ b/gulp/tasks/browserify.js @@ -4,19 +4,18 @@ var bundleLogger = require('../util/bundleLogger'); var gulp = require('gulp'); var handleErrors = require('../util/handleErrors'); var source = require('vinyl-source-stream'); -var _6to5 = require('6to5ify'); +var _6to5 = require('./6to5ify'); var aliasify = require('aliasify'); var externalLibs = require('../external-libs'); var cssify = require('cssify'); var reactify = require('reactify'); +var buffer = require('vinyl-buffer'); gulp.task('browserify', function() { var bundler = browserify({ cache: {}, packageCache: {}, fullPaths: true, - // Specify the entry point of your app entries: ['./src/scripts/app.jsx'], - // Add file extentions to make optional in your requires extensions: ['.js', '.jsx', /*'.css', '.scss'*/], debug: false, //!gulp.env.production, // enable source maps //global: true, // global transforms @@ -25,6 +24,10 @@ gulp.task('browserify', function() { detectGlobals: false }); + bundler.transform(_6to5.configure({ + ignore: 'node_modules', + sourceMap: false + })); var bundle = function() { // Log when bundling starts @@ -32,25 +35,10 @@ gulp.task('browserify', function() { return bundler .external(externalLibs) - // .transform({global: true}, aliasify) - // .transform(reactify) - // .transform(cssify) - .transform(_6to5.configure({ - sourceMap: 'inline' - })) .bundle() - // Report compile errors .on('error', handleErrors) - // Use vinyl-source-stream to make the - // stream gulp compatible. Specifiy the - // desired output filename here. .pipe(source('app.js')) - // .pipe(changed('./build/', {extension: '.js'})) - // .pipe(debug({verbose: true})) - // .pipe(transform(function () { return exorcist('./build/app.js.map'); })) - // Specify the output destination .pipe(gulp.dest('./build/')) - // Log when bundling completes! .on('end', bundleLogger.end); }; diff --git a/package.json b/package.json index f627729..8777331 100644 --- a/package.json +++ b/package.json @@ -40,6 +40,7 @@ "react-bootstrap": "^0.13.2" }, "devDependencies": { + "6to5-core": "^2.13.5", "6to5ify": "^3.1.2", "aliasify": "^1.5.1", "browser-sync": "^1.9.0", @@ -66,6 +67,8 @@ "pretty-hrtime": "^1.0.0", "reactify": "^0.17.1", "sassify": "^0.5.2", + "through": "^2.3.6", + "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.0.0", "vinyl-transform": "1.0.0", "watchify": "^2.2.1"