2017-04-26 17:05:29 -04:00
|
|
|
'use strict';
|
|
|
|
|
2017-04-14 13:47:33 -04:00
|
|
|
const argv = require('yargs').argv;
|
|
|
|
const gulp = require('gulp'),
|
|
|
|
plumber = require('gulp-plumber');
|
|
|
|
const autoprefixer = require('gulp-autoprefixer');
|
|
|
|
const uglify = require('gulp-uglify');
|
|
|
|
const minifycss = require('gulp-clean-css');
|
|
|
|
const sass = require('gulp-sass');
|
|
|
|
const browserify = require("browserify");
|
|
|
|
const source = require('vinyl-source-stream');
|
|
|
|
const buffer = require('vinyl-buffer');
|
|
|
|
const babelify = require("babelify");
|
|
|
|
const watchify = require("watchify");
|
|
|
|
const envify = require("envify");
|
|
|
|
const gutil = require("gulp-util");
|
2017-07-27 10:14:53 -04:00
|
|
|
const liveReload = require('gulp-livereload');
|
2017-04-14 13:47:33 -04:00
|
|
|
|
|
|
|
if (argv.production) process.env.NODE_ENV = 'production';
|
2017-07-27 10:14:53 -04:00
|
|
|
let isProduction = argv.production || process.env.NODE_ENV === 'production';
|
2017-04-14 13:47:33 -04:00
|
|
|
|
|
|
|
gulp.task('styles', () => {
|
|
|
|
let chain = gulp.src(['resources/assets/sass/**/*.scss'])
|
|
|
|
.pipe(plumber({
|
|
|
|
errorHandler: function (error) {
|
|
|
|
console.log(error.message);
|
|
|
|
this.emit('end');
|
|
|
|
}}))
|
|
|
|
.pipe(sass())
|
|
|
|
.pipe(autoprefixer('last 2 versions'));
|
2017-07-27 10:14:53 -04:00
|
|
|
if (isProduction) chain = chain.pipe(minifycss());
|
|
|
|
return chain.pipe(gulp.dest('public/css/')).pipe(liveReload());
|
2017-04-14 13:47:33 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-07-27 10:14:53 -04:00
|
|
|
function scriptTask(watch = false) {
|
2017-04-14 13:47:33 -04:00
|
|
|
|
|
|
|
let props = {
|
|
|
|
basedir: 'resources/assets/js',
|
|
|
|
debug: true,
|
2017-07-27 10:14:53 -04:00
|
|
|
entries: ['global.js'],
|
|
|
|
fast: !isProduction,
|
|
|
|
cache: {},
|
|
|
|
packageCache: {},
|
2017-04-14 13:47:33 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
let bundler = watch ? watchify(browserify(props), { poll: true }) : browserify(props);
|
2017-07-27 10:14:53 -04:00
|
|
|
|
|
|
|
if (isProduction) {
|
|
|
|
bundler.transform(envify, {global: true}).transform(babelify, {presets: ['es2015']});
|
|
|
|
}
|
|
|
|
|
2017-04-14 13:47:33 -04:00
|
|
|
function rebundle() {
|
|
|
|
let stream = bundler.bundle();
|
|
|
|
stream = stream.pipe(source('common.js'));
|
2017-07-27 10:14:53 -04:00
|
|
|
if (isProduction) stream = stream.pipe(buffer()).pipe(uglify());
|
|
|
|
return stream.pipe(gulp.dest('public/js/')).pipe(liveReload());
|
2017-04-14 13:47:33 -04:00
|
|
|
}
|
2017-07-27 10:14:53 -04:00
|
|
|
|
2017-04-14 13:47:33 -04:00
|
|
|
bundler.on('update', function() {
|
|
|
|
rebundle();
|
2017-07-27 10:14:53 -04:00
|
|
|
gutil.log('Rebundling assets...');
|
2017-04-14 13:47:33 -04:00
|
|
|
});
|
2017-07-27 10:14:53 -04:00
|
|
|
|
2017-04-14 13:47:33 -04:00
|
|
|
bundler.on('log', gutil.log);
|
|
|
|
return rebundle();
|
|
|
|
}
|
|
|
|
|
|
|
|
gulp.task('scripts', () => {scriptTask(false)});
|
|
|
|
gulp.task('scripts-watch', () => {scriptTask(true)});
|
|
|
|
|
|
|
|
gulp.task('default', ['styles', 'scripts-watch'], () => {
|
2017-07-27 10:14:53 -04:00
|
|
|
liveReload.listen();
|
2017-04-14 13:47:33 -04:00
|
|
|
gulp.watch("resources/assets/sass/**/*.scss", ['styles']);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('build', ['styles', 'scripts']);
|