X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=rollup.config.js;h=ec98513a8e889a0f0baef91cd24f6484360ab675;hb=c0a330785a8f27f5a3e889251829497a2538ebef;hp=9a8b5955b315e4bcac6905f4271171ff379ebd82;hpb=128f985401bd87bf53f68cbe1bfec8d64bbaa6d9;p=e-mobility-charging-stations-simulator.git diff --git a/rollup.config.js b/rollup.config.js index 9a8b5955..ec98513a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,23 +1,107 @@ +/* eslint-disable n/no-unpublished-import */ +import * as os from 'node:os'; +import { env } from 'node:process'; + +import json from '@rollup/plugin-json'; +import terser from '@rollup/plugin-terser'; +import typescript from '@rollup/plugin-typescript'; +import { copy } from '@web/rollup-plugin-copy'; +import { defineConfig } from 'rollup'; +import analyze from 'rollup-plugin-analyzer'; import del from 'rollup-plugin-delete'; -import ts from '@wessberg/rollup-plugin-ts'; -export default { - input: ['src/start.ts', 'src/charging-station/StationWorker.ts'], - output: { - dir: 'dist', - format: 'cjs', - exports: 'auto', - sourcemap: true, - preserveModules: true, - preserveModulesRoot: 'src' - }, - external: ['crypto', 'perf_hooks', 'fs', 'poolifier', 'uuid', 'ws', 'winston', 'winston-daily-rotate-file', 'worker_threads'], +const availableParallelism = () => { + // eslint-disable-next-line no-shadow + let availableParallelism = 1; + try { + availableParallelism = os.availableParallelism(); + } catch { + const cpus = os.cpus(); + if (Array.isArray(cpus) && cpus.length > 0) { + availableParallelism = cpus.length; + } + } + return availableParallelism; +}; + +const isDevelopmentBuild = env.BUILD === 'development'; +const isAnalyzeBuild = env.ANALYZE; +const sourcemap = !!isDevelopmentBuild; + +export default defineConfig({ + input: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'], + strictDeprecations: true, + output: [ + { + dir: './dist', + format: 'esm', + sourcemap, + plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })], + }, + ], + external: [ + '@mikro-orm/core', + '@mikro-orm/reflection', + 'ajv', + 'ajv-formats', + 'basic-ftp', + 'chalk', + 'date-fns', + 'deep-clone', + 'http-status-codes', + 'just-merge', + 'mnemonist/lru-map-with-delete.js', + 'mnemonist/queue.js', + 'mongodb', + 'node:async_hooks', + 'node:crypto', + 'node:events', + 'node:fs', + 'node:http', + 'node:http2', + 'node:path', + 'node:perf_hooks', + 'node:process', + 'node:stream', + 'node:url', + 'node:util', + 'node:worker_threads', + 'poolifier', + 'tar', + 'winston', + 'winston-daily-rotate-file', + 'winston/lib/winston/transports/index.js', + 'ws', + ], plugins: [ - ts({ - tsconfig: 'tsconfig.json' + json(), + typescript({ + tsconfig: './tsconfig.json', + compilerOptions: { + sourceMap: sourcemap, + }, }), del({ - targets: 'dist/*' - }) - ] -}; + targets: [ + './dist/*', + '!./dist/assets', + './dist/assets/*.json', + './dist/assets/json-schemas', + './dist/assets/station-templates', + './dist/assets/ui-protocol', + ], + }), + copy({ + rootDir: './src', + patterns: 'assets/**/*.json', + exclude: [ + 'assets/config-template.json', + 'assets/*config[-_.]*.json', + 'assets/idtags-template.json', + 'assets/authorization-tags-template.json', + 'assets/ui-protocol/**/*', + ], + }), + isAnalyzeBuild && analyze(), + ], +});