From e59878d650543cf7e2520bf025562fe157a1b875 Mon Sep 17 00:00:00 2001 From: Mathieu Benoit Date: Thu, 8 Oct 2026 03:08:48 -0400 Subject: [PATCH] [IMP] build: chunk size warning at 1000 kB, a failing test beyond it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Vite warned on every build because its 500 kB threshold targets pages fetched over a network; this page is read from the local disk once, and one chunk holds the whole application with the generation worker inlined. The threshold now sits at 1000 kB, so it only flags abnormal growth, and the build test fails when any chunk exceeds it, naming the file and size. Checked: the build is 658 kB with no warning; a 600 kB threshold turns the test red. --- FR --- [IMP] construction : seuil d'avertissement à 1000 ko, épreuve au-delà Vite avertissait à chaque construction, car son seuil de 500 ko vise les pages chargées par le réseau ; cette page se lit sur le disque local, une fois, et un seul morceau porte l'application entière, travailleur de génération incrusté compris. Le seuil passe à 1000 ko et ne signale plus qu'une croissance anormale ; l'épreuve de construction tombe quand un morceau le dépasse, en nommant le fichier et sa taille. Vérifié : 658 ko sans avertissement ; un seuil à 600 ko rend l'épreuve rouge. Assisted-by: Claude Opus 5.5 --- test/construction.long.test.js | 18 +++++++++++++++++- vite.config.js | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/test/construction.long.test.js b/test/construction.long.test.js index 5f712bf..6e57c06 100644 --- a/test/construction.long.test.js +++ b/test/construction.long.test.js @@ -16,7 +16,7 @@ import assert from 'node:assert/strict'; import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { extname, join, relative, resolve, sep } from 'node:path'; -import { fileURLToPath } from 'node:url'; +import { fileURLToPath, pathToFileURL } from 'node:url'; import { build } from 'vite'; import { describe, test } from './lanceur.js'; @@ -315,6 +315,22 @@ describe('construction', () => { ); assert.deepEqual(modules.filter(moduleDEpreuve), []); + // La taille de chaque morceau tient sous le seuil d'avertissement de + // vite.config.js, en kilooctets de 1 000 octets comme Vite les compte : + // un paquet qui grossit au-delà fait tomber cette épreuve, et non + // seulement avertir la construction. + const { default: vite } = await import(pathToFileURL(join(RACINE, 'vite.config.js')).href); + const seuil = vite.build?.chunkSizeWarningLimit; + assert.equal(typeof seuil, 'number', 'vite.config.js ne pose aucun build.chunkSizeWarningLimit'); + const morceaux = sorties.filter((s) => s.type === 'chunk'); + assert.ok(morceaux.length > 0, `aucun morceau parmi ${sorties.length} sorties`); + assert.deepEqual( + morceaux + .filter((m) => Buffer.byteLength(m.code, 'utf8') > seuil * 1000) + .map((m) => `${m.fileName} : ${Math.ceil(Buffer.byteLength(m.code, 'utf8') / 1000)} ko > ${seuil} ko`), + [], + ); + // Un actif n'est pas un module : moduleIds ne le voit pas. Une donnée // jointe par new URL(…, import.meta.url) n'apparaît que là. const actifs = sorties diff --git a/vite.config.js b/vite.config.js index 372a00b..ae200cd 100644 --- a/vite.config.js +++ b/vite.config.js @@ -5,6 +5,12 @@ // Electron. La base relative fait commencer chaque chemin d'actif par « ./ » : // la coquille charge la page par file://, où un chemin absolu « /assets/… » // désigne la racine du disque. +// +// Le seuil d'avertissement d'un morceau vaut 1 000 ko, et non les 500 ko de +// Vite : la page se lit sur le disque local, hors ligne, une fois au +// lancement, et un seul morceau porte l'application entière, travailleur de +// génération incrusté compris. Le seuil n'avertit donc que d'une croissance +// anormale du paquet ; test/construction.long.test.js tombe au-delà. import { defineConfig } from 'vite'; import { svelte } from '@sveltejs/vite-plugin-svelte'; @@ -14,5 +20,6 @@ export default defineConfig({ build: { outDir: 'www', emptyOutDir: true, + chunkSizeWarningLimit: 1000, }, });