-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
133 lines (123 loc) · 3.91 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
const {src, dest, watch, parallel, series} = require('gulp');
const pug = require('gulp-pug');
const sass = require('gulp-sass')(require('sass'));
const postCSS = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');
const bs = require('browser-sync').create();
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const concat = require('gulp-concat');
const TerserPlugin = require('terser-webpack-plugin');
const imagemin = require('gulp-imagemin');
// const changed = require('gulp-changed');
const sourcemaps = require('gulp-sourcemaps');
function browserSync() {
bs.init({
server: {
baseDir: 'docs',
},
notify: false
});
}
function layout() {
return src('source/index.pug')
.pipe(pug())
.pipe(dest('docs'))
.pipe(bs.stream())
}
function styles() {
// noinspection JSCheckFunctionSignatures
return src('source/main.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(postCSS([
autoprefixer({grid: 'autoplace'}),
cssnano({
preset: [
'default',
{
discardComments: {removeAll: true}
}
]
})
]))
.pipe(sourcemaps.write())
.pipe(dest('docs'))
.pipe(bs.stream())
}
function scripts() {
return src('source/script.js')
.pipe(sourcemaps.init())
.pipe(webpackStream({
mode: 'production',
performance: {hints: false},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /('node_modules')/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['babel-plugin-root-import']
}
}
}
]
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false
}
},
extractComments: false
})
]
}
}, webpack).on('error', () => this.emit('end')))
.pipe(concat('script.min.js'))
.pipe(sourcemaps.write())
.pipe(dest('docs'))
.pipe(bs.stream())
}
function images() {
return src('source/images/*')
// .pipe(changed('source/images'))
.pipe(imagemin([
imagemin.svgo({
// plugins disabled to prevent svgo from empty svg sprite
plugins: [
{
cleanupIDs: false,
removeUselessDefs: false
}
]
})
]))
.pipe(dest('docs/images'))
.pipe(bs.stream());
}
function watcher() {
watch("source/index.pug", {usePolling: true}, layout).on('change', bs.reload);
watch("source/main.scss", {usePolling: true}, styles);
watch("source/script.js", {usePolling: true}, scripts);
watch("source/images/*", {usePolling: true}, images);
}
function moveAssets() {
return src('source/favicon/*')
.pipe(dest('docs'));
}
exports.layout = layout;
exports.styles = styles;
exports.scripts = scripts;
exports.images = images;
exports.build = parallel(layout, styles, scripts, images, moveAssets);
exports.browserSync = browserSync;
exports.watcher = watcher;
exports.default = series(parallel(layout, styles, scripts, images), parallel(browserSync, watcher));