Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Babel task/recipe #348

Closed
oskarrough opened this issue Jun 22, 2015 · 24 comments
Closed

Add Babel task/recipe #348

oskarrough opened this issue Jun 22, 2015 · 24 comments

Comments

@oskarrough
Copy link

Hi, would you be open to do an optional babel task (or recipe)? I've got it more or less working but there are some issues with uglify and how to properly fit the useref/serve/dist tasks properly.

@silvenon
Copy link
Member

Absolutely 👍 We'd like to include it in the core.

@silvenon
Copy link
Member

You can open the PR with what you have and we can help you to finish it.

@yonatanmn
Copy link

would like to see that happen too.

@pascaloliv
Copy link

Yes ! 👍 + 1

@oskarrough
Copy link
Author

Feels like I won't have time to open a PR but here's the task I'm currently using:

// Compile JavaScript with ES2015+
gulp.task('scripts', () => {
    return gulp.src(['app/scripts/**/*.js', '!app/scripts/vendor/**/*.js'])
        .pipe($.sourcemaps.init())
        .pipe($.babel())
        .pipe($.concat('main.js'))
        .pipe(gulp.dest('.tmp/scripts'))
        .pipe($.sourcemaps.write('.'))
        .pipe(browserSync.stream({ match: '**/*.js' }));
});

Not quite sure how it'll play together with the html task of this generator?

@silvenon
Copy link
Member

silvenon commented Aug 5, 2015

Yeah, some adjustments will have to be made… Thanks for sharing your workflow.

@vdclouis
Copy link

I guess you can just add it to the html task?

return gulp.src('app/*.html')
    .pipe(assets)
    .pipe($.if('*.js', $.babel(), $.uglify()))
    .pipe($.if('*.css', $.minifyCss({compatibility: '*'})))
    .pipe(assets.restore())
    .pipe($.useref())
    .pipe($.if('*.html', $.minifyHtml({conditionals: true, loose: true})))
    .pipe(gulp.dest('dist'));

Not sure how this will work with gulp serve though...
As you would need babel to transpile your js on the fly

@neilhem
Copy link
Collaborator

neilhem commented Aug 27, 2015

After moving from grunt to gulp we use config like this:

gulp.task('babel', () => {
  return gulp.src(['app/scripts/**/*.js'])
    .pipe($.sourcemaps.init())
    .pipe($.babel())
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/scripts'))
    .pipe(reload({stream: true}));
});

@wenerme
Copy link

wenerme commented Sep 2, 2015

@neilhem How you watch and recompile ?
I use you task config

gulp.task('scripts', () => {
  return gulp.src(['app/scripts/**/*.js', '!app/scripts/vendor/**/*.js'])
    .pipe($.sourcemaps.init())
    .pipe($.babel())
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/scripts'))
    .pipe(reload({stream: true}));
});

And add

gulp.watch('app/script/**/*.js', ['scripts']);
gulp.watch('app/script/main.js', ['scripts']);

to serve, but it will not recompile the js . How can I do ?

@wenerme
Copy link

wenerme commented Sep 3, 2015

Changed to

gulp.watch('app/**/*.js', ['scripts']);

works, why ?

@colinwhat
Copy link

I added the watch tasks, but is the 'scripts' task that @wenerme added also working for the build? I can't tell if the build is building from the source files or the tmp folder.

@neonowy neonowy mentioned this issue Oct 26, 2015
@alexej-d
Copy link

It's a pity the pull request received no updates any more, would love to have an easy way to write es6 js 😞

@silvenon
Copy link
Member

Yeah, it needs to be rebased and updated. I'll soon get around to fixing some long overdue issues, Babel will be one of them.

@alexej-d
Copy link

Sounds awesome! Looking forward! 😍

@Keyamoon
Copy link

Is it planned to support es6 modules with npm packages?

@silvenon
Copy link
Member

For that we would need to add a module bundler. Since there are so many (browserify, webpack, jspm…), we're hesitant about that. E.g. webpack could replace gulp altogether, so that would be a major rewrite and should perhaps be a separate project.

Do you have some preferences?

@alexej-d
Copy link

Probably leave out the module functionality and integrate that into another project to keep that one simple. (e.g. only add basic transpiling to this generator)

@silvenon
Copy link
Member

@alexej-d yes, my thoughts exactly.

@Keyamoon
Copy link

I have only used browserify so far. A separate project would be fine, but supporting modules using browserfiy wouldn't be that complicated either.

@silvenon
Copy link
Member

Released in v1.1.0.

@silvenon
Copy link
Member

@Keyamoon by the way, I'm maintaining generator-wbp, which uses browserify and stuff, it might be what you're looking for?

@Keyamoon
Copy link

@silvenon Thanks. Will take a look. With all the build tool options available, I'm no longer sure what I'm looking for!

@silvenon
Copy link
Member

@Keyamoon I feel you. I spent a lot of time using and studying these tools, here's the summary of my experience:

  • gulp – useful for presentation sites and small JS apps, but not flexible enough for heavy JS apps
  • browserify – easy to understand for beginners, but a task runner like gulp is probably still needed, and browserify's setup is not so pretty 😅
  • webpack – useful for JS apps (not so much for presentation sites), harder to understand at first, but totally worth it because it's very powerful and flexible with a much smaller configuration, no task runner needed

If you have questions, feel free to send me an email or something, I'd be happy to help further.

@Keyamoon
Copy link

@silvenon That's a good summary. Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants