fix: make ESM bundle work
[e-mobility-charging-stations-simulator.git] / rollup.config.mjs
CommitLineData
f412fe24 1import json from '@rollup/plugin-json';
8b6da988
JB
2import terser from '@rollup/plugin-terser';
3import typescript from '@rollup/plugin-typescript';
cb1948a3 4import analyze from 'rollup-plugin-analyzer';
c4a19794 5import copy from 'rollup-plugin-copy';
44b07a21 6import del from 'rollup-plugin-delete';
44b07a21 7
1d064457
JB
8const isDevelopmentBuild = process.env.BUILD === 'development';
9
44b07a21 10export default {
5a010bf0 11 input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
b768993d 12 strictDeprecations: true,
44a95b7f
JB
13 output: [
14 {
15 dir: 'dist',
2896e06d 16 format: 'esm',
44a95b7f
JB
17 exports: 'auto',
18 sourcemap: true,
19 preserveModules: true,
20 preserveModulesRoot: 'src',
21 entryFileNames: '[name].mjs',
8b6da988 22 ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }),
44a95b7f
JB
23 },
24 {
25 dir: 'dist',
26 format: 'cjs',
27 exports: 'auto',
28 sourcemap: true,
29 preserveModules: true,
30 preserveModulesRoot: 'src',
31 entryFileNames: '[name].cjs',
8b6da988 32 ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }),
44a95b7f
JB
33 },
34 ],
e7aeea18 35 external: [
e3018bc4
JB
36 '@mikro-orm/core',
37 '@mikro-orm/reflection',
38 'ajv',
e3018bc4 39 'ajv-formats',
e7aeea18
JB
40 'basic-ftp',
41 'chalk',
852a4c5f 42 'http-status-codes',
088ee3c1
JB
43 'just-clone',
44 'just-merge',
b768993d 45 'mnemonist/lru-map-with-delete.js',
0bb3ee61 46 'moment',
e7aeea18 47 'mongodb',
01f4001e 48 'node:async_hooks',
0c7370da 49 'node:crypto',
130783a7 50 'node:fs',
01f4001e 51 'node:http',
130783a7 52 'node:path',
01f4001e 53 'node:perf_hooks',
8a168938 54 'node:stream',
130783a7 55 'node:url',
0c7370da 56 'node:util',
01f4001e 57 'node:worker_threads',
e7aeea18
JB
58 'poolifier',
59 'proper-lockfile',
e7aeea18 60 'tar',
e3018bc4 61 'winston',
e7aeea18 62 'winston-daily-rotate-file',
b768993d 63 'winston/lib/winston/transports/index.js',
e3018bc4 64 'ws',
e7aeea18 65 ],
44b07a21 66 plugins: [
84e52c2c 67 json(),
8b6da988 68 typescript({
ae8ee665 69 tsconfig: 'tsconfig.json',
44b07a21
JB
70 }),
71 del({
045639f5
JB
72 targets: [
73 'dist/*',
74 '!dist/assets',
75 'dist/assets/*.json',
76 'dist/assets/station-templates',
77 'dist/assets/json-schemas',
78 ],
c4a19794
JB
79 }),
80 copy({
e7aeea18 81 targets: [{ src: 'src/assets', dest: 'dist/' }],
cb1948a3 82 }),
e7aeea18
JB
83 isDevelopmentBuild && analyze(),
84 ],
44b07a21 85};