Skip to content

Instantly share code, notes, and snippets.

@twobyte
Created February 16, 2017 10:34
Show Gist options
  • Save twobyte/a7ce436227404736fb7793cb7be7b72c to your computer and use it in GitHub Desktop.
Save twobyte/a7ce436227404736fb7793cb7be7b72c to your computer and use it in GitHub Desktop.
Example of javascript bundling using Gulp
/*jslint node: true */
"use strict";
const $ = require('gulp-load-plugins')();
const argv = require('yargs').argv;
const gulp = require('gulp');
const browserSync = require('browser-sync').create();
const merge = require('merge-stream');
const colors = require('colors');
const gutil = require('gulp-util');
const cleanCSS = require('gulp-clean-css');
const PATHS = {
sass: [
'assets/scss/**',
],
javascript: [
// Include your own custom scripts (located in the custom folder)
//'bower_components/fastclick/lib/fastclick.js',
'bower_components/bootstrap-sass/assets/javascripts/bootstrap.js',
'assets/js/custom/*.js'
]
};
// Combine JavaScript into one file
// In production, the file is minified
gulp.task('javascript', function() {
return gulp.src(PATHS.javascript)
.pipe($.sourcemaps.init())
.pipe($.babel())
.pipe($.concat('script.js'))
.pipe($.if(isProduction, uglify ))
.pipe($.if(!isProduction, $.sourcemaps.write()))
.pipe(gulp.dest('assets/js'))
.pipe(browserSync.stream());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment