-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.mjs
240 lines (219 loc) · 7.34 KB
/
gulpfile.mjs
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
238
239
240
import browserSync from 'browser-sync';
import chalk from 'chalk';
import {deleteAsync} from 'del';
import gulp from 'gulp';
import prefixer from 'gulp-autoprefixer';
import minifyCss from 'gulp-clean-css';
import concat from 'gulp-concat';
import eslint from 'gulp-eslint';
import favicons from 'gulp-favicons';
import gulpIf from 'gulp-if';
import imagemin, {gifsicle, mozjpeg, optipng, svgo} from 'gulp-imagemin';
import * as dartSass from 'sass';
import gulpSass from 'gulp-sass';
import sassLint from 'gulp-sass-lint';
import sourcemaps from 'gulp-sourcemaps';
import uglify from 'gulp-uglify-es';
import config from './src/app/gulpfile-config.js';
import isEnv from './src/app/is-env.js';
import lintFunc from './src/app/lint.js';
const sass = gulpSass(dartSass);
const browserSyncInstance = browserSync.create();
// initialize BrowserSync
export function browserSyncInit(done) {
browserSyncInstance.init(config[config.browserSyncConfig]);
done();
}
// reload browser
function browserSyncReload(done) {
browserSyncInstance.reload();
done();
}
// clean up folders
export function cleanUp() {
// deleteAsync([
// config.systemPath + 'css/styles.*',
// config.systemPath + 'font/**/*',
// config.systemPath + 'img/**/*',
// config.systemPath + 'js/scripts.*',
// config.systemPath + 'svg/**/*'
// ], {force: true});
return deleteAsync([
config.publicPath + 'css/styles.*',
config.publicPath + 'font/**/*',
config.publicPath + 'img/**/*',
config.publicPath + 'js/scripts.*',
config.publicPath + 'svg/**/*'
]);
}
// generate favicons
export function favicon() {
return gulp.src('./src/img/favicon.png')
.pipe(favicons({
appName: 'Gulp Skeleton',
appShortName: 'Gulp Skeleton',
appDescription: 'Skeleton to create templates with Gulp',
developerName: 'CodelineRed',
developerURL: 'https://www.codelinered.net/',
background: '#000',
theme_color: '#000',
lang: "en-US",
path: '/img/favicons/',
url: 'https://gulp.codelinered.net/',
display: 'standalone',
orientation: 'portrait',
scope: '/',
start_url: '/',
version: 1.0,
logging: false,
html: 'index.html',
pipeHTML: true,
replace: true
}))
// .pipe(gulp.dest(config.systemPath + 'img/favicons/'))
.pipe(gulp.dest(config.publicPath + 'img/favicons/'));
}
// copy font files
export function font() {
return gulp.src([
// 'node_modules/@fortawesome/fontawesome-free/webfonts/**',
'node_modules/slick-carousel/slick/fonts/**',
config.sourcePath + 'font/**'
])
// .pipe(gulp.dest(config.systemPath + 'font/'))
.pipe(gulp.dest(config.publicPath + 'font/'));
}
// compress images
export function img() {
return gulp.src(config.sourcePath + 'img/**/*.{png,gif,jpg,jpeg,ico,xml,json,svg}')
.pipe(imagemin([
gifsicle({
interlaced: true
}),
mozjpeg({
progressive: true
}),
optipng({
optimizationLevel: 5
}),
svgo({
plugins: [
{
name: 'removeViewBox',
active: true
},
{
name: 'cleanupIDs',
active: false
}
]
})
]))
// .pipe(gulp.dest(config.systemPath + 'img/'))
.pipe(gulp.dest(config.publicPath + 'img/'));
}
// concatinate and uglify js files
export function js() {
return gulp.src([
'node_modules/jquery/dist/jquery.js',
'node_modules/bootstrap/dist/js/bootstrap.bundle.js',
'node_modules/@fortawesome/fontawesome-free/js/all.js',
config.sourcePath + 'js/lib/**/*.js',
'node_modules/slick-carousel/slick/slick.min.js',
'node_modules/cssuseragent/cssua.js',
'node_modules/vanilla-lazyload/dist/lazyload.js',
'node_modules/cookieconsent/src/cookieconsent.js',
'node_modules/@fancyapps/ui/dist/fancybox/fancybox.umd.js',
'node_modules/@fancyapps/ui/dist/fancybox/l10n/de.umd.js',
'node_modules/@fancyapps/ui/dist/fancybox/l10n/en.umd.js',
config.sourcePath + 'js/plugin/**/*.js',
config.sourcePath + 'js/module/**/*.js',
config.sourcePath + 'js/scripts.js'
])
.pipe(sourcemaps.init())
.pipe(concat('scripts.js'))
.pipe(gulpIf(isEnv(['test', 'prod'], config.env), uglify.default()))
.pipe(sourcemaps.write('./'))
// .pipe(gulp.dest(config.systemPath + 'js/'))
.pipe(gulp.dest(config.publicPath + 'js/'));
}
// lint js files
export function jsLint() {
return lintFunc(gulp, eslint, [config.sourcePath + 'js/**/*.js'], 'js');
}
// processing scss to css and minify result
export function scss() {
return gulp.src(config.sourcePath + 'scss/styles.scss')
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(prefixer({
overrideBrowserslist: ['last 2 versions'],
cascade: false
}))
.pipe(gulpIf(isEnv(['test', 'prod'], config.env), minifyCss({compatibility: 'ie8'})))
.pipe(sourcemaps.write('./'))
// .pipe(gulp.dest(config.systemPath + 'css/'))
.pipe(gulp.dest(config.publicPath + 'css/'));
}
// lint scss files
export function scssLint() {
return lintFunc(gulp, sassLint, [config.sourcePath + 'scss/**/*.scss'], 'scss');
}
// compress and copy svg files
export function svg() {
return gulp.src([
// 'node_modules/@fortawesome/fontawesome-free/svgs/**',
// 'node_modules/@fortawesome/fontawesome-free/sprites/**',
config.sourcePath + 'svg/**/*.svg'
])
.pipe(imagemin([
svgo({
plugins: [
{
name: 'removeViewBox',
active: true
},
{
name: 'cleanupIDs',
active: false
}
]
})
]))
// .pipe(gulp.dest(config.systemPath + 'svg/'))
.pipe(gulp.dest(config.publicPath + 'svg/'));
}
// thank you
export function thankYou() {
return new Promise(function(resolve, reject) {
console.log(chalk.redBright(' ♥ ') + chalk.bold('Thank you for using Gulp Skeleton 7!') + chalk.redBright(' ♥ '));
resolve();
});
}
// watch files
export function watch() {
// watch fonts
gulp.watch(config.sourcePath + 'font/**', font);
// watch images
gulp.watch(config.sourcePath + 'img/**', img);
// watch favicon
gulp.watch(config.sourcePath + 'img/favicon.png', favicon);
// watch js files
gulp.watch(config.sourcePath + 'js/**', gulp.series(js, jsLint));
// watch scss files
gulp.watch(config.sourcePath + 'scss/**', gulp.series(scss, scssLint));
// watch svg
gulp.watch(config.sourcePath + 'svg/**', svg);
}
// watch files and reload browser on file change
function watchAndReload() {
watch();
gulp.watch(config.publicPath + '**/*.{css,eot,ico,js,jpg,otf,png,svg,ttf,woff,woff2}', browserSyncReload);
gulp.watch('template/**/*.{php,html,phtml}', browserSyncReload);
}
// gulp
export default gulp.parallel(watchAndReload, browserSyncInit);
// gulp build
export const build = gulp.series(thankYou, cleanUp, favicon, font, img, js, jsLint, scss, scssLint, svg);
// gulp lint
export const lint = gulp.series(jsLint, scssLint);