Skip to content

Commit

Permalink
Fixed out of memory error: babel/babel#558
Browse files Browse the repository at this point in the history
  • Loading branch information
mbektimirov committed Jan 21, 2015
1 parent 9f5d9a1 commit 0bdcde6
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 18 deletions.
53 changes: 53 additions & 0 deletions gulp/tasks/6to5ify.js
Original file line number Diff line number Diff line change
@@ -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;
};
};
24 changes: 6 additions & 18 deletions gulp/tasks/browserify.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,32 +24,21 @@ gulp.task('browserify', function() {
detectGlobals: false
});

bundler.transform(_6to5.configure({
ignore: 'node_modules',
sourceMap: false
}));

var bundle = function() {
// Log when bundling starts
bundleLogger.start();

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);
};

Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down

0 comments on commit 0bdcde6

Please sign in to comment.