build: properly account build time
[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 console.info(chalk.green(`Building in ${isDevelopmentBuild ? 'development' : 'production'} mode`));
13 (async () => {
14 console.time('Build time');
15 await build({
16 entryPoints: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'],
17 bundle: true,
18 platform: 'node',
19 format: 'esm',
20 external: [
21 '@mikro-orm/*',
22 'ajv',
23 'ajv-formats',
24 'basic-ftp',
25 'chalk',
26 'date-fns',
27 'http-status-codes',
28 'just-merge',
29 'logform',
30 'mnemonist/*',
31 'mongodb',
32 'node:*',
33 'poolifier',
34 'tar',
35 'winston',
36 'winston/*',
37 'winston-daily-rotate-file',
38 'ws',
39 ],
40 minify: true,
41 sourcemap,
42 entryNames: '[name]',
43 outdir: './dist',
44 plugins: [
45 clean({
46 patterns: [
47 './dist/*',
48 '!./dist/assets',
49 './dist/assets/*.json',
50 './dist/assets/json-schemas',
51 './dist/assets/station-templates',
52 './dist/assets/ui-protocol',
53 ],
54 }),
55 copy({
56 assets: [
57 {
58 from: ['./src/assets/config.json'],
59 to: ['./assets'],
60 },
61 {
62 from: ['./src/assets/idtags!(-template)*.json'],
63 to: ['./assets'],
64 },
65 {
66 from: ['./src/assets/json-schemas/**/*.json'],
67 to: ['./assets/json-schemas'],
68 },
69 {
70 from: ['./src/assets/station-templates/**/*.json'],
71 to: ['./assets/station-templates'],
72 },
73 ],
74 }),
75 ],
76 });
77 console.timeEnd('Build time');
78 })();