-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
139 lines (129 loc) · 4.15 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
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');
const flatten = require('gulp-flatten');
const data = require('gulp-data');
const content = require('./src/content.json');
function browserSync() {
bs.init({
server: {
baseDir: 'build',
},
notify: false
});
}
function layout() {
return src(['src/index.pug', 'src/placeholder.pug'])
.pipe(data(() => content))
.pipe(pug())
.pipe(dest('build'))
.pipe(bs.stream())
}
function styles() {
// noinspection JSCheckFunctionSignatures
return src('src/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('build'))
.pipe(bs.stream())
}
function scripts() {
return src(['node_modules/select2/dist/js/select2.min.js',
'src/blocks/**/*.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('scripts.min.js'))
.pipe(sourcemaps.write())
.pipe(dest('build'))
.pipe(bs.stream())
}
function images() {
return src('src/**/img/*')
.pipe(changed('build/img'))
.pipe(imagemin([
imagemin.svgo({
// plugins disabled to prevent svgo from empty svg sprite
plugins: [
{
cleanupIDs: false,
removeUselessDefs: false
}
]
})
]))
.pipe(flatten({subPath: [1, 0]}))
.pipe(dest('build/img'))
.pipe(bs.stream());
}
function assets() {
return src('src/favicon/*')
.pipe(dest('build'));
}
function watcher() {
watch("src/**/*.scss", {usePolling: true}, styles);
watch("src/**/*.js", {usePolling: true}, scripts);
watch("src/img/*", {usePolling: true}, images);
watch("src/**/*.pug", {usePolling: true}, layout).on('change', bs.reload);
}
exports.layout = layout;
exports.styles = styles;
exports.scripts = scripts;
exports.images = images;
exports.build = parallel(layout, styles, scripts, images, assets);
exports.browserSync = browserSync;
exports.watcher = watcher;
exports.default = series(parallel(layout, styles, scripts, images, assets), parallel(browserSync, watcher));