-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
84 lines (67 loc) · 2.18 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
const gulp = require('gulp')
const multiDest = require('gulp-multi-dest')
const rename = require('gulp-rename')
const webpack = require('webpack')
const webpackStream = require('webpack-stream')
const postCss = require('gulp-postcss')
const sass = require('gulp-sass')(require('sass'))
const del = require('del')
const tailwindCss = require('tailwindcss')
const csso = require('postcss-csso')
const isProduction = process.env.NODE_ENV === 'production'
const commonDest = () => multiDest(['extensions/chrome', 'extensions/firefox'])
const clean = () => del('extensions/*/**')
const copyIcon = () => gulp.src('source/icon.png').pipe(commonDest())
const compileJs = () =>
webpackStream(require('./webpack.config.js'), webpack).pipe(commonDest())
const compilePopupCss = () =>
gulp
.src('source/popup/popup.css')
.pipe(
postCss([
tailwindCss(),
...(isProduction ? [csso({ comments: false })] : []),
]),
)
.pipe(commonDest())
const compileContentCss = () =>
gulp
.src('source/content.scss')
.pipe(sass({ outputStyle: 'compressed' }).on('error', sass.logError))
.pipe(commonDest())
const copyChromeHtml = () =>
gulp
.src('source/popup/popup.chrome.html')
.pipe(rename('popup.html'))
.pipe(gulp.dest('extensions/chrome'))
const copyFirefoxHtml = () =>
gulp
.src('source/popup/popup.firefox.html')
.pipe(rename('popup.html'))
.pipe(gulp.dest('extensions/firefox'))
const generateManifests = require('./scripts/generate-manifests')
const build = gulp.series(
clean,
gulp.parallel(
copyIcon,
compileJs,
compilePopupCss,
compileContentCss,
copyFirefoxHtml,
copyChromeHtml,
generateManifests,
),
)
const watch = () => {
gulp.watch('source/**/*.scss', compileContentCss)
gulp.watch(['source/popup/popup.css', 'tailwind.config.js'], compilePopupCss)
gulp.watch('source/**/*.(ts|vue)', compileJs)
gulp.watch('source/manifest.js', generateManifests)
}
const dev = gulp.series(build, watch)
module.exports = { build, dev }
// Necessary in order to see errors from webpack
process.on('unhandledRejection', (_, promise) => {
console.log('Unhandled promise rejection:', promise)
process.exit(1)
})