build(deps): Bump poolifier from 2.7.3 to 2.7.4
[e-mobility-charging-stations-simulator.git] / rollup.config.mjs
CommitLineData
653b69b4 1/* eslint-disable n/no-unpublished-import */
eadc058c 2import * as os from 'node:os';
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
eadc058c
JB
12const availableParallelism = () => {
13 // eslint-disable-next-line no-shadow
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
1d064457 26const isDevelopmentBuild = process.env.BUILD === 'development';
51022aa0 27const isAnalyzeBuild = process.env.ANALYZE;
92bee070 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',
92bee070 37 sourcemap: 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',
8a168938 63 'node:stream',
130783a7 64 'node:url',
0c7370da 65 'node:util',
01f4001e 66 'node:worker_threads',
e7aeea18 67 'poolifier',
e7aeea18 68 'tar',
e3018bc4 69 'winston',
e7aeea18 70 'winston-daily-rotate-file',
b768993d 71 'winston/lib/winston/transports/index.js',
e3018bc4 72 'ws',
e7aeea18 73 ],
44b07a21 74 plugins: [
84e52c2c 75 json(),
8b6da988 76 typescript({
60770235 77 tsconfig: './tsconfig.json',
c98873ea 78 compilerOptions: {
92bee070 79 sourceMap,
c98873ea 80 },
44b07a21
JB
81 }),
82 del({
045639f5 83 targets: [
60770235
JB
84 './dist/*',
85 '!./dist/assets',
86 './dist/assets/*.json',
87 './dist/assets/json-schemas',
88 './dist/assets/station-templates',
89 './dist/assets/ui-protocol',
045639f5 90 ],
c4a19794
JB
91 }),
92 copy({
60770235 93 rootDir: './src',
672551ed
JB
94 patterns: 'assets/**/*.json',
95 exclude: [
96 'assets/config-template.json',
70b77dcd 97 'assets/*config[-_.]*.json',
672551ed 98 'assets/idtags-template.json',
5d1a7b7d 99 'assets/authorization-tags-template.json',
672551ed
JB
100 'assets/ui-protocol/**/*',
101 ],
cb1948a3 102 }),
51022aa0 103 isAnalyzeBuild && analyze(),
e7aeea18 104 ],
2172e282 105});