This repository has been archived by the owner on Apr 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
73 lines (62 loc) · 2.27 KB
/
gulpfile.babel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
var gulp = require('gulp');
var browserify = require('browserify');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var watch = require('gulp-watch');
var batch = require('gulp-batch');
var html = require('html-browserify');
var less = require('gulp-less');
var browserSync = require('browser-sync').create();
var environments = require('gulp-environments');
var cleanCSS = require('gulp-clean-css');
var development = environments.development;
var production = environments.production;
gulp.task('default', ['less', 'browserify', 'serve']);
gulp.task('install', ['less', 'browserify']);
gulp.task('browserify', function () {
var bundler = browserify({
entries: 'app/app.js',
paths: ['./node_modules','./app', './resources', './', './components'],
debug: false,
insertGlobals: true,
transform: html
})
//.transform('node-lessify')
.transform('babelify')
.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(development(sourcemaps.init({ loadMaps: true })))
.pipe(production(uglify().on('error', function (err) { console.error(err); })))
.pipe(development(sourcemaps.write('./')))
.pipe(gulp.dest('public/assets/js'));
});
gulp.task('less', function(){
gulp.src(['resources/assets/**/*.less'])
.pipe(development(sourcemaps.init({ loadMaps: true })))
.pipe(less())
.pipe(production(cleanCSS()))
.pipe(development(sourcemaps.write('./')))
.pipe(gulp.dest('public/assets'))
.pipe(browserSync.stream());
});
gulp.task('watchLess', function () {
watch(['resources/assets/**/*.less', 'app/**/*.less', '!app/dist/*'], batch(function (events, done) {
gulp.start('less', done);
}));
});
gulp.task('watch', function () {
watch(['app/*.js', 'app/**/*.js', 'public/*.html', 'resources/**/*.html', 'config/*.js', 'components/**/*.js'], batch(function (events, done) {
gulp.start('browserify', done);
}));
});
gulp.task('serve', ['watch', 'watchLess'], function() {
browserSync.init({
server: {
baseDir: "public"
}
});
gulp.watch("public/assets/js/app.js").on('change', browserSync.reload);
});