52 lines
1.5 KiB
JavaScript
52 lines
1.5 KiB
JavaScript
import { fdir } from "fdir";
|
|
import { resolve } from "node:path";
|
|
import * as v from "valibot";
|
|
import { defineConfig } from "vite";
|
|
import valibot from "vite-plugin-valibot-env";
|
|
|
|
const SLUG_THEME = "haiku-atelier-2024";
|
|
const SRC_TYPESCRIPT_PATHS = new fdir()
|
|
.withBasePath()
|
|
.glob("**/*.ts")
|
|
.filter((path, isDirectory) => !isDirectory && !path.endsWith("lol.ts"))
|
|
.filter((path, isDirectory) => !isDirectory && !path.endsWith("d.ts"))
|
|
.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_URL: v.pipe(v.string(), v.nonEmpty(), v.url(), v.readonly()),
|
|
});
|
|
|
|
export default defineConfig({
|
|
base: "",
|
|
build: {
|
|
assetsDir: ".",
|
|
emptyOutDir: true,
|
|
/* Génère un fichier manifeste dans outDir */
|
|
manifest: true,
|
|
minify: true,
|
|
outDir: resolve("./web/app/themes/haiku-atelier-2024/assets/js"),
|
|
reportCompressedSize: true,
|
|
rollupOptions: {
|
|
input: await SRC_TYPESCRIPT_PATHS,
|
|
output: {
|
|
assetFileNames: "[name][extname]",
|
|
chunkFileNames: "[name].js",
|
|
compact: true,
|
|
entryFileNames: "[name].js",
|
|
validate: true,
|
|
},
|
|
treeshake: "smallest",
|
|
},
|
|
sourcemap: true,
|
|
target: "es2023",
|
|
watch: { clearScreen: false },
|
|
write: true,
|
|
},
|
|
plugins: [
|
|
/* Permet de valider les variables d'environnements définies à partir d'un schéma Valibot */
|
|
valibot(SCHEMA_ENVIRONNEMENT),
|
|
],
|
|
});
|