-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
52 lines (47 loc) · 1.33 KB
/
esbuild.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
const esbuild = require('esbuild')
const copyStaticFiles = require('esbuild-copy-static-files')
const fs = require('fs')
const path = require('path')
const appendUIStyles = (options) => ({
name: 'append-ui-styles',
setup(build) {
build.onEnd(() =>
fs.readFile('widget-src/ui/css/ui.css', 'utf8', (err, css) => {
if (err) throw err
fs.readdir(options.src, (err, files) => {
if (err) throw err
const htmlFiles = files.filter((el) => path.extname(el) === '.html')
htmlFiles.forEach((html) => {
fs.appendFile(`${options.src}/${html}`, `\n\n<style>\n${css}\n</style>`, (err) => {
if (err) throw err
})
})
console.log('Build - Done', `${process.hrtime()[1] / 100000000}ms`)
})
})
)
}
})
esbuild
.build({
entryPoints: [`widget-src/code.tsx`],
assetNames: 'assets/[name]',
bundle: true,
minify: true,
watch: process.env.npm_lifecycle_event ? true : false,
outfile: `dist/code.js`,
plugins: [
copyStaticFiles({
src: `widget-src/ui/html`,
dest: `dist/`,
dereference: true,
errorOnExist: false,
preserveTimestamps: true,
recursive: true,
}),
appendUIStyles({
src: `dist/`
})
]
})
.catch(() => process.exit(1))