From 025a6ed89ac6745c01ea99cd18c259c8b19e1bee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Thu, 6 Apr 2023 19:18:32 +0200 Subject: [PATCH] Add script post build to check size of integration script is not too big --- site/vite-iframe-script.config.ts | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/site/vite-iframe-script.config.ts b/site/vite-iframe-script.config.ts index d23691c69..c62ab353c 100644 --- a/site/vite-iframe-script.config.ts +++ b/site/vite-iframe-script.config.ts @@ -1,4 +1,5 @@ import yaml from '@rollup/plugin-yaml' +import { statSync } from 'fs' import path from 'path' import { defineConfig } from 'vite' import { VitePWA } from 'vite-plugin-pwa' @@ -16,5 +17,25 @@ export default defineConfig({ }, emptyOutDir: false, }, - plugins: [yaml(), VitePWA({ disable: true })], + plugins: [ + yaml(), + VitePWA({ disable: true }), + { + name: 'postbuild-commands', + closeBundle: () => { + // eslint-disable-next-line @typescript-eslint/no-misused-promises + setTimeout(() => { + const path = './dist/simulateur-iframe-integration.js' + const stats = statSync(path) + + const limit = 5000 + if (stats.size > limit) { + console.error( + `Failed to build ${path}, the built file looks too big! (${stats.size} > ${limit})` + ) + } + }, 1000) + }, + }, + ], })