mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
Vastly sped up gulp watch and added livereload
This commit is contained in:
parent
f200b4183d
commit
072f6b103e
28
gulpfile.js
28
gulpfile.js
@ -12,8 +12,10 @@ const babelify = require("babelify");
|
||||
const watchify = require("watchify");
|
||||
const envify = require("envify");
|
||||
const gutil = require("gulp-util");
|
||||
const liveReload = require('gulp-livereload');
|
||||
|
||||
if (argv.production) process.env.NODE_ENV = 'production';
|
||||
let isProduction = argv.production || process.env.NODE_ENV === 'production';
|
||||
|
||||
gulp.task('styles', () => {
|
||||
let chain = gulp.src(['resources/assets/sass/**/*.scss'])
|
||||
@ -24,31 +26,40 @@ gulp.task('styles', () => {
|
||||
}}))
|
||||
.pipe(sass())
|
||||
.pipe(autoprefixer('last 2 versions'));
|
||||
if (argv.production) chain = chain.pipe(minifycss());
|
||||
return chain.pipe(gulp.dest('public/css/'));
|
||||
if (isProduction) chain = chain.pipe(minifycss());
|
||||
return chain.pipe(gulp.dest('public/css/')).pipe(liveReload());
|
||||
});
|
||||
|
||||
|
||||
function scriptTask(watch=false) {
|
||||
function scriptTask(watch = false) {
|
||||
|
||||
let props = {
|
||||
basedir: 'resources/assets/js',
|
||||
debug: true,
|
||||
entries: ['global.js']
|
||||
entries: ['global.js'],
|
||||
fast: !isProduction,
|
||||
cache: {},
|
||||
packageCache: {},
|
||||
};
|
||||
|
||||
let bundler = watch ? watchify(browserify(props), { poll: true }) : browserify(props);
|
||||
bundler.transform(envify, {global: true}).transform(babelify, {presets: ['es2015']});
|
||||
|
||||
if (isProduction) {
|
||||
bundler.transform(envify, {global: true}).transform(babelify, {presets: ['es2015']});
|
||||
}
|
||||
|
||||
function rebundle() {
|
||||
let stream = bundler.bundle();
|
||||
stream = stream.pipe(source('common.js'));
|
||||
if (argv.production) stream = stream.pipe(buffer()).pipe(uglify());
|
||||
return stream.pipe(gulp.dest('public/js/'));
|
||||
if (isProduction) stream = stream.pipe(buffer()).pipe(uglify());
|
||||
return stream.pipe(gulp.dest('public/js/')).pipe(liveReload());
|
||||
}
|
||||
|
||||
bundler.on('update', function() {
|
||||
rebundle();
|
||||
gutil.log('Rebundle...');
|
||||
gutil.log('Rebundling assets...');
|
||||
});
|
||||
|
||||
bundler.on('log', gutil.log);
|
||||
return rebundle();
|
||||
}
|
||||
@ -57,6 +68,7 @@ gulp.task('scripts', () => {scriptTask(false)});
|
||||
gulp.task('scripts-watch', () => {scriptTask(true)});
|
||||
|
||||
gulp.task('default', ['styles', 'scripts-watch'], () => {
|
||||
liveReload.listen();
|
||||
gulp.watch("resources/assets/sass/**/*.scss", ['styles']);
|
||||
});
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
"gulp": "3.9.1",
|
||||
"gulp-autoprefixer": "3.1.1",
|
||||
"gulp-clean-css": "^3.0.4",
|
||||
"gulp-livereload": "^3.8.1",
|
||||
"gulp-minify-css": "1.2.4",
|
||||
"gulp-plumber": "1.1.0",
|
||||
"gulp-sass": "3.1.0",
|
||||
|
Loading…
Reference in New Issue
Block a user