/
bundle.js
64 lines (60 loc) · 1.82 KB
/
bundle.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const esbuild = require('esbuild');
const glob = require('fast-glob');
const { nodeExternalsPlugin } = require('esbuild-node-externals');
const { vanillaExtractPlugin } = require('@vanilla-extract/esbuild-plugin');
const args = process.argv.slice(2);
const watchEnabled = args[0] === 'watch';
const packageName = process.env.npm_package_name;
const watchConfig = watchEnabled
? {
onRebuild(error, result) {
if (error) console.error(`watch build failed for ${packageName}:`, error);
else console.log(`watch build succeeded for ${packageName}:`, result);
}
}
: false;
esbuild
.build({
entryPoints: glob.sync(['src/**/*.ts?(x)', 'src/*.ts?(x)'], {
ignore: ['**/__tests__', 'src/labs']
}),
loader: {
'.jpg': 'dataurl',
'.png': 'dataurl',
'.svg': 'text'
},
outdir: './dist',
bundle: true,
sourcemap: false,
splitting: true,
minify: true,
format: 'esm',
target: ['es2022'],
plugins: [nodeExternalsPlugin(), vanillaExtractPlugin({})],
external: [
'react',
'react-dom',
'next/*',
'@jpmorganchase/mosaic-components',
'@jpmorganchase/mosaic-components-lab',
'@jpmorganchase/mosaic-open-api-component',
'@jpmorganchase/mosaic-content-editor-plugin',
'@jpmorganchase/mosaic-site-components',
'@jpmorganchase/mosaic-layouts',
'@jpmorganchase/mosaic-store'
],
watch: watchConfig
})
.catch(e => {
if (e.errors && e.errors.length > 0) {
console.group(`!!!!!!! ${packageName} build errors !!!!!!!`);
console.error(e.errors);
console.groupEnd();
}
if (e.warnings && e.warnings.length > 0) {
console.group(`!!!!!!! ${packageName} build warnings !!!!!!!`);
console.error(e.warnings);
console.groupEnd();
}
return process.exit(1);
});