build: fix docker image build
[e-mobility-charging-stations-simulator.git] / rollup.config.ts
CommitLineData
eadc058c 1import * as os from 'node:os';
10687422 2import { env } from 'node:process';
31b5738e 3
f412fe24 4import json from '@rollup/plugin-json';
8b6da988
JB
5import terser from '@rollup/plugin-terser';
6import typescript from '@rollup/plugin-typescript';
672551ed 7import { copy } from '@web/rollup-plugin-copy';
2172e282 8import { defineConfig } from 'rollup';
cb1948a3 9import analyze from 'rollup-plugin-analyzer';
44b07a21 10import del from 'rollup-plugin-delete';
44b07a21 11
5ae86cf4
JB
12const availableParallelism = (): number => {
13 // eslint-disable-next-line @typescript-eslint/no-shadow
eadc058c
JB
14 let availableParallelism = 1;
15 try {
16 availableParallelism = os.availableParallelism();
17 } catch {
abea4654
JB
18 const cpus = os.cpus();
19 if (Array.isArray(cpus) && cpus.length > 0) {
20 availableParallelism = cpus.length;
eadc058c
JB
21 }
22 }
23 return availableParallelism;
24};
25
10687422
JB
26const isDevelopmentBuild = env.BUILD === 'development';
27const isAnalyzeBuild = env.ANALYZE;
b2c01742 28const sourcemap = !!isDevelopmentBuild;
1d064457 29
2172e282 30export default defineConfig({
60770235 31 input: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'],
b768993d 32 strictDeprecations: true,
44a95b7f
JB
33 output: [
34 {
60770235 35 dir: './dist',
2896e06d 36 format: 'esm',
b2c01742 37 sourcemap,
eadc058c 38 plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })],
44a95b7f 39 },
44a95b7f 40 ],
e7aeea18 41 external: [
e3018bc4
JB
42 '@mikro-orm/core',
43 '@mikro-orm/reflection',
44 'ajv',
e3018bc4 45 'ajv-formats',
e7aeea18
JB
46 'basic-ftp',
47 'chalk',
a675e34b 48 'date-fns',
32f5e42d 49 'deep-clone',
852a4c5f 50 'http-status-codes',
088ee3c1 51 'just-merge',
f31d1d0c
JB
52 'mnemonist/lru-map-with-delete.js',
53 'mnemonist/queue.js',
e7aeea18 54 'mongodb',
01f4001e 55 'node:async_hooks',
0c7370da 56 'node:crypto',
942f9727 57 'node:events',
130783a7 58 'node:fs',
01f4001e 59 'node:http',
8334d329 60 'node:http2',
130783a7 61 'node:path',
01f4001e 62 'node:perf_hooks',
10687422 63 'node:process',
8a168938 64 'node:stream',
130783a7 65 'node:url',
0c7370da 66 'node:util',
01f4001e 67 'node:worker_threads',
e7aeea18 68 'poolifier',
e7aeea18 69 'tar',
e3018bc4 70 'winston',
e7aeea18 71 'winston-daily-rotate-file',
b768993d 72 'winston/lib/winston/transports/index.js',
e3018bc4 73 'ws',
e7aeea18 74 ],
44b07a21 75 plugins: [
84e52c2c 76 json(),
8b6da988 77 typescript({
60770235 78 tsconfig: './tsconfig.json',
c98873ea 79 compilerOptions: {
b2c01742 80 sourceMap: sourcemap,
c98873ea 81 },
44b07a21
JB
82 }),
83 del({
045639f5 84 targets: [
60770235
JB
85 './dist/*',
86 '!./dist/assets',
87 './dist/assets/*.json',
88 './dist/assets/json-schemas',
89 './dist/assets/station-templates',
90 './dist/assets/ui-protocol',
045639f5 91 ],
c4a19794
JB
92 }),
93 copy({
60770235 94 rootDir: './src',
672551ed
JB
95 patterns: 'assets/**/*.json',
96 exclude: [
97 'assets/config-template.json',
70b77dcd 98 'assets/*config[-_.]*.json',
672551ed 99 'assets/idtags-template.json',
5d1a7b7d 100 'assets/authorization-tags-template.json',
672551ed
JB
101 'assets/ui-protocol/**/*',
102 ],
cb1948a3 103 }),
5ae86cf4 104 Boolean(isAnalyzeBuild) && analyze(),
e7aeea18 105 ],
2172e282 106});