-
-
Save nevernotsean/625cb56867811564b8621828903ceee6 to your computer and use it in GitHub Desktop.
ES6 project with Gulp, Sass, Babel & Browserify
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An awesome and slightly modified gulp, babel, sass workflow via https://gist.github.com/dverbovyi/7f71879bec8a16847dee | |
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/app.js', | |
browserDir = './dist/', | |
sassWatchPath = './src/assets/sass/**/*.scss', | |
jsWatchPath = './src/**/*.js', | |
htmlWatchPath = './public/**/*.html' | |
/**/ | |
gulp.task('js', function() { | |
return browserify(entryPoint, { debug: true, extensions: ['es6'] }) | |
.transform('babelify', { presets: ['es2015', 'react'] }) | |
.bundle() | |
.pipe(source('app.js')) | |
.pipe(buffer()) | |
.pipe(sourcemaps.init({ loadMaps: true })) | |
.pipe(sourcemaps.write()) | |
.pipe(gulp.dest('./dist/js/')) | |
.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('./dist/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']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "React, 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": "Sean Harrington", | |
"devDependencies": { | |
"babel-preset-es2015": "^6.6.0", | |
"babelify": "^7.3.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", | |
"react": "^15.6.1", | |
"react-dom": "^15.6.1", | |
"vinyl-buffer": "^1.0.0", | |
"vinyl-source-stream": "^1.1.0", | |
"babel-preset-react": "^6.24.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment