-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.prod.js
45 lines (43 loc) · 1.14 KB
/
esbuild.prod.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
import { build } from 'esbuild'
import { existsAsync } from 'fs'
import { readFile, writeFile } from 'fs/promises'
import { join } from 'path'
await build({
entryPoints: ['src/index.ts'],
outdir: 'dist',
format: 'esm',
bundle: true,
minify: true,
loader: {
'.aac': 'file',
'.eot': 'file',
'.flac': 'file',
'.gif': 'file',
'.jpeg': 'file',
'.jpg': 'file',
'.mp3': 'file',
'.mp4': 'file',
'.ogg': 'file',
'.otf': 'file',
'.png': 'file',
'.svg': 'file',
'.ttf': 'file',
'.wav': 'file',
'.webm': 'file',
'.webp': 'file',
'.woff': 'file',
'.woff2': 'file',
},
define: {
'process.env.ENV': '"production"',
'process.env.PROD': 'true',
'process.env.DEV': 'false'
}
})
// Insert import "./index.css" at the start of index.js
if (existsAsync(join('dist', 'index.css'))) {
const indexJsPath = join('dist', 'index.js')
const indexJs = (await readFile(indexJsPath, 'utf-8'))
.replace(/^/, 'import "./index.css";');
await writeFile(indexJsPath, indexJs)
}