-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
182 lines (153 loc) · 4.34 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
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
const gulp = require(`gulp`);
// JS concat and compile
const webpack = require(`webpack`);
const webpackStream = require(`webpack-stream`);
const webpackConfig = require(`./webpack.config.js`);
const uglifyjs = require(`gulp-uglify`);
// CSS concat and compile
const postcss = require(`gulp-postcss`);
const postcssPresetEnv = require(`postcss-preset-env`);
const cssimport = require(`postcss-import`);
const postcssOKLabFunction = require('@csstools/postcss-oklab-function');
const postcssCascadeLayers = require('@csstools/postcss-cascade-layers');
const postcssLogical = require('postcss-logical');
const cssnano = require(`cssnano`);
const csso = require('gulp-csso');
// Notificaiton friendly errors
const notify = require(`gulp-plumber-notifier`);
// Browser syc
const browsersync = require(`browser-sync`);
// SITE VARIABLES BELOW
const domain = ``;
const webroot = `./public_html`;
const scriptEntryPoint = `${webroot}/ui/_js/main.js`;
const stylesEntryPoint = `${webroot}/ui/_css/main.css`;
const scriptDestPoint = `${webroot}/ui/js/`;
const stylesDestPoint = `${webroot}/ui/css/`;
// Add more sources in these arrays
const scriptSources = [`${webroot}/ui/_js/**/*.js`];
const styleSources = [`${webroot}/ui/_css/**/*.css`];
const imageSources = [`${webroot}/ui/images/*`];
const templateSources = [`${webroot}/*.html`, `${webroot}/**/*.html`, `${webroot}/*.twig`, `${webroot}/**/*.twig`, `${webroot}/*.php`, `${webroot}/**/*.php`];
gulp.task(`scripts`, gulp.series((done) => {
console.log(`Scripts Run`);
gulp.src(scriptEntryPoint)
.pipe(notify())
.pipe(webpackStream(webpackConfig), webpack)
.pipe(gulp.dest(scriptDestPoint))
.pipe(browsersync.reload({
stream: true,
}));
done();
}));
gulp.task(`scriptsBuild`, gulp.series((done) => {
console.log(`Scripts Build`);
gulp.src(scriptEntryPoint)
.pipe(notify())
.pipe(webpackStream(webpackConfig), webpack)
.pipe(uglifyjs())
.pipe(gulp.dest(scriptDestPoint));
done();
}));
gulp.task(`styles`, gulp.series((done) => {
console.log(`Styles Run`);
const processors = [
postcssOKLabFunction({
preserve: true,
enableProgressiveCustomProperties: true,
}),
cssimport(),
postcssCascadeLayers(),
postcssLogical(),
postcssPresetEnv({
stage: 0,
features: {
'nesting-rules': true,
},
browsers: [`IE 8`],
}),
];
gulp.src(stylesEntryPoint)
.pipe(notify())
.pipe(postcss(processors))
.pipe(csso())
.pipe(gulp.dest(stylesDestPoint))
.pipe(browsersync.reload({
stream: true,
}));
done();
}));
gulp.task(`stylesBuild`, gulp.series((done) => {
console.log(`Styles Build`);
const processors = [
postcssOKLabFunction({
preserve: true,
enableProgressiveCustomProperties: true,
}),
cssimport(),
postcssCascadeLayers(),
postcssLogical(),
postcssPresetEnv({
stage: 0,
features: {
'nesting-rules': true,
},
browsers: [`IE 8`],
}),
cssnano({
autoprefixer: {
grid: true
}
}),
];
gulp.src(stylesEntryPoint)
.pipe(notify())
.pipe(postcss(processors))
.pipe(csso())
.pipe(gulp.dest(stylesDestPoint));
done();
}));
gulp.task(`imagemin`, gulp.series((done) => {
console.log(`Image Compression`);
gulp.src(imageSources)
.pipe(imagemin());
// .pipe(gulp.dest(`${webroot}`));
done();
}));
gulp.task(`html`, gulp.series((done) => {
console.log(`Template Reload`);
gulp.src(templateSources)
.pipe(browsersync.reload({
stream: true,
}));
done();
}));
gulp.task(`sync`, gulp.series((done) => {
if (domain === ``) {
browsersync.init({
server: {
baseDir: webroot,
// https: true,
},
});
} else {
browsersync.init({
proxy: domain,
// https: true,
});
}
done();
}));
gulp.task(`watch`, gulp.series((done) => {
console.log(`Watchinig Scripts`);
gulp.watch(scriptSources, gulp.series([`scripts`]));
console.log(`Watchinig Styles`);
gulp.watch(styleSources, gulp.series([`styles`]));
// gulp.watch(`${stylesDestPoint}main.css`, gulp.series([`critical`]));
console.log(`Watchinig Templates`);
gulp.watch(templateSources, gulp.series([`html`]));
done();
}));
gulp.task(`default`, gulp.series([`sync`, `scripts`, `styles`, `watch`]));
gulp.task(`build`, gulp.series([`scriptsBuild`, `stylesBuild`]));
// EOF