-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·180 lines (154 loc) · 4.79 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
170
171
172
173
174
175
176
177
178
179
180
var gulp = require('gulp');
var plugin = require('gulp-load-plugins')();
var rollup = require('rollup');
var rollup_resolve = require('@rollup/plugin-node-resolve');
var rollup_commonjs = require('@rollup/plugin-commonjs');
var minifyjs = require('gulp-minify.js');
var destDir = './assets';
// === Stylus
gulp.task('css:app', function() {
return gulp.src([
'./src/stylus/*.styl',
'!./src/stylus/libs.styl',
])
.pipe(plugin.sourcemaps.init())
.pipe(plugin.stylus({
'include css': true,
compress: false
}).on('error', plugin.notify.onError('<%= error.message %>')))
.pipe(plugin.autoprefixer({
remove: false,
cascade: false,
}))
.pipe(plugin.sourcemaps.write('../css'))
.pipe(gulp.dest(destDir + '/css'))
});
gulp.task('css:libs', function() {
return gulp.src([
'./src/stylus/libs.styl',
])
.pipe(plugin.stylus({
'include css': true,
compress: false
}).on('error', plugin.notify.onError('<%= error.message %>')))
.pipe(gulp.dest(destDir + '/css/'))
});
gulp.task('css:bundle', function() {
return gulp.src([
destDir + '/css/libs.css',
destDir + '/css/main.css',
])
.pipe(plugin.concat('bundle.css'))
.pipe(gulp.dest(destDir + '/css/'));
});
gulp.task('css:minify', function() {
return gulp.src([
destDir + '/css/*.css',
'!' + destDir + '/css/*.min.css',
])
.pipe(plugin.cleanCss())
.pipe(plugin.rename({
suffix: '.min'
}))
.pipe(gulp.dest(destDir + '/css/'));
});
gulp.task('css', gulp.series('css:app', 'css:libs', 'css:bundle', 'css:minify'));
// === JS
gulp.task('js:app', function() {
return gulp.src([
'./src/js/*.js',
'!./src/js/libs.js',
])
.pipe(plugin.sourcemaps.init())
.pipe(plugin.include()).on('error', console.log)
.pipe(plugin.babel({ presets: [ '@babel/env' ] }))
.pipe(plugin.sourcemaps.write('../js'))
.pipe(gulp.dest(destDir + '/js'))
});
gulp.task('js:libs', function() {
return rollup.rollup({
input: './src/js/libs.js',
plugins: [ rollup_commonjs(), rollup_resolve() ],
})
.then(bundle => {
return bundle.write({
file: destDir + '/js/libs.js',
format: 'umd',
sourcemap: false,
});
});
});
gulp.task('js:bundle', function() {
return gulp.src([
'./assets/js/libs.js',
'./assets/js/main.js',
])
.pipe(plugin.concat('bundle.js'))
.pipe(gulp.dest(destDir + '/js/'))
});
gulp.task('js:minify', function() {
return gulp.src([
destDir + '/js/*.js',
'!' + destDir + '/js/*.min.js',
])
// .pipe(plugin.uglify())
.pipe(minifyjs())
.pipe(plugin.rename({
suffix: '.min'
}))
.pipe(gulp.dest(destDir + '/js'));
});
gulp.task('js', gulp.series('js:app', 'js:libs', 'js:bundle', 'js:minify'));
// === SVG
gulp.task('svg:sprite', function() {
return gulp.src([
'./assets/icons/*.svg',
'!./assets/icons/sprit*.svg',
])
.pipe(plugin.svgSymbolView({
name: 'sprite',
svgo: { plugins: [
{ removeAttrs: {attrs: '(fill-rule|clip-rule|fill|color|stroke-linecap|stroke-linejoin|style)'} }
]}
}))
.pipe(gulp.dest(destDir + '/icons'));
});
gulp.task('svg:spritecolor', function() {
return gulp.src([
'./assets/icons/*.svg',
'!./assets/icons/sprit*.svg',
])
.pipe(plugin.svgSymbolView({
name: 'sprite-color',
}))
.pipe(gulp.dest(destDir + '/icons'));
});
gulp.task('svg', gulp.series('svg:sprite', 'svg:spritecolor'));
// === Reloader
gulp.task('reloader', function(done) {
plugin.livereload.changed('/');
done();
});
// === Watch
gulp.task('watch', function() {
plugin.livereload.listen({
basePath: './',
start: true
});
// --- CSS
gulp.watch(['./src/stylus/**/*.styl', '!./src/stylus/**/libs.styl'], gulp.series('css:app', 'css:bundle', 'css:minify', 'reloader'));
gulp.watch(['./src/stylus/**/libs.styl'], gulp.series('css:libs', 'css:bundle', 'css:minify', 'reloader'));
// --- JS
gulp.watch(['./src/js/**/*.js', '!./src/js/**/libs.js'], gulp.series('js:app', 'js:bundle', 'js:minify', 'reloader'));
gulp.watch(['./src/js/**/libs.js'], gulp.series('js:libs', 'js:bundle', 'js:minify', 'reloader'));
// --- PHP
gulp.watch(['*.php', 'views/**/*.php'], function php(done) {
plugin.livereload.reload();
done();
});
});
gulp.task('media', gulp.series('svg', 'reloader'), function () {});
gulp.task('build', gulp.series( 'svg', 'css', 'js' ),
function() {}
);
gulp.task('default', gulp.series('build', 'watch'), function () {});