forked from openai-translator/openai-translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-tauri.mjs
79 lines (72 loc) · 1.93 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
69
70
71
72
73
74
75
76
77
78
79
import esbuild from 'esbuild'
import { copy } from 'esbuild-plugin-copy'
import fs from 'fs-extra'
import esbuildServer from 'esbuild-server'
import inlineImportPlugin from 'esbuild-plugin-inline-import'
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', 'src/tauri/thumb.tsx'],
target: ['es2015', 'safari11'],
bundle: true,
outdir: tauriOutDir,
watch: enableWatch,
treeShaking: true,
minify: true,
legalComments: 'none',
sourcemap: true,
loader: {
'.png': 'dataurl',
'.jpg': 'dataurl',
'.gif': 'dataurl',
},
plugins: [
inlineImportPlugin(),
copy({
resolveFrom: 'cwd',
assets: [
{
from: 'public/cld-min.js',
to: `${tauriOutDir}/cld-min.js`,
},
{
from: 'src/tauri/index.html',
to: `${tauriOutDir}/index.html`,
},
{
from: 'src/tauri/thumb.html',
to: `${tauriOutDir}/thumb.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()
}