-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
237 lines (208 loc) · 7.07 KB
/
Copy pathgulpfile.js
File metadata and controls
237 lines (208 loc) · 7.07 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
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
const {watch, series, parallel, src, dest, task} = require('gulp');
const del = require('del');
const plumber = require('gulp-plumber');
const cache = require('gulp-cache');
const zip = require('gulp-zip');
const mergeStream = require('merge-stream');
const fs = require('fs');
const sass = require('gulp-sass');
sass.compiler = require('node-sass');
const sourcemaps = require('gulp-sourcemaps');
const cssnano = require('cssnano');
const autoprefixer = require('autoprefixer');
const postcss = require('gulp-postcss');
const flexFix = require('postcss-flexbugs-fixes');
const imagemin = require('gulp-imagemin');
const realFavicon = require('gulp-real-favicon');
const htmlmin = require('gulp-htmlmin');
const browserSync = require('browser-sync').create();
const uglify = require('gulp-uglify-es').default;
const iconfont = require('gulp-iconfont');
const iconfontCss = require('gulp-iconfont-css');
const woff = require('gulp-ttf2woff');
const woff2 = require('gulp-ttf2woff2');
const projectConfig = require('./package.json');
const FAVICON_DATA_FILE = 'faviconData.json';
function removeDist() {
return del('dist');
}
function removeZip() {
return del(`${projectConfig.name}.zip`, {force: true});
}
function compileSass() {
return src(['src/sass/*.scss', 'src/sass/libs/*.scss']).
pipe(plumber()).
pipe(sourcemaps.init()).
pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError)).
pipe(sourcemaps.write('./')).
pipe(dest('src/css')).
pipe(browserSync.stream());
}
function buildCSS() {
return src('src/css/*.css').
pipe(postcss([
autoprefixer({cascade: false}),
flexFix(),
cssnano()
])).
pipe(dest('dist/css'));
}
function buildImages() {
return src('src/images/**/*').pipe(cache(
imagemin([
imagemin.gifsicle({interlaced: true}),
imagemin.mozjpeg({quality: 75, progressive: true}),
imagemin.optipng({optimizationLevel: 5}),
imagemin.svgo({
plugins: [
{removeViewBox: true},
{cleanupIDs: false}
]
})
], {
verbose: true
}), {
name: 'images'
})
).pipe(dest('dist/images'));
}
function favicon(done) {
return realFavicon.generateFavicon({
masterPicture: 'src/assets/favicon.png',
dest: 'dist/favicon',
iconsPath: 'favicon/',
design: {
ios: {
pictureAspect: 'noChange',
assets: {
ios6AndPriorIcons: false,
ios7AndLaterIcons: false,
precomposedIcons: false,
declareOnlyDefaultIcon: true
}
},
desktopBrowser: {},
windows: {
pictureAspect: 'noChange',
backgroundColor: '#da532c',
onConflict: 'override',
assets: {
windows80Ie10Tile: false,
windows10Ie11EdgeTiles: {
small: false,
medium: true,
big: false,
rectangle: false
}
}
},
androidChrome: {
pictureAspect: 'noChange',
themeColor: '#ffffff',
manifest: {
display: 'standalone',
orientation: 'notSet',
onConflict: 'override',
declared: true
},
assets: {
legacyIcon: false,
lowResolutionIcons: false
}
}
},
settings: {
scalingAlgorithm: 'Mitchell',
errorOnImageTooSmall: false,
readmeFile: false,
htmlCodeFile: false,
usePathAsIs: false
},
markupFile: FAVICON_DATA_FILE
}, function () {
src('dist/*.html').
pipe(realFavicon.injectFaviconMarkups(
JSON.parse(fs.readFileSync(FAVICON_DATA_FILE)).favicon.html_code)
).
pipe(dest('dist')).on('end', done);
});
}
function checkFaviconUpdate(done) {
const currentVersion = JSON.parse(fs.readFileSync(FAVICON_DATA_FILE)).version;
realFavicon.checkForUpdates(currentVersion, function (err) {
if (err) {
throw err;
}
done();
});
}
function buildHtml() {
return src('src/*.html').pipe(htmlmin({collapseWhitespace: true})).pipe(dest('dist'));
}
function clear() {
return cache.clearAll();
}
function buildJS() {
const moveMinifyJS = src(['src/js/common.js']).
pipe(dest('dist/js'));
const minAndMoveJS = src(['src/js/*', '!src/js/*.min.js', '!src/js/common.js']).
pipe(uglify()).
pipe(dest('dist/js'));
return mergeStream(moveMinifyJS, minAndMoveJS);
}
function buildFonts() {
return src('src/fonts/**/*').
pipe(dest('dist/fonts'));
}
function getZip() {
return src(['**/*', '!node_modules/**', '!..*']).
pipe(zip(`${projectConfig.name}.zip`)).
pipe(dest('./'));
}
function fontIcon() {
return src('src/assets/icons/*.svg').pipe(iconfontCss({
fontName: 'iconfont',
path: 'src/assets/templates/iconfont',
targetPath: '../../css/iconfont.css',
fontPath: '../fonts/iconfont/'
})).pipe(iconfont({
fontName: 'iconfont',
prependUnicode: true,
formats: ['woff', 'woff2'],
timestamp: Math.round(Date.now() / 1000),
centerHorizontally: true,
normalize: true
})).pipe(dest('src/fonts/iconfont'));
}
function fonts() {
const woffFonts = src('src/assets/fonts/**/*.ttf').
pipe(woff()).
pipe(dest('src/fonts'));
const woff2Fonts = src('src/assets/fonts/**/*.ttf').
pipe(woff2()).
pipe(dest('src/fonts'));
return mergeStream(woffFonts, woff2Fonts);
}
exports.default = function () {
browserSync.init({
server: {
baseDir: 'src',
index: 'index.html'
},
open: false,
notify: false
});
watch('src/assets/icons/*.svg', fontIcon);
watch('src/sass/**/*.{scss, sass}', compileSass);
watch('src/*.html').on('change', browserSync.reload);
};
exports.build = series(removeDist,
parallel(series(compileSass, buildCSS), buildImages, buildHtml, buildJS, buildFonts)
);
exports.zip = series(removeZip, getZip);
task(removeDist);
task(clear);
task(fontIcon);
task(fonts);
task(favicon);
task(checkFaviconUpdate);