-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
63 lines (52 loc) · 1.51 KB
/
gulpfile.js
File metadata and controls
63 lines (52 loc) · 1.51 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
const fs = require('fs')
const gulp = require('gulp')
const rename = require('gulp-rename')
const postcss = require('gulp-postcss')
const htmlmin = require('gulp-htmlmin')
const inlineSource = require('gulp-inline-source')
function generateVersion() {
return 'v' + Date.now()
}
function updateServiceWorkerVersion(cb) {
const swPath = 'web/sw.js'
const newVersion = generateVersion()
console.log(`🔄 Updating Service Worker version to: ${newVersion}`)
try {
let swContent = fs.readFileSync(swPath, 'utf8')
swContent = swContent.replace(
/const CACHE_VERSION = "[^"]+"/,
`const CACHE_VERSION = "${newVersion}"`
)
fs.writeFileSync(swPath, swContent)
console.log(`✅ Service Worker version updated successfully!`)
cb()
} catch (error) {
console.error('❌ Error updating Service Worker version:', error)
cb(error)
}
}
function buildCSS() {
return gulp.src('web/assets/css/styles.css')
.pipe(postcss([
require('tailwindcss'),
require('autoprefixer')
]))
.pipe(rename('tailwind.css'))
.pipe(gulp.dest('web/assets/css'))
}
function minify() {
return gulp.src('web/index.html')
.pipe(inlineSource({
compress: true
}))
.pipe(htmlmin({
minifyJS: true,
minifyCSS: true,
removeComments: true,
collapseWhitespace: true
}))
.pipe(rename('index.min.html'))
.pipe(gulp.dest('web'))
}
const tasks = gulp.series(updateServiceWorkerVersion, buildCSS, minify)
module.exports = { tasks }