Merge dependabot/npm_and_yarn/ui/web/vite-5.0.9 into combined-prs-branch
[e-mobility-charging-stations-simulator.git] / bundle.js
1 /* eslint-disable n/no-unpublished-import */
2 import { env } from 'node:process';
3
4 import chalk from 'chalk';
5 import { build } from 'esbuild';
6 import { clean } from 'esbuild-plugin-clean';
7 import { copy } from 'esbuild-plugin-copy';
8
9 const isDevelopmentBuild = env.BUILD === 'development';
10 const sourcemap = !!isDevelopmentBuild;
11
12 (async () => {
13 console.info(
14 chalk.green(`Building in ${isDevelopmentBuild ? 'development' : 'production'} mode`),
15 );
16 console.time('Build time');
17 await build({
18 entryPoints: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'],
19 bundle: true,
20 platform: 'node',
21 format: 'esm',
22 external: [
23 '@mikro-orm/*',
24 'ajv',
25 'ajv-formats',
26 'basic-ftp',
27 'chalk',
28 'date-fns',
29 'http-status-codes',
30 'just-merge',
31 'logform',
32 'mnemonist/*',
33 'mongodb',
34 'node:*',
35 'poolifier',
36 'tar',
37 'winston',
38 'winston/*',
39 'winston-daily-rotate-file',
40 'ws',
41 ],
42 minify: true,
43 sourcemap,
44 entryNames: '[name]',
45 outdir: './dist',
46 plugins: [
47 clean({
48 patterns: [
49 './dist/*',
50 '!./dist/assets',
51 './dist/assets/*.json',
52 './dist/assets/json-schemas',
53 './dist/assets/station-templates',
54 './dist/assets/ui-protocol',
55 ],
56 }),
57 copy({
58 assets: [
59 {
60 from: ['./src/assets/config.json'],
61 to: ['./assets'],
62 },
63 {
64 from: ['./src/assets/idtags!(-template)*.json'],
65 to: ['./assets'],
66 },
67 {
68 from: ['./src/assets/json-schemas/**/*.json'],
69 to: ['./assets/json-schemas'],
70 },
71 {
72 from: ['./src/assets/station-templates/**/*.json'],
73 to: ['./assets/station-templates'],
74 },
75 ],
76 }),
77 ],
78 });
79 console.timeEnd('Build time');
80 })();