-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
169 lines (136 loc) · 4.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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 rollup = require('gulp-rollup')
const browserSync = require('browser-sync').create()
const pug = require('gulp-pug')
const prettyHtml = require('gulp-pretty-html')
const iconfont = require('gulp-iconfont')
const consolidate = require('gulp-consolidate')
const inject = require('gulp-inject-string')
// Types
const isDev = process.env.NODE_ENV === 'development'
const isModern = process.env.BROWSERS_ENV === 'modern'
/*
* Server
*/
if ( isDev ) {
gulp.task('serve', function() {
browserSync.init({
ui: false,
open: false,
notify: false,
port: 3002,
server: ['./examples', './dist']
})
gulp.watch('./resources/css/**/*.styl', gulp.series('build:styles'))
gulp.watch('./resources/img/**/*', gulp.series('build:img'))
gulp.watch(['./resources/js/**/*.js', './resources/vue/**/*.vue'], gulp.series('build:js', 'reload'))
// gulp.watch('./resources/pug/**/*.pug', gulp.series('build:html', 'reload'))
gulp.watch('./examples/**/*.html', gulp.series('reload'))
})
gulp.task('reload', function(done) { browserSync.reload(); done() })
}
/*
* Watch CSS Only
*/
gulp.task('watch-css', function() {
browserSync.init({
ui: false,
open: false,
notify: false,
port: 3009,
server: ['./examples', './dist']
})
gulp.watch('./resources/css/**/*.styl', gulp.series('build:styles'))
})
/*
* 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/framework/+(main|editor).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( isDev ? noop() : inject.prepend('/* Created: ' + new Date().toLocaleString("ru-RU") + ' */\n') )
.pipe( gulp.dest('./dist/css') )
.pipe( isDev ? browserSync.stream() : noop() )
})
/*
* IMAGES
*/
gulp.task('build:img', function() {
return gulp.src('./resources/img/**/*')
.pipe( gulp.dest('./dist/img') )
})
/*
* HTML
*/
gulp.task('build:html', function(){
return gulp.src('./resources/pug/*.pug')
.pipe( plumber() )
.pipe( pug() )
.pipe( prettyHtml() )
.pipe( gulp.dest('./examples') )
})
/*
* Icon Font
*/
const runTimestamp = Math.round(Date.now()/1000)
gulp.task('build:icons', function(){
return gulp.src('./resources/svg/*.svg')
.pipe(iconfont({
fontName: 'icons',
fontHeight: 1000,
prependUnicode: true,
formats: ['ttf', 'eot', 'woff'],
normalize: true,
timestamp: runTimestamp
}))
.on('glyphs', function(glyphs, options) {
gulp.src('./resources/svg/template/icons.styl')
.pipe( consolidate('lodash', {
glyphs: glyphs,
fontName: options.fontName,
fontPath: '../fonts/', // TODO: need full path in production build !!!
className: 'icon'
}) )
.pipe( gulp.dest('./resources/css/framework/') )
})
.pipe(gulp.dest('./dist/fonts/'));
})
/*
* Gloabl tasks
*/
gulp.task('clean', function(){
return gulp.src(['./dist'/*, './examples'*/], { read: false, allowEmpty: true })
.pipe( clean() )
})
gulp.task('build', gulp.series('build:js', 'build:img', 'build:icons', 'build:styles') )
// start
defaultTask = ['build']
if ( ! isModern ) defaultTask.unshift('clean')
if ( isDev ) {
//defaultTask = defaultTask.concat(['build:html', 'serve'])
defaultTask.push('serve')
}
gulp.task('default', gulp.series(defaultTask) )