This commit is contained in:
2025-12-08 09:47:31 +07:00
parent 1dbf988073
commit 603d024af3
5 changed files with 36 additions and 210 deletions

View File

@@ -1,71 +1,24 @@
import { defineConfig } from "vite"
import injectHTML from "vite-plugin-html-inject"
import { resolve } from "node:path"
import fs from "node:fs"
import tailwindcss from "@tailwindcss/vite"
import { fileURLToPath } from "node:url"
const __dirname = fileURLToPath(new URL(".", import.meta.url))
const getHtmlFiles = (dir: string): string[] => {
let results: string[] = []
const list = fs.readdirSync(dir)
list.forEach((file) => {
file = resolve(dir, file)
const stat = fs.statSync(file)
if (stat && stat.isDirectory()) {
if (file.endsWith("/partials")) {
return
}
results = results.concat(getHtmlFiles(file))
} else if (file.endsWith(".html")) {
results.push(file)
}
})
return results
}
// Normalize the paths to ensure consistent forward slashes
const normalizePath = (path: string): string => path.split(resolve(__dirname, "src")).join("").replace(/\\/g, "/")
// Use normalizePath function to process the paths correctly
const htmlFiles = getHtmlFiles("src")
const input = Object.fromEntries(
htmlFiles.map((file) => [normalizePath(file).replace(".html", "").replace(/^\//, ""), file])
)
const removecors = () => {
return {
name: "remove-cors",
transformIndexHtml: {
order: "post" as const,
handler(html: string) {
return html.replace(/crossorigin\s*/g, "")
},
},
}
}
export default defineConfig({
base: "",
server: {
open: "/",
},
publicDir: "../public",
plugins: [injectHTML(), removecors(), tailwindcss()],
root: "src",
optimizeDeps: {
include: ["filepond", "filepond-plugin-image-preview"],
},
build: {
outDir: "../html",
emptyOutDir: true,
lib: {
entry: {
global: resolve(__dirname, "assets/typescript/main.ts"),
},
formats: ["es"],
fileName: (format, entryName) => `${entryName}.js`,
},
outDir: "assets/script",
emptyOutDir: false,
rollupOptions: {
input,
output: {
entryFileNames: `assets/script/[name].js`,
chunkFileNames: `assets/script/[name].js`,
assetFileNames: `assets/script/[name].[ext]`,
dir: "assets/script",
entryFileNames: "[name].js",
},
},
},