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