-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile4-01.js
More file actions
executable file
·111 lines (96 loc) · 2.54 KB
/
Copy pathgulpfile4-01.js
File metadata and controls
executable file
·111 lines (96 loc) · 2.54 KB
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
/*
Gulp 4 build flow
NPM Setup:
npm i gulp --global
npm i -D gulp
npm i -D gulp-inject
npm i -D gulp-sass
npm i -D gulp-uglify
npm i -D gulp-uglifycss
npm i -D gulp-htmlmin
npm i -D pump
npm i -D gulp-babel@next @babel/core
*/
/*
The idea of this gulp flow is to take SCSS and JC and insert it as text into index.html,
resulting in one self contained file.
It does not watch for changes, but when the HTML, CSS, and JSS
are at a certain point to bundle, run 'gulp all'.
Edited files are in /start.
Transpiled SCSS goes to /tmp
minified CSS and JS go to /dest
HTML with injected CSS and JS goes to /dest
minified HTML goes to /dist
*/
const { src, dest, series, parallel, watch } = require('gulp');
const inject = require('gulp-inject');
const sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var uglifycss = require('gulp-uglifycss');
var htmlmin = require('gulp-htmlmin');
var pump = require('pump');
const babel = require('gulp-babel');
/* functions */
/*
Transpile SCSS from /start into CSS and place in /tmp
*/
const transpilescss = () => {
return src('./start/**/*.scss')
.pipe(sass())
.pipe(dest('./tmp'));
};
/*
Minify CSS from /tmp and place in /dest
*/
const compresscss = () => {
return src('./tmp/**/*.css')
.pipe(uglifycss({
"maxLineLen": 0,
"uglyComments": true
}))
.pipe(dest('./dest'));
};
/*
Minify JS from /start and place in /dest
*/
const compressjs = () => {
return pump([
src('./start/**/*.js'),
uglify(),
dest('./dest')
]
);
};
/*
Inject JS from /dest into index.html from /start, as content not link, while adding <script> tags,
then inject CSS from /dest into that result, as content not link, while adding <style tags,
ouputing HTML to /dest
*/
const injectjscss = () => {
return src('./start/index.html')
.pipe(inject(src(['./dest/*.js']), {
starttag: '<!-- inject:head:js -->',
transform: function (filePath, file) {
return '<script>'+file.contents.toString('utf8')+'</script>'
}
}))
.pipe(inject(src(['./dest/*.css']), {
starttag: '<!-- inject:head:css -->',
transform: function (filePath, file) {
return '<style>'+file.contents.toString('utf8')+'</style>'
}
}))
.pipe(dest('./dest'));
};
/*
Minify the resulting index.htmlk from /dest, output it to /dist
*/
const comphtml = () => {
return src('./dest/**/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(dest('./dist'));
};
exports.all = series(transpilescss, compresscss, compressjs, injectjscss, comphtml);