question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

transform babelify is slow since the very first run and it doesn't get better

See original GitHub issue

So i’ve been reading tons of posts about similar issues… I tried several different approaches with “watchify”, none of the helped… seems my problem is not the same everyone used to have…

Here’s my gulpfile:

// VENDOR LIBS
var browserify = require('browserify');
var buffer = require('vinyl-buffer');
var cleancss = require('gulp-clean-css');
var concat = require('gulp-concat');
var eslint = require('gulp-eslint');
var gulp = require('gulp');
var rimraf = require('rimraf');
var sass = require('gulp-sass');
var scsslint = require('gulp-scss-lint');
var source = require('vinyl-source-stream');
var uglify = require('gulp-uglify');

gulp.task('lint', function () {
    return gulp.src(['./app/**/*.js','!./node_modules/**', '!./dist/**'])
        .pipe(eslint())
        .pipe(eslint.format())
});

gulp.task('bundle', function () {
    return browserify({entries: './app/main.js', debug: true})
        .transform('babelify', {presets: ['es2015', 'react']})
        .bundle()
        .pipe(source('main.js'))
        .pipe(buffer())
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
});

gulp.task('sass', function () {
    gulp.src('./app/components/**/*.scss')
        .pipe(scsslint({config: 'lint.yml'}))
        .pipe(sass())
        .pipe(concat('styles.css'))
        .pipe(cleancss())
        .pipe(gulp.dest('./dist'));
});

gulp.task('copy', ['lint', 'bundle', 'sass'], function () {
    return gulp.src(['app/index.html','app/lib/bootstrap-css/css/bootstrap.min.css','app/style.css'])
        .pipe(gulp.dest('dist'));
});

gulp.task('rimraf', function () {
    rimraf.sync('dist');
});

gulp.task('watch', ['copy'], function () {
    gulp.watch(['app/**/*', '!dist/**/*'], ['copy']);
});

gulp.task('build',['rimraf', 'watch'], function () {
   console.log('Gulp completed...');
});

gulp.task('default', ['build']);

It takes “bundle” around 7 second to finish (on the first and every subsequent run) and i’m barely starting with my project, so i’m worried this is going to get worse later 😕

I tried removing the uglifier but it’s the same and the file weights a lot more so that’s a no-no…

Any ideas on how to make this thing go faster?

Thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
amirkdvcommented, Dec 3, 2019

I have been having similar issues and in my case the root issue was not babelify but rather my usage of browserify and watchify. As per watchify docs:

you MUST set the cache and packageCache properties

when creating the browserify instance (see code example below). In my case, I cut down my build times in watch (i.e. after the first build) from ~ 8 seconds to ~ 1 second by going from:

browserify(entry, {debug: true}).transform( ... )

to

browserify(entry, {debug: true, cache: {}, packageCache: {}}).transform( ... )

Turning debug off further cuts the 1 second down to 0.1 second for me.

Given the language in watchify docs, I’m confused why things would even work (instead of work and be super slow) if those two properties are not set.

0reactions
goto-bus-stopcommented, Nov 22, 2018

the OP is minifying the bundle too, and dependencies like react are quite large so depending on settings it can take a good while to minify. I’m not sure what gulp-uglify’s defaults are, but running terser -cm on just react-dom’s development build takes 4 seconds for me (without babel).

babelify does not run on dependencies unless you pass global: true. see earlier related questions: #268 #276 #56

the primary way to speed up builds in development is using watchify, which will only re-transpile the files that changed: https://github.com/browserify/watchify (and don’t minify in development! 😸 )

Read more comments on GitHub >

github_iconTop Results From Across the Web

browserify and babelify very slow due to large data js files
This works great and it works in the browser too (using browserify), however bundling takes ages - about 10 minutes. I use the...
Read more >
ES6 + browserify + babel + gulp + jasmine | Carlos Blé
Configuring the tools has taken more time than I thought as the tooling ... It must be a very specific problem on my...
Read more >
Getting import/export working ES6 style using Browserify + ...
Getting import/export working ES6 style using Browserify + Babelify + Gulp = -5hrs of life. Web browsers have traditionally been quite slow ......
Read more >
Improve your client-side-javascript workflow more by using ES6
To do this, you'll just pass a -t babelify parameter to browserify. So if you run it with the testbabel.js file as input...
Read more >
Using ECMAScript 6 (ES6/ES2015) with AngularJS 1.x
Since I prefer gulp over Grunt as a build tool, I will be using gulp ... transformations and you can plugin Babel via...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found