Commit | Line | Data |
---|---|---|
653b69b4 | 1 | /* eslint-disable n/no-unpublished-import */ |
eadc058c | 2 | import * as os from 'node:os'; |
10687422 | 3 | import { env } from 'node:process'; |
31b5738e | 4 | |
f412fe24 | 5 | import json from '@rollup/plugin-json'; |
8b6da988 JB |
6 | import terser from '@rollup/plugin-terser'; |
7 | import typescript from '@rollup/plugin-typescript'; | |
672551ed | 8 | import { copy } from '@web/rollup-plugin-copy'; |
2172e282 | 9 | import { defineConfig } from 'rollup'; |
cb1948a3 | 10 | import analyze from 'rollup-plugin-analyzer'; |
44b07a21 | 11 | import del from 'rollup-plugin-delete'; |
44b07a21 | 12 | |
eadc058c JB |
13 | const availableParallelism = () => { |
14 | // eslint-disable-next-line no-shadow | |
15 | let availableParallelism = 1; | |
16 | try { | |
17 | availableParallelism = os.availableParallelism(); | |
18 | } catch { | |
abea4654 JB |
19 | const cpus = os.cpus(); |
20 | if (Array.isArray(cpus) && cpus.length > 0) { | |
21 | availableParallelism = cpus.length; | |
eadc058c JB |
22 | } |
23 | } | |
24 | return availableParallelism; | |
25 | }; | |
26 | ||
10687422 JB |
27 | const isDevelopmentBuild = env.BUILD === 'development'; |
28 | const isAnalyzeBuild = env.ANALYZE; | |
92bee070 | 29 | const sourceMap = !!isDevelopmentBuild; |
1d064457 | 30 | |
2172e282 | 31 | export default defineConfig({ |
60770235 | 32 | input: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'], |
b768993d | 33 | strictDeprecations: true, |
44a95b7f JB |
34 | output: [ |
35 | { | |
60770235 | 36 | dir: './dist', |
2896e06d | 37 | format: 'esm', |
92bee070 | 38 | sourcemap: sourceMap, |
eadc058c | 39 | plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })], |
44a95b7f | 40 | }, |
44a95b7f | 41 | ], |
e7aeea18 | 42 | external: [ |
e3018bc4 JB |
43 | '@mikro-orm/core', |
44 | '@mikro-orm/reflection', | |
45 | 'ajv', | |
e3018bc4 | 46 | 'ajv-formats', |
e7aeea18 JB |
47 | 'basic-ftp', |
48 | 'chalk', | |
a675e34b | 49 | 'date-fns', |
32f5e42d | 50 | 'deep-clone', |
852a4c5f | 51 | 'http-status-codes', |
088ee3c1 | 52 | 'just-merge', |
f31d1d0c JB |
53 | 'mnemonist/lru-map-with-delete.js', |
54 | 'mnemonist/queue.js', | |
e7aeea18 | 55 | 'mongodb', |
01f4001e | 56 | 'node:async_hooks', |
0c7370da | 57 | 'node:crypto', |
942f9727 | 58 | 'node:events', |
130783a7 | 59 | 'node:fs', |
01f4001e | 60 | 'node:http', |
8334d329 | 61 | 'node:http2', |
130783a7 | 62 | 'node:path', |
01f4001e | 63 | 'node:perf_hooks', |
10687422 | 64 | 'node:process', |
8a168938 | 65 | 'node:stream', |
130783a7 | 66 | 'node:url', |
0c7370da | 67 | 'node:util', |
01f4001e | 68 | 'node:worker_threads', |
e7aeea18 | 69 | 'poolifier', |
e7aeea18 | 70 | 'tar', |
e3018bc4 | 71 | 'winston', |
e7aeea18 | 72 | 'winston-daily-rotate-file', |
b768993d | 73 | 'winston/lib/winston/transports/index.js', |
e3018bc4 | 74 | 'ws', |
e7aeea18 | 75 | ], |
44b07a21 | 76 | plugins: [ |
84e52c2c | 77 | json(), |
8b6da988 | 78 | typescript({ |
60770235 | 79 | tsconfig: './tsconfig.json', |
c98873ea | 80 | compilerOptions: { |
92bee070 | 81 | sourceMap, |
c98873ea | 82 | }, |
44b07a21 JB |
83 | }), |
84 | del({ | |
045639f5 | 85 | targets: [ |
60770235 JB |
86 | './dist/*', |
87 | '!./dist/assets', | |
88 | './dist/assets/*.json', | |
89 | './dist/assets/json-schemas', | |
90 | './dist/assets/station-templates', | |
91 | './dist/assets/ui-protocol', | |
045639f5 | 92 | ], |
c4a19794 JB |
93 | }), |
94 | copy({ | |
60770235 | 95 | rootDir: './src', |
672551ed JB |
96 | patterns: 'assets/**/*.json', |
97 | exclude: [ | |
98 | 'assets/config-template.json', | |
70b77dcd | 99 | 'assets/*config[-_.]*.json', |
672551ed | 100 | 'assets/idtags-template.json', |
5d1a7b7d | 101 | 'assets/authorization-tags-template.json', |
672551ed JB |
102 | 'assets/ui-protocol/**/*', |
103 | ], | |
cb1948a3 | 104 | }), |
51022aa0 | 105 | isAnalyzeBuild && analyze(), |
e7aeea18 | 106 | ], |
2172e282 | 107 | }); |