forked from openai-translator/openai-translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-tauri.mjs
68 lines (61 loc) · 1.51 KB
/
build-tauri.mjs
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
import esbuild from 'esbuild'
import { copy } from 'esbuild-plugin-copy'
import fs from 'fs-extra'
import esbuildServer from 'esbuild-server'
const tauriOutDir = 'dist/tauri'
// eslint-disable-next-line no-undef
const enableWatch = process.argv.includes('--watch')
// eslint-disable-next-line no-undef
const enableServe = process.argv.includes('--serve')
const config = {
entryPoints: ['src/tauri/index.tsx'],
bundle: true,
outdir: tauriOutDir,
watch: enableWatch,
treeShaking: true,
minify: true,
legalComments: 'none',
sourcemap: true,
loader: {
'.png': 'dataurl',
'.jpg': 'dataurl',
'.gif': 'dataurl',
},
plugins: [
copy({
resolveFrom: 'cwd',
assets: [
{
from: 'src/tauri/index.html',
to: `${tauriOutDir}/index.html`,
},
{
from: 'src-tauri/get-selected-text.applescript',
to: `${tauriOutDir}/get-selected-text.applescript`,
},
],
watch: enableWatch,
}),
],
}
async function esbuildTauri() {
await fs.remove(tauriOutDir)
await esbuild.build(config)
}
async function build() {
await esbuildTauri()
}
async function serve() {
await fs.remove(tauriOutDir)
esbuildServer
.createServer(config, {
static: tauriOutDir,
port: 3000,
})
.start()
}
if (enableServe) {
serve()
} else {
build()
}