forked from galacticcouncil/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.prod.mjs
executable file
·63 lines (55 loc) · 1.54 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import esbuild from 'esbuild';
import { fixTalismanEsm } from './talisman.mjs';
import { readFileSync, readdirSync } from 'fs';
import { resolve, dirname } 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 = dirname(__filename);
const indexTemplate = readFileSync(resolve(__dirname, 'index.html'), 'utf8');
const packageJson = JSON.parse(readFileSync(resolve(__dirname, 'package.json'), 'utf-8'));
const polkadotDeps = [];
readdirSync('node_modules/@polkadot').forEach((pckg) => {
polkadotDeps.push('@polkadot/' + pckg);
});
const indexDOM = parse(indexTemplate);
const script = indexDOM.getElementsByTagName('script')[0];
script.remove();
fixTalismanEsm();
const common = {
preserveSymlinks: true,
treeShaking: true,
minify: true,
bundle: true,
format: 'esm',
platform: 'browser',
target: 'esnext',
};
// Website bundle
esbuild.build({
...common,
metafile: true,
entryPoints: ['src/app.ts'],
entryNames: 'bundle-[hash]',
outdir: 'dist/',
plugins: [
htmlPlugin({
files: [
{
entryPoints: ['src/app.ts'],
filename: 'index.html',
scriptLoading: 'module',
htmlTemplate: indexDOM.toString(),
},
],
}),
],
});
// Library bundle
esbuild.build({
...common,
entryPoints: ['src/index.ts'],
outfile: 'dist/index.esm.js',
external: Object.keys(packageJson.peerDependencies).concat(polkadotDeps),
});