Skip to content

Instantly share code, notes, and snippets.

@gradosevic
Last active November 24, 2022 06:27
Show Gist options
  • Save gradosevic/97bcde437502d021c6e1 to your computer and use it in GitHub Desktop.
Save gradosevic/97bcde437502d021c6e1 to your computer and use it in GitHub Desktop.
Working gulpfile.js with gulp-babel ES6 and React
var gulp = require('gulp');
var babel = require("gulp-babel");
var sourcemaps = require('gulp-sourcemaps');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
gulp.task('default', () => {
return gulp.src('js/main.js')
.pipe(sourcemaps.init())
.pipe(babel({
presets: ['es2015','react']
}))
.pipe(concat('all.js'))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build'));
});
gulp.task('watch', function () {
gulp.watch('js/*.js', ['default']);
});
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const browserify = require('browserify');
const babelify = require('babelify');
const source = require('vinyl-source-stream');
const rename = require('gulp-rename');
const streamify = require('gulp-streamify');
gulp.task('default', () => {
return browserify('main.js')
.transform(babelify, {presets: ["es2015", "react"]})
.bundle()
.pipe(source('all.js'))
.pipe(gulp.dest('build'))
.pipe(rename('all.min.js'))
.pipe(streamify(concat('all.min.js')))
.pipe(streamify(uglify()))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('build'));
});
gulp.task('watch', () => {
gulp.watch('js/*.js', ['default']);
});
@coder618
Copy link

Bro how to run this?

@bewards
Copy link

bewards commented May 19, 2021

This is an older approach to compiling react - try using gulp-babel with presets: ["@babel/env", "@babel/preset-react"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment