build(deps-dev): Bump vitest from 0.34.4 to 0.34.5 in /ui/web
[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 { defineConfig } from 'rollup';
9 import analyze from 'rollup-plugin-analyzer';
10 import del from 'rollup-plugin-delete';
11
12 const availableParallelism = () => {
13 // eslint-disable-next-line 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 = process.env.BUILD === 'development';
27 const isAnalyzeBuild = process.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: 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:stream',
64 'node:url',
65 'node:util',
66 'node:worker_threads',
67 'poolifier',
68 'tar',
69 'winston',
70 'winston-daily-rotate-file',
71 'winston/lib/winston/transports/index.js',
72 'ws',
73 ],
74 plugins: [
75 json(),
76 typescript({
77 tsconfig: './tsconfig.json',
78 compilerOptions: {
79 sourceMap,
80 },
81 }),
82 del({
83 targets: [
84 './dist/*',
85 '!./dist/assets',
86 './dist/assets/*.json',
87 './dist/assets/json-schemas',
88 './dist/assets/station-templates',
89 './dist/assets/ui-protocol',
90 ],
91 }),
92 copy({
93 rootDir: './src',
94 patterns: 'assets/**/*.json',
95 exclude: [
96 'assets/config-template.json',
97 'assets/*config[-_.]*.json',
98 'assets/idtags-template.json',
99 'assets/authorization-tags-template.json',
100 'assets/ui-protocol/**/*',
101 ],
102 }),
103 isAnalyzeBuild && analyze(),
104 ],
105 });