Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ES6 project with Gulp, Sass, Babel & Browserify
/**
* Created by Dmytro on 3/27/2016.
*/
var browserify = require('browserify'),
gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
sass = require('gulp-sass'),
autoprefixer = require('gulp-autoprefixer'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
browserSync = require('browser-sync');
/* pathConfig*/
var entryPoint = './src/index.js',
browserDir = './',
sassWatchPath = './styles/**/*.scss',
jsWatchPath = './src/**/*.js',
htmlWatchPath = './**/*.html';
/**/
gulp.task('js', function () {
return browserify(entryPoint, {debug: true, extensions: ['es6']})
.transform("babelify", {presets: ["es2015"]})
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build/'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('browser-sync', function () {
const config = {
server: {baseDir: browserDir}
};
return browserSync(config);
});
gulp.task('sass', function () {
return gulp.src(sassWatchPath)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions']
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build/css'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('watch', function () {
gulp.watch(jsWatchPath, ['js']);
gulp.watch(sassWatchPath, ['sass']);
gulp.watch(htmlWatchPath, function () {
return gulp.src('')
.pipe(browserSync.reload({stream: true}))
});
});
gulp.task('run', ['js', 'sass', 'watch', 'browser-sync']);
{
"name": "ES6 with Gulp, Sass, Babel & Browserify",
"version": "1.0.0",
"description": "Gulpfile for ES6 project",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Dmytro Verbovyi",
"devDependencies": {
"babel-preset-es2015": "^6.6.0",
"babelify": "^7.2.0",
"browser-sync": "^2.11.2",
"browserify": "^13.0.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.0",
"gulp-sass": "^2.2.0",
"gulp-sourcemaps": "^1.6.0",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
}
}
@lumonad

This comment has been minimized.

Copy link

lumonad commented Mar 28, 2016

thanks, this very usefull for my project

@ghost

This comment has been minimized.

Copy link

ghost commented Jul 28, 2017

thank you!

@alisterrick

This comment has been minimized.

Copy link

alisterrick commented Nov 8, 2017

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.