-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
108 lines (91 loc) · 2.73 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
var DEST = './web/';
var gulp = require( 'gulp' );
var plumber = require( 'gulp-plumber' );
var mergeStream = require( 'merge-stream' );
var streamify = require( 'gulp-streamify' );
var less = require( 'gulp-less' );
var autoprefixer = require( 'gulp-autoprefixer' );
var cleanCSS = require( 'gulp-clean-css' );
var svgo = require( 'gulp-svgo');
var typogr = require( 'gulp-typogr' );
var htmlmin = require( 'gulp-htmlmin' );
var terser = require( 'gulp-terser' );
var replace = require( 'gulp-replace' );
var rollupStream = require( '@rollup/stream' );
const { nodeResolve } = require('@rollup/plugin-node-resolve');
var source = require( 'vinyl-source-stream' );
// Favicon
function favicon() {
return gulp.src( 'src/img/favicon.*' )
.pipe( gulp.dest( DEST ) );
};
// CSS
function css() {
return gulp.src( 'src/css/style.less' )
.pipe( plumber( { errorHandler: function ( err ) {
console.log(err);
this.emit('end');
} } ) )
.pipe( less() )
.pipe( autoprefixer() )
.pipe( cleanCSS() )
.pipe( gulp.dest( DEST ) );
};
// JS
function js() {
return mergeStream(
gulp.src( 'src/gsiril/gsiril.worker.js' )
.pipe( gulp.dest( DEST ) ),
gulp.src( 'src/js/service-worker.js' )
.pipe( replace('compositionprover-DATE', 'compositionprover-'+(new Date()).toISOString().substr(0,19).replace(/[-:T]/g,'') ) )
.pipe( streamify( terser() ) )
.pipe( gulp.dest( DEST ) ),
rollupStream( {
input: 'src/js/app.js',
output: { format: 'iife' },
plugins: [nodeResolve()]
} )
.pipe( source( 'app.js' ) )
.pipe( streamify( terser() ) )
.pipe( gulp.dest( DEST ) )
);
};
// HTML
function html() {
return gulp.src( 'src/html/index.html' )
.pipe( plumber( { errorHandler: function ( err ) {
console.log( err );
this.emit( 'end' );
}
} ) )
.pipe( typogr( { only: ['amp', 'widont', 'caps', 'smartypants'] } ) )
.pipe( htmlmin( { removeComments: true, collapseWhitespace: true } ) )
.pipe( gulp.dest( DEST ) );
};
// Manifest
function manifest() {
return gulp.src( 'src/manifest/manifest.json' )
.pipe( gulp.dest( DEST ) );
};
// Images
function img() {
return mergeStream(
gulp.src( ['src/img/*.svg'] )
.pipe( svgo() )
.pipe( gulp.dest( DEST ) ),
gulp.src( ['src/img/*.png'] )
.pipe( gulp.dest( DEST ) )
);
};
// Watcher
function watch() {
gulp.watch( ['src/**/*.less', 'src/**/*.css'], css );
gulp.watch( ['src/**/*.html'], html );
gulp.watch( ['src/**/*.js'], js );
gulp.watch( ['src/manifest/*'], manifest );
};
exports.default = gulp.parallel( css, html, js, img, favicon, manifest );
exports.css = css;
exports.html = html;
exports.js = js;
exports.watch = watch;