haiku-atelier-2024/vite.config.ts
gcch f8ee393d6b 2025-11-03 (bis)
- ajoute un .dockerignore.
- ajoute un Dockerfile.
- met à jour les dépendances.
- utilise bun comme gestionnaire de paquets npm.
- utilise une configuration Vite en TypeScript.
- ajoute les fichiers compilés JavaScript aux fichiers pris en charge par Git.
2025-11-03 17:20:13 +01:00

89 lines
2.8 KiB
TypeScript
Executable file

import legacy from "@vitejs/plugin-legacy";
import { fdir, PathsOutput } from "fdir";
import { resolve } from "node:path";
import process from "node:process";
import * as v from "valibot";
import { defineConfig, loadEnv } from "vite";
import { compression } from "vite-plugin-compression2";
import manifestSRI from "vite-plugin-manifest-sri";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import valibot from "vite-plugin-valibot-env";
const SLUG_THEME = "haiku-atelier-2024";
const SRC_TYPESCRIPT_PATHS: Promise<PathsOutput> = new fdir()
.withBasePath()
.filter((path, isDirectory) => !isDirectory && !path.endsWith("d.ts"))
.withMaxDepth(0)
.crawl(`web/app/themes/${SLUG_THEME}/src/scripts`)
.withPromise();
// Voir le fichier vite.env.d.ts.
const SCHEMA_ENVIRONNEMENT = v.object({
VITE_GLITCHTIP_NSD: v.pipe(v.string(), v.url(), v.readonly()),
VITE_MODE: v.pipe(v.string(), v.readonly()),
VITE_URL: v.pipe(v.string(), v.nonEmpty(), v.url(), v.readonly()),
});
const basePlugins = [
// Permet de valider les variables d'environnements définies à partir d'un schéma Valibot
valibot(SCHEMA_ENVIRONNEMENT),
manifestSRI({ algorithms: ["sha512"] }),
nodePolyfills({
include: [],
protocolImports: true,
}),
];
// Les extensions activées en production.
const prodPlugins = [
legacy({
modernPolyfills: true,
modernTargets:
"chrome >0 and last 3 years, edge >0 and last 3 years, safari >0 and last 3 years, firefox >0 and last 3 years, and_chr >0 and last 3 years, and_ff >0 and last 3 years, ios >0 and last 3 years",
renderLegacyChunks: true,
}),
compression({
algorithms: [
"brotliCompress",
"gzip",
"zstandard",
],
threshold: 1000,
}),
];
export default defineConfig(async ({ mode }) => {
const env = loadEnv(mode, process.cwd(), "VITE");
console.debug(env);
return {
base: "/",
build: {
assetsDir: ".",
emptyOutDir: true,
// Génère un fichier manifeste dans outDir.
manifest: true,
minify: env["VITE_MODE"] === "production",
outDir: resolve("./web/app/themes/haiku-atelier-2024/assets/js"),
reportCompressedSize: true,
rollupOptions: {
input: await SRC_TYPESCRIPT_PATHS,
experimental: {
incrementalBuild: true,
nativeMagicString: true,
},
output: {
assetFileNames: "[name].[hash].[extname]",
chunkFileNames: "[name].[hash].js",
entryFileNames: "[name].js",
minify: env["VITE_MODE"] === "production",
},
treeshake: true,
},
sourcemap: env["VITE_MODE"] === "development",
target: "es2020",
write: true,
},
mode: env["VITE_MODE"] ?? "production",
plugins: env["VITE_MODE"] === "production" ? [...basePlugins, ...prodPlugins] : [...basePlugins],
};
});