-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
gulpfile.js
85 lines (67 loc) · 2.17 KB
/
gulpfile.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
73
74
75
76
77
78
79
80
81
82
83
84
85
const gulp = require('gulp')
const clean = require('gulp-clean')
const plumber = require('gulp-plumber')
const noop = require('gulp-noop')
const stylus = require('gulp-stylus')
const postcss = require('gulp-postcss')
const nib = require('nib')
const sourcemaps = require('gulp-sourcemaps')
const browserSync = require('browser-sync').create()
const rollup = require('gulp-rollup')
const isDev = process.env.NODE_ENV === 'development'
const isModern = process.env.BROWSERSLIST_ENV === 'modern'
/*
* Server
*/
if ( isDev ) {
gulp.task('serve', function(){
browserSync.init({
ui: false,
open: false,
notify: false,
serveStatic: ['./examples', './dist'],
proxy: "localhost:3030"
})
gulp.watch('./resources/css/**/*.styl', gulp.series('build:styles'))
gulp.watch(['./resources/js/**/*.js', './resources/vue/**/*.vue', 'src/vue/**/*.js'], gulp.series('build:js', 'reload'))
gulp.watch('./examples/**/*.html', gulp.series('reload'))
})
gulp.task('reload', function(done) { browserSync.reload(); done() })
}
/*
* JS
*/
const rollupConfig = require('./rollup.config.js')
rollupConfig.allowRealFiles = true // solves gulp-rollup hipotetical file system problem
rollupConfig.rollup = require('rollup')
gulp.task('build:js', function(){
return gulp.src('./resources/js/main.js')
.pipe( plumber() )
.pipe( rollup(rollupConfig) )
.pipe( gulp.dest('./dist/js') )
})
/*
* Styles
*/
gulp.task('build:styles', function(){
return gulp.src('./resources/css/main.styl')
.pipe( plumber() )
.pipe( isDev ? sourcemaps.init() : noop() )
.pipe( stylus({ use: nib(), 'include css': true, import: ['nib'], compress: false }) )
.pipe( isDev ? noop() : postcss() )
.pipe( isDev ? sourcemaps.write() : noop() )
.pipe( gulp.dest('./dist/css') )
.pipe( isDev ? browserSync.stream() : noop() )
})
/*
* Gloabl tasks
*/
gulp.task('clean', function(){
return gulp.src('./dist', { read: false, allowEmpty: true })
.pipe( clean() )
})
gulp.task('build', gulp.series('build:js', 'build:styles') )
// start
defaultTask = ['clean', 'build']
if ( isDev ) defaultTask.push('serve')
gulp.task('default', gulp.series(defaultTask) )