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