Отключать все обработки Vite
Описание
Мне понадобился компилятор и линкер для Node модулей на Front-end, и мне посоветовали Vite. Я решил его попробовать... В целом, он справляется с компиляцией и подключением модулей, что неплохо. Однако он делает много лишнего: меняет пути, компилирует изображения, создает новые папки и превращает мою многослойную структуру в плоскую.
Кому-то это может показаться удобным, но мне это ломает все расчеты и пути. Если в режиме разработки все работает прекрасно, то после компиляции возникает полная неразбериха.
Мне нужно настроить его так, чтобы он просто копировал всю структуру, компилируя файлы TS в файлы JS с сохранением прежних имен, то есть создавал абсолютную копию.
"use strict";
import "adaptive-extender/node";
import { defineConfig } from "vite";
import { viteStaticCopy, type Target } from "vite-plugin-static-copy";
import FileSystem from "fs";
const input: Record<string, string> = {
["main"]: "index.html",
["feed/index"]: "feed/index.html",
["applications/209-birthdays/index"]: "applications/209-birthdays/index.html",
["shortcuts/vscode-quartz/index"]: "shortcuts/vscode-quartz/index.html",
// ["404/index"]: "404/index.html",
};
function collectStaticFiles(dir: string, baseDir: string = ""): Target[] {
const ignoreList = ["node_modules", "dist", ".git", ".vscode", ".idea", "types"];
const results: Target[] = [];
try {
const items = FileSystem.readdirSync(dir);
for (const item of items) {
if (ignoreList.includes(item)) continue;
if (item === "vite.config.ts") continue;
if (item === "tsconfig.json") continue;
if (item.startsWith("package")) continue;
if (item.startsWith(".")) continue;
const fullPath = baseDir ? `${dir}/${item}` : item;
const isDirectory = FileSystem.statSync(fullPath).isDirectory();
if (isDirectory) {
results.push(...collectStaticFiles(fullPath, fullPath));
} else {
const isViteFile = item.endsWith(".ts") || item.endsWith(".html");
if (!isViteFile) {
const destFolder = baseDir || ".";
results.push({ src: fullPath, dest: destFolder });
}
}
}
} catch (e) {
console.error(`Error scanning directory ${dir}:`, e);
}
return results;
}
export default defineConfig(({ command }) => {
const isBuild = command === 'build';
const copyTargets = collectStaticFiles(".");
return {
publicDir: false,
base: "/",
build: {
outDir: "dist",
emptyOutDir: true,
rollupOptions: {
preserveEntrySignatures: "strict",
input,
output: {
preserveModules: true,
entryFileNames: "[name].js",
chunkFileNames: "chunks/[name].js",
assetFileNames: "assets/[name][extname]",
},
},
},
plugins: [
isBuild ? viteStaticCopy({
targets: copyTargets
}) : undefined,
],
};
});
Вопрос
Не могу я его вот так настроить.
Поможете?
Или может есть более хорошие и простые инструменты для этого дела?