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