X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=rollup.config.mjs;h=c28aaf0460dd35fa7100ffffcba00c60c3c5b978;hb=9f139e99d5c59592faad743f3285b26acc03b7c9;hp=e660242612b1a9892dd84a0daa390819f3356dda;hpb=672551edc7fdd48814717269e2f814bd54fa387b;p=e-mobility-charging-stations-simulator.git diff --git a/rollup.config.mjs b/rollup.config.mjs index e6602426..c28aaf04 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,24 +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 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', - ...(isDevelopmentBuild && { sourcemap: true }), - ...(!isDevelopmentBuild && { plugins: [terser({ maxWorkers: 2 })] }), + sourcemap: sourceMap, + plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })], }, ], external: [ @@ -28,17 +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', @@ -55,28 +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({ - rootDir: 'src', + rootDir: './src', patterns: 'assets/**/*.json', exclude: [ 'assets/config-template.json', - 'assets/*config[-_]*.json', + 'assets/*config[-_.]*.json', 'assets/idtags-template.json', + 'assets/authorization-tags-template.json', 'assets/ui-protocol/**/*', ], }), isAnalyzeBuild && analyze(), ], -}; +});