X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=rollup.config.mjs;h=c28aaf0460dd35fa7100ffffcba00c60c3c5b978;hb=69d1cb501a021bc921127f7e4e91ba6dcfaccf66;hp=be507238e8268c58c3e898f47c69a49e033d8b3b;hpb=70b77dcd483b37e7c16e45ff277fd0e5df0690b2;p=e-mobility-charging-stations-simulator.git diff --git a/rollup.config.mjs b/rollup.config.mjs index be507238..c28aaf04 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,25 +1,41 @@ /* eslint-disable n/no-unpublished-import */ -import { cpus } from 'node:os'; +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', - sourcemap: !!isDevelopmentBuild, - plugins: [terser({ maxWorkers: cpus().length / 2 })], + sourcemap: sourceMap, + plugins: [terser({ maxWorkers: Math.floor(availableParallelism() / 2) })], }, ], external: [ @@ -29,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', @@ -56,23 +74,23 @@ export default { plugins: [ json(), typescript({ - tsconfig: 'tsconfig.json', + tsconfig: './tsconfig.json', compilerOptions: { - sourceMap: !!isDevelopmentBuild, + 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', @@ -84,4 +102,4 @@ export default { }), isAnalyzeBuild && analyze(), ], -}; +});