forked from logseq/logseq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
76 lines (65 loc) · 2.22 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
const fs = require('fs')
const path = require('path')
const gulp = require('gulp')
const postcss = require('gulp-postcss')
const concat = require('gulp-concat')
const cached = require('gulp-cached')
const remember = require('gulp-remember')
const cleanCSS = require('gulp-clean-css')
const del = require('del')
const outputPath = path.join(__dirname, 'static')
const resourcesPath = path.join(__dirname, 'resources')
const sourcePath = path.join(__dirname, 'src/main/frontend')
const resourceFilePath = path.join(resourcesPath, '**')
const tailwind = {
paths: [path.join(__dirname, 'tailwind.css'), path.join(sourcePath, '**/*.css')],
outputDir: path.join(outputPath, 'css'),
outputName: 'tailwind.build.css',
}
const css = {
async watchCSS () {
// remove tailwind core css
await new Promise((resolve) => {
css._buildTailwind(
tailwind.paths.shift(),
'tailwind.core.css'
)
.on('end', resolve)
})
return gulp.watch(
tailwind.paths, { ignoreInitial: false },
css._buildTailwind.bind(null, void 0, void 0))
},
buildCSS (...params) {
return gulp.series(css._buildTailwind.bind(null, void 0, void 0), css._optimizeCSSForRelease)(...params)
},
_buildTailwind (entry, output) {
return gulp.src(entry || tailwind.paths)
.pipe(cached('postcss-' + entry))
.pipe(postcss())
.pipe(remember('postcss-' + entry))
.pipe(concat(output || tailwind.outputName))
.pipe(gulp.dest(tailwind.outputDir))
},
_optimizeCSSForRelease () {
// tailwind.core.css placeholder
fs.writeFileSync(path.join(outputPath, 'css', 'tailwind.core.css'), '')
return gulp.src(path.join(outputPath, 'css', 'style.css'))
.pipe(cleanCSS())
.pipe(gulp.dest(path.join(outputPath, 'css')))
},
}
const common = {
clean () {
return del(outputPath)
},
syncResourceFile () {
return gulp.src(resourceFilePath).pipe(gulp.dest(outputPath))
},
keepSyncResourceFile () {
return gulp.watch(resourceFilePath, { ignoreInitial: false }, common.syncResourceFile)
}
}
exports.clean = common.clean
exports.watch = gulp.parallel(common.keepSyncResourceFile, css.watchCSS)
exports.build = gulp.series(common.clean, common.syncResourceFile, css.buildCSS)