Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save iCodeForBananas/e539d415fb2effe86e5c53c1352738a9 to your computer and use it in GitHub Desktop.

Select an option

Save iCodeForBananas/e539d415fb2effe86e5c53c1352738a9 to your computer and use it in GitHub Desktop.
var gulp = require('gulp'),
autoprefixer = require('gulp-autoprefixer'),
browserify = require('browserify'),
cleanCSS = require('gulp-clean-css'),
gulpif = require('gulp-if'),
gutil = require('gulp-util'),
notify = require('gulp-notify'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
source = require('vinyl-source-stream'),
sourcemaps = require('gulp-sourcemaps'),
streamify = require('gulp-streamify'),
uglify = require('gulp-uglify'),
watchify = require('watchify'),
jsObfuscator = require('gulp-js-obfuscator'),
vueify = require('gulp-vueify')
var isProduction = process.env.NODE_ENV === 'production'
// ****************************************************
// Directory Variables
// ****************************************************
var APP = 'app/',
SRC = 'resources/assets/',
NODE = './node_modules/',
DIST = 'public/';
var handleError = function (err) {
console.error(err.message);
notify({message: err.message});
gutil.beep();
this.emit('end');
};
// ****************************************************
// CSS Tasks
// ****************************************************
// SCSS Compiling and Minification
gulp.task('scss', function () {
return gulp.src(SRC + 'sass/app.scss')
.pipe(sourcemaps.init())
.pipe(sass({
// sourcemap: true,
// debugInfo: true,
// lineNumbers: true,
includePaths: [
SRC + 'sass/'
]
}))
.on('error', handleError)
.pipe(autoprefixer('last 3 version'))
.pipe(cleanCSS({ debug: true }, function(details) {
console.log(details.name + ': ' + details.stats.originalSize)
console.log(details.name + ': ' + details.stats.minifiedSize)
}))
.pipe(sourcemaps.write('/', {
includeContent: false,
sourceMappingURLPrefix: '/css'
}))
.pipe(gulp.dest(DIST + '/css'))
.pipe(notify({message: 'SCSS Compiled!'}))
});
gulp.task('buildcss', ['scss']);
// ****************************************************
// Javascript Tasks
// ****************************************************
// Browserify
gulp.task('buildjs', function() {
var customOpts = {
debug: true,
entries: SRC + 'js/app.js',
plugin: [watchify]
}
var opts = Object.assign({}, watchify.args, customOpts)
var bundler = browserify(opts)
.transform("babelify", {
global: true,
ignore: /\/node_modules\//,
extensions: [".js"]
})
.transform("browserify-shim", {
global: true,
ignore: /\/node_modules\//,
extensions: [".js"]
})
var rebundle = function() {
var startDate = new Date();
console.log('Update start at ' + startDate.toLocaleString());
return bundler.bundle()
.on('error', handleError)
.pipe(source('app.min.js'))
.pipe(gulpif(isProduction, streamify(uglify({ mangle: false }))))
.pipe(gulpif(isProduction, streamify(jsObfuscator())))
.pipe(gulp.dest(DIST + 'js'))
.pipe(notify({message: 'JS Compiled!'}))
}
bundler.on('update', rebundle)
return rebundle()
})
// ****************************************************
// Master Build Tasks
// ****************************************************
gulp.task('build', ['buildcss', 'buildjs'])
// Gulp Default Task
gulp.task('default', ['build'], function() {
// Watch .scss files
gulp.watch([
SRC + 'sass/**/*.scss'
], ['scss']);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment