Add initial support for ESM build
[e-mobility-charging-stations-simulator.git] / rollup.config.mjs
CommitLineData
cb1948a3 1import analyze from 'rollup-plugin-analyzer';
c4a19794 2import copy from 'rollup-plugin-copy';
44b07a21 3import del from 'rollup-plugin-delete';
4082efc1 4import istanbul from 'rollup-plugin-istanbul';
84e52c2c 5import json from '@rollup/plugin-json';
fc201913 6import { terser } from 'rollup-plugin-terser';
ae8ee665 7import ts from 'rollup-plugin-ts';
44b07a21 8
1d064457
JB
9const isDevelopmentBuild = process.env.BUILD === 'development';
10
44b07a21 11export default {
903becc3 12 input: ['src/start.ts', 'src/ui/httpd/start.ts', 'src/charging-station/ChargingStationWorker.ts'],
44a95b7f
JB
13 output: [
14 {
15 dir: 'dist',
16 format: 'es',
17 exports: 'auto',
18 sourcemap: true,
19 preserveModules: true,
20 preserveModulesRoot: 'src',
21 entryFileNames: '[name].mjs',
22 ...(!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] }),
23 },
24 {
25 dir: 'dist',
26 format: 'cjs',
27 exports: 'auto',
28 sourcemap: true,
29 preserveModules: true,
30 preserveModulesRoot: 'src',
31 entryFileNames: '[name].cjs',
32 ...(!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] }),
33 },
34 ],
e7aeea18
JB
35 external: [
36 'basic-ftp',
37 'chalk',
38 'crypto',
175d4f46 39 'express',
e7aeea18
JB
40 'fs',
41 '@mikro-orm/core',
42 '@mikro-orm/reflection',
7c72977b 43 'mnemonist/lru-map-with-delete',
0bb3ee61 44 'moment',
e7aeea18
JB
45 'mongodb',
46 'path',
47 'perf_hooks',
48 'poolifier',
49 'proper-lockfile',
50 'reflect-metadata',
51 'tar',
52 'url',
53 'uuid',
54 'ws',
55 'winston-daily-rotate-file',
0d8140bd 56 'winston/lib/winston/transports/index.js',
e7aeea18
JB
57 'winston',
58 'worker_threads',
59 ],
44b07a21 60 plugins: [
84e52c2c 61 json(),
ae8ee665
JB
62 ts({
63 tsconfig: 'tsconfig.json',
e7aeea18 64 browserslist: false,
44b07a21 65 }),
4082efc1 66 isDevelopmentBuild && istanbul(),
44b07a21 67 del({
073bd098 68 targets: ['dist/*', '!dist/assets', 'dist/assets/*.json', 'dist/assets/station-templates'],
c4a19794
JB
69 }),
70 copy({
e7aeea18 71 targets: [{ src: 'src/assets', dest: 'dist/' }],
cb1948a3 72 }),
e7aeea18
JB
73 isDevelopmentBuild && analyze(),
74 ],
44b07a21 75};