-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathesbuild.mjs
94 lines (84 loc) · 2.65 KB
/
esbuild.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import tailwindcss from '@tailwindcss/postcss'
import { config } from 'dotenv'
import esbuild from 'esbuild'
import postCssPlugin from 'esbuild-style-plugin'
import stdLibBrowser from 'node-stdlib-browser'
import plugin from 'node-stdlib-browser/helpers/esbuild/plugin'
import replace from 'postcss-replace'
import { fileURLToPath } from 'url'
config()
const SERVE_PORT = 3999
esbuild
.context({
entryPoints: [
'./src/background/index.ts',
// INJECT EIP-1193 PROVIDER TO DAPPS TO RECORD TRANSACTIONS
'./src/inject/contentScript/main.ts',
'./src/inject/injectedScript/main.ts',
// MONITOR TAB CONNECTION STATUS AND SHOW RELOAD NOTIFICATION
'./src/monitor/contentScript/main.ts',
'./src/monitor/injectedScript/main.ts',
// COMPANION APP TO EDIT ROUTES
'./src/companion/contentScripts/main.ts',
'./src/companion/injectedScripts/main.ts',
// SIDEPANEL APP
'./src/panel/app.tsx',
],
bundle: true,
/** IMPORTANT: For scripts that are injected into other apps, it's crucial we build to IIFE format to avoid global scope clashes. */
format: 'iife',
treeShaking: true,
minify: process.env.NODE_ENV !== 'development',
sourcemap: process.env.NODE_ENV === 'development' ? 'inline' : true,
loader: {
'.svg': 'file',
'.woff': 'file',
'.woff2': 'file',
'.png': 'file',
'.html': 'text',
},
target: ['chrome96'],
outdir: './public/build',
publicPath: '/build',
inject: [
fileURLToPath(
import.meta.resolve('node-stdlib-browser/helpers/esbuild/shim'),
),
],
define: {
'process.env.LIVE_RELOAD':
process.env.NODE_ENV === 'development'
? `"http://127.0.0.1:${SERVE_PORT}/esbuild"`
: 'false',
global: 'window',
'process.env.COMPANION_APP_URL': `"${process.env.COMPANION_APP_URL}"`,
},
plugins: [
plugin(stdLibBrowser),
postCssPlugin({
postcss: {
plugins: [
tailwindcss,
replace({ pattern: /:root/, data: { replaceAll: ':root, :host' } }),
],
},
}),
// process.env.NODE_ENV !== 'development' &&
// sentryEsbuildPlugin({
// authToken: process.env.SENTRY_AUTH_TOKEN,
// org: 'gnosis-guild',
// project: 'pilot-extension',
// }),
].filter(Boolean),
logLevel: 'info',
})
.then(async (ctx) => {
if (process.env.NODE_ENV === 'development') {
await ctx.serve({ port: SERVE_PORT, servedir: './public' })
await ctx.watch()
} else {
await ctx.rebuild()
console.log('Build successful.')
ctx.dispose()
}
})