X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=rollup.config.js;h=ec98513a8e889a0f0baef91cd24f6484360ab675;hb=c0a330785a8f27f5a3e889251829497a2538ebef;hp=14acfddd6fbc2f7e0c26140d7069eb25cff403ba;hpb=2a370053f45f2d58e90ab7b292294c521a262ca1;p=e-mobility-charging-stations-simulator.git diff --git a/rollup.config.js b/rollup.config.js index 14acfddd..ec98513a 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,40 +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 copy from 'rollup-plugin-copy'; import del from 'rollup-plugin-delete'; -import istanbul from 'rollup-plugin-istanbul'; -import json from '@rollup/plugin-json'; -import { terser } from 'rollup-plugin-terser'; -import typescript from 'rollup-plugin-typescript2'; -const isDevelopmentBuild = process.env.BUILD === 'development'; +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 { - input: ['src/start.ts', 'src/charging-station/ChargingStationWorker.ts'], - output: - { - dir: 'dist', - format: 'cjs', - exports: 'auto', - sourcemap: true, - preserveModules: true, - preserveModulesRoot: 'src', - ...!isDevelopmentBuild && { plugins: [terser({ numWorkers: 2 })] } - }, - external: ['basic-ftp', 'chalk', 'crypto', 'mongodb', 'perf_hooks', 'fs', 'path', 'poolifier', 'tar', 'url', 'uuid', 'ws', 'winston-daily-rotate-file', 'winston/lib/winston/transports', 'winston', 'worker_threads'], +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: [ json(), typescript({ - tsconfig: 'tsconfig.json' + tsconfig: './tsconfig.json', + compilerOptions: { + sourceMap: sourcemap, + }, }), - isDevelopmentBuild && istanbul(), del({ - targets: 'dist/*' + targets: [ + './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(), + ], +});