X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=rollup.config.mjs;h=2c8d35564c05b9925bfaf91e3c39f4aa582abc7d;hb=b89fb74f6d61fb58fc6e7c3d5b1502c2ab04bbe8;hp=80f99ca861c7c6b71933abe3b26a815d7e70daa7;hpb=0c995ea6078b233350884f71f9c178e4d57150c6;p=e-mobility-charging-stations-simulator.git diff --git a/rollup.config.mjs b/rollup.config.mjs index 80f99ca8..2c8d3556 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,11 +1,30 @@ +/* eslint-disable n/no-unpublished-import */ +import * as os from 'node:os'; + 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 analyze from 'rollup-plugin-analyzer'; -import copy from 'rollup-plugin-copy'; import del from 'rollup-plugin-delete'; +const availableParallelism = () => { + // eslint-disable-next-line no-shadow + let availableParallelism = 1; + try { + availableParallelism = os.availableParallelism(); + } catch { + const numberOfCpus = os.cpus(); + if (Array.isArray(numberOfCpus) && numberOfCpus.length > 0) { + availableParallelism = numberOfCpus.length; + } + } + return availableParallelism; +}; + const isDevelopmentBuild = process.env.BUILD === 'development'; +const isAnalyzeBuild = process.env.ANALYZE; +const sourceMap = !!isDevelopmentBuild; export default { input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'], @@ -14,22 +33,8 @@ export default { { dir: 'dist', format: 'esm', - exports: 'auto', - sourcemap: true, - preserveModules: true, - preserveModulesRoot: 'src', - entryFileNames: '[name].mjs', - ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }), - }, - { - dir: 'dist', - format: 'cjs', - exports: 'auto', - sourcemap: true, - preserveModules: true, - preserveModulesRoot: 'src', - entryFileNames: '[name].cjs', - ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }), + sourcemap: sourceMap, + plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })], }, ], external: [ @@ -39,16 +44,19 @@ export default { 'ajv-formats', 'basic-ftp', 'chalk', + 'date-fns', + 'deep-clone', 'http-status-codes', - 'just-clone', 'just-merge', 'mnemonist/lru-map-with-delete.js', - 'moment', + 'mnemonist/queue.js', 'mongodb', 'node:async_hooks', 'node:crypto', + 'node:events', 'node:fs', 'node:http', + 'node:http2', 'node:path', 'node:perf_hooks', 'node:stream', @@ -56,7 +64,6 @@ export default { 'node:util', 'node:worker_threads', 'poolifier', - 'proper-lockfile', 'tar', 'winston', 'winston-daily-rotate-file', @@ -67,6 +74,9 @@ export default { json(), typescript({ tsconfig: 'tsconfig.json', + compilerOptions: { + sourceMap, + }, }), del({ targets: [ @@ -79,8 +89,16 @@ export default { ], }), copy({ - targets: [{ src: 'src/assets', dest: 'dist/' }], + 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/**/*', + ], }), - isDevelopmentBuild && analyze(), + isAnalyzeBuild && analyze(), ], };