-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
executable file
·71 lines (60 loc) · 1.81 KB
/
build.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
#!/usr/bin/env node
import * as esbuild from 'esbuild'
import * as fs from 'fs'
import * as path from 'path'
import * as sass from 'sass'
import * as chokidar from 'chokidar'
const prod = process.argv.indexOf('prod') !== -1
const watch = process.argv.indexOf('watch') !== -1
function buildSass() {
const sassEntryFile = './src/assets/css/style.scss'; // Your main Sass file
const cssOutputFile = './dist/assets/css/style.build.css'; // Output CSS file
const result = sass.renderSync({
file: sassEntryFile,
outFile: cssOutputFile,
sourceMap: true,
outputStyle: 'compressed',
})
fs.mkdirSync(path.dirname(cssOutputFile), { recursive: true })
fs.writeFileSync(cssOutputFile, result.css)
if (result.map) {
fs.writeFileSync(`${cssOutputFile}.map`, result.map)
}
console.log('Sass compiled successfully')
}
// Build Sass initially
buildSass()
function buildEsbuild() {
esbuild
.build({
bundle: true,
entryPoints: {
'popup.build': './src/popup.jsx',
'prompt.build': './src/prompt.jsx',
'options.build': './src/options.jsx',
'background.build': './src/background.jsx',
'content-script.build': './src/content-script.jsx'
},
outdir: './dist',
sourcemap: prod ? false : 'inline',
define: {
window: 'self',
global: 'self'
}
})
.then(() => console.log('Build success.'))
}
// Build esbuild and watch for changes
buildEsbuild()
if (watch) {
// Watch for changes in Sass files
chokidar.watch('./src/**/*.{jsx,jsx}').on('change', (event) => {
console.log(`File ${event} has been changed`)
buildEsbuild()
});
// Watch for changes in Sass files
chokidar.watch('./src/assets/css/*.scss').on('change', (event) => {
console.log(`File ${event} has been changed`)
buildSass()
});
}