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