X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=rollup.config.mjs;h=c28aaf0460dd35fa7100ffffcba00c60c3c5b978;hb=e5485e24a540c7e0102f6721897e80fa79ce3533;hp=80f99ca861c7c6b71933abe3b26a815d7e70daa7;hpb=0c995ea6078b233350884f71f9c178e4d57150c6;p=e-mobility-charging-stations-simulator.git diff --git a/rollup.config.mjs b/rollup.config.mjs index 80f99ca8..c28aaf04 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,35 +1,41 @@ +/* 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 { defineConfig } from 'rollup'; 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 cpus = os.cpus(); + if (Array.isArray(cpus) && cpus.length > 0) { + availableParallelism = cpus.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'], +export default defineConfig({ + input: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'], strictDeprecations: true, output: [ { - dir: 'dist', + 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 +45,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 +65,6 @@ export default { 'node:util', 'node:worker_threads', 'poolifier', - 'proper-lockfile', 'tar', 'winston', 'winston-daily-rotate-file', @@ -66,21 +74,32 @@ export default { plugins: [ json(), typescript({ - tsconfig: 'tsconfig.json', + tsconfig: './tsconfig.json', + compilerOptions: { + sourceMap, + }, }), del({ targets: [ - 'dist/*', - '!dist/assets', - 'dist/assets/*.json', - 'dist/assets/json-schemas', - 'dist/assets/station-templates', - 'dist/assets/ui-protocol', + './dist/*', + '!./dist/assets', + './dist/assets/*.json', + './dist/assets/json-schemas', + './dist/assets/station-templates', + './dist/assets/ui-protocol', ], }), 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(), ], -}; +});