-
Notifications
You must be signed in to change notification settings - Fork 7
/
build-api.cjs
50 lines (48 loc) · 1.4 KB
/
build-api.cjs
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
const esbuild = require('esbuild');
const { polyfillNode } = require('esbuild-plugin-polyfill-node');
const globalsPlugin = require('esbuild-plugin-globals');
const dotenv = require('dotenv');
const envObj = dotenv.config().parsed;
const build = async () => {
try {
await esbuild
.build({
entryPoints: ['./out/api/view.js'],
bundle: true,
outfile: 'api.view.js',
sourcemap: false,
minify: true,
minifyWhitespace: true,
minifyIdentifiers: true,
minifySyntax: true,
target: 'ESNext',
platform: 'browser',
treeShaking: true,
jsx: 'automatic',
jsxImportSource: 'preact',
define: {
'process.env.NODE_ENV': '"production"',
...Object.entries(envObj).reduce((result, [key, value]) => {
result[`process.env.${key}`] = `"${value}"`;
return result;
}, {})
},
plugins: [
globalsPlugin({
'react': 'React',
'react-dom': 'ReactDOM',
'react-dom/client': 'ReactDOM',
'prismjs': 'Prism',
'react-markdown': 'ReactMarkdown'
}),
polyfillNode({
globals: false
})
]
});
} catch (err) {
console.error('Failed building project', { err });
process.exit(1);
}
};
build();