mirror of
https://github.com/huntabyte/shadcn-svelte.git
synced 2026-09-14 19:33:46 +08:00
76 lines
2.1 KiB
TypeScript
76 lines
2.1 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { execSync } from "node:child_process";
|
|
import { minimatch } from "minimatch";
|
|
import { defineConfig } from "vite";
|
|
import tailwindcss from "@tailwindcss/vite";
|
|
import { sveltekit } from "@sveltejs/kit/vite";
|
|
import { build } from "./scripts/build-registry.js";
|
|
import { visualizer } from "rollup-plugin-visualizer";
|
|
import { enhancedImages } from "@sveltejs/enhanced-img";
|
|
import packageJson from "./package.json" with { type: "json" };
|
|
|
|
// don't build when we're running `vite preview`
|
|
if (!process.argv.includes("preview")) {
|
|
console.log("Building registry...");
|
|
await buildRegistry();
|
|
console.log("Registry built.");
|
|
}
|
|
|
|
const __dirname = fileURLToPath(new URL(".", import.meta.url));
|
|
export const veliteDirPath = path.join(__dirname, ".velite");
|
|
export const staticDirPath = path.join(__dirname, "src/registry/json");
|
|
export const contentDirPath = path.join(__dirname, "content");
|
|
export const ogDirPath = path.join(__dirname, "src/routes/og");
|
|
|
|
export default defineConfig({
|
|
plugins: [
|
|
visualizer({
|
|
emitFile: true,
|
|
filename: "stats.html",
|
|
}),
|
|
tailwindcss(),
|
|
enhancedImages(),
|
|
sveltekit(),
|
|
{
|
|
name: "registry-builder",
|
|
enforce: "pre",
|
|
async watchChange(id) {
|
|
if (!minimatch(id, "**/src/lib/registry/**")) return;
|
|
this.info("Registry file updated. Rebuilding registry...");
|
|
await buildRegistry();
|
|
this.info("Registry built.");
|
|
},
|
|
},
|
|
],
|
|
server: {
|
|
fs: {
|
|
allow: [veliteDirPath, staticDirPath, contentDirPath, ogDirPath],
|
|
},
|
|
},
|
|
build: {
|
|
// minify: false,
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks: {
|
|
icons: ["@lucide/svelte", "@tabler/icons-svelte"],
|
|
},
|
|
},
|
|
},
|
|
},
|
|
ssr: {
|
|
noExternal: Object.keys(packageJson.devDependencies),
|
|
},
|
|
});
|
|
|
|
async function buildRegistry() {
|
|
await build();
|
|
execSync("pnpm shadcn-svelte registry build --output static/registry", {
|
|
stdio: ["pipe", "pipe", "inherit"],
|
|
});
|
|
fs.cpSync(path.resolve("static", "registry"), path.resolve("src", "__registry__", "json"), {
|
|
recursive: true,
|
|
});
|
|
}
|