forked from galacticcouncil/api-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.prod.mjs
executable file
·47 lines (43 loc) · 1.18 KB
/
esbuild.prod.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
import esbuild from 'esbuild';
import fs from 'fs';
import path from 'path';
import {fileURLToPath} from 'url';
import {htmlPlugin} from '@craftamap/esbuild-plugin-html';
import {parse} from 'node-html-parser';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const indexTemplate = fs.readFileSync(
path.resolve(__dirname, 'index.html'),
'utf8'
);
const indexDOM = parse(indexTemplate);
const baseNode = indexDOM.getElementsByTagName('base')[0];
const newBaseNode = baseNode.setAttribute('href', process.env.BASE_HREF || '/');
const script = indexDOM.getElementsByTagName('script')[0];
indexDOM.exchangeChild(baseNode, newBaseNode);
script.remove();
esbuild.build({
entryPoints: ['src/index.ts'],
entryNames: 'bundle-[hash]',
bundle: true,
format: 'esm',
platform: 'browser',
target: 'es2021',
preserveSymlinks: true,
treeShaking: true,
metafile: true,
minify: true,
outdir: 'dist/',
plugins: [
htmlPlugin({
files: [
{
entryPoints: ['src/index.ts'],
filename: 'index.html',
scriptLoading: 'module',
htmlTemplate: indexDOM.toString(),
},
],
}),
],
});