Skip to content

Instantly share code, notes, and snippets.

@nobuti
Forked from dverbovyi/gulpfile.js
Created February 4, 2017 06:53
Show Gist options
  • Save nobuti/b2b906b16f753832490d24464021295a to your computer and use it in GitHub Desktop.
Save nobuti/b2b906b16f753832490d24464021295a to your computer and use it in GitHub Desktop.
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"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment