From f36c2478a92ea04a096232c4060427438ad2cd79 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 12 Jan 2024 20:33:31 +0100 Subject: [PATCH] refactor: use top level await in bundling code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- bundle.js | 136 +++++++++++++++++++++++++++--------------------------- 1 file changed, 67 insertions(+), 69 deletions(-) diff --git a/bundle.js b/bundle.js index 455da66f..9a68fa7a 100644 --- a/bundle.js +++ b/bundle.js @@ -6,72 +6,70 @@ import { build } from 'esbuild' import { clean } from 'esbuild-plugin-clean' import { copy } from 'esbuild-plugin-copy' -;(async () => { - const isDevelopmentBuild = env.BUILD === 'development' - const sourcemap = !!isDevelopmentBuild - console.info(chalk.green(`Building in ${isDevelopmentBuild ? 'development' : 'production'} mode`)) - console.time('Build time') - await build({ - entryPoints: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'], - bundle: true, - platform: 'node', - format: 'esm', - external: [ - '@mikro-orm/*', - 'ajv', - 'ajv-formats', - 'basic-ftp', - 'chalk', - 'date-fns', - 'http-status-codes', - 'just-merge', - 'logform', - // 'mnemonist', - 'mongodb', - 'node:*', - 'poolifier', - 'tar', - 'winston', - 'winston/*', - 'winston-daily-rotate-file', - 'ws' - ], - minify: true, - sourcemap, - entryNames: '[name]', - outdir: './dist', - plugins: [ - clean({ - patterns: [ - './dist/*', - '!./dist/assets', - './dist/assets/*.json', - './dist/assets/json-schemas', - './dist/assets/station-templates', - './dist/assets/ui-protocol' - ] - }), - copy({ - assets: [ - { - from: ['./src/assets/config.json'], - to: ['./assets'] - }, - { - from: ['./src/assets/idtags!(-template)*.json'], - to: ['./assets'] - }, - { - from: ['./src/assets/json-schemas/**/*.json'], - to: ['./assets/json-schemas'] - }, - { - from: ['./src/assets/station-templates/**/*.json'], - to: ['./assets/station-templates'] - } - ] - }) - ] - }) - console.timeEnd('Build time') -})() +const isDevelopmentBuild = env.BUILD === 'development' +const sourcemap = !!isDevelopmentBuild +console.info(chalk.green(`Building in ${isDevelopmentBuild ? 'development' : 'production'} mode`)) +console.time('Build time') +await build({ + entryPoints: ['./src/start.ts', './src/charging-station/ChargingStationWorker.ts'], + bundle: true, + platform: 'node', + format: 'esm', + external: [ + '@mikro-orm/*', + 'ajv', + 'ajv-formats', + 'basic-ftp', + 'chalk', + 'date-fns', + 'http-status-codes', + 'just-merge', + 'logform', + // 'mnemonist', + 'mongodb', + 'node:*', + 'poolifier', + 'tar', + 'winston', + 'winston/*', + 'winston-daily-rotate-file', + 'ws' + ], + minify: true, + sourcemap, + entryNames: '[name]', + outdir: './dist', + plugins: [ + clean({ + patterns: [ + './dist/*', + '!./dist/assets', + './dist/assets/*.json', + './dist/assets/json-schemas', + './dist/assets/station-templates', + './dist/assets/ui-protocol' + ] + }), + copy({ + assets: [ + { + from: ['./src/assets/config.json'], + to: ['./assets'] + }, + { + from: ['./src/assets/idtags!(-template)*.json'], + to: ['./assets'] + }, + { + from: ['./src/assets/json-schemas/**/*.json'], + to: ['./assets/json-schemas'] + }, + { + from: ['./src/assets/station-templates/**/*.json'], + to: ['./assets/station-templates'] + } + ] + }) + ] +}) +console.timeEnd('Build time') -- 2.34.1