build(deps): apply updates
[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 console.info(chalk.green(`Building in ${isDevelopmentBuild ? 'development' : 'production'} mode`))
12 console.time('Build time')
13 await build({
14 entryPoints: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'],
15 bundle: true,
16 platform: 'node',
17 format: 'esm',
18 external: [
19 '@mikro-orm/*',
20 'ajv',
21 'ajv-formats',
22 'basic-ftp',
23 'chalk',
24 'date-fns',
25 'date-fns/*',
26 'http-status-codes',
27 'logform',
28 'mnemonist',
29 'mongodb',
30 'node:*',
31 'poolifier',
32 'rambda',
33 'tar',
34 'winston',
35 'winston/*',
36 'winston-daily-rotate-file',
37 'ws'
38 ],
39 treeShaking: true,
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 './dist/assets/configs-docker'
54 ]
55 }),
56 copy({
57 assets: [
58 {
59 from: ['./src/assets/config.json'],
60 to: ['./assets']
61 },
62 {
63 from: ['./src/assets/idtags!(-template)*.json'],
64 to: ['./assets']
65 },
66 {
67 from: ['./src/assets/json-schemas/**/*.json'],
68 to: ['./assets/json-schemas']
69 },
70 {
71 from: ['./src/assets/station-templates/**/*.json'],
72 to: ['./assets/station-templates']
73 },
74 {
75 from: ['./src/assets/configs-docker/*.json'],
76 to: ['./assets/configs-docker']
77 }
78 ]
79 })
80 ]
81 })
82 console.timeEnd('Build time')