-
Notifications
You must be signed in to change notification settings - Fork 65
/
Copy pathgulpfile.js
123 lines (104 loc) · 2.74 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
const path = require('path')
const fs = require('fs')
const gulp = require('gulp')
const git = require('gulp-git')
const shell = require('gulp-shell')
const postcss = require('gulp-postcss')
const csso = require('postcss-csso')
const pimport = require('postcss-import')
const minmax = require('postcss-media-minmax')
const autoprefixer = require('autoprefixer')
const esbuild = require('gulp-esbuild')
const del = require('del')
const rev = require('gulp-rev')
const revRewrite = require('gulp-rev-rewrite')
const { contentRepGithub, contentRepFolders } = require(path.join(__dirname, 'config/constants'))
const cloneContent = () => git.clone(contentRepGithub)
const makeLinks = shell.task(`node make-links.js --default`, {
env: {
PATH_TO_CONTENT: path.join(__dirname, 'content'),
PATH: process.env.PATH,
},
})
// Styles
const styles = () => {
return gulp
.src('src/styles/{index.css,index.sc.css,dark-theme.css}')
.pipe(
postcss([
pimport,
minmax,
autoprefixer,
csso({
restructure: false,
}),
]),
)
.pipe(gulp.dest('dist/styles'))
}
// Scripts
const sw = () => {
return gulp
.src('src/sw.js')
.pipe(
esbuild({
target: 'es2015',
minify: true,
}),
)
.pipe(gulp.dest('dist/'))
}
const scripts = () => {
return gulp
.src('src/scripts/index.js')
.pipe(
esbuild({
target: 'es2015',
bundle: true,
minify: true,
plugins: [
{
name: 'node-modules-resolution',
setup(build) {
build.onResolve({ filter: /^\// }, (args) => {
const cwd = process.cwd()
const newPath = args.path.includes(cwd) ? args.path : path.join(cwd, 'node_modules', args.path)
return {
path: newPath,
}
})
},
},
],
}),
)
.pipe(gulp.dest('dist/scripts'))
}
// Clean
const clean = () => {
return del(['dist/styles', 'dist/scripts', 'dist/sw.js'])
}
// Cache
const cacheHash = () => {
return gulp
.src('dist/**/*.{css,js}')
.pipe(rev())
.pipe(gulp.dest('dist'))
.pipe(rev.manifest('rev-manifset.json'))
.pipe(gulp.dest('dist'))
}
const cacheReplace = () => {
return gulp
.src('dist/**/*.{html,css,svg}')
.pipe(
revRewrite({
manifest: fs.readFileSync('dist/rev-manifset.json'),
}),
)
.pipe(gulp.dest('dist'))
}
const cache = gulp.series(cacheHash, cacheReplace)
exports.setupContent = gulp.series(cloneContent, makeLinks)
exports.dropContent = () => del(['content', ...contentRepFolders.map((folder) => `src/${folder}`)])
// Default
exports.default = gulp.series(clean, styles, scripts, sw, cache)