Files
vite_front/vite.config.ts
T
2022-07-09 19:48:50 +09:00

63 lines
1.7 KiB
TypeScript

import { defineConfig, UserConfigExport } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "node:path";
import { map } from "lodash";
import { existsSync, readFileSync } from "node:fs";
type ExportKey = "ingame" | "ingame_vue";
type BuildExports = Record<ExportKey, Record<string, string>>;
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
const target = "hwe"; //방법이 있나?
const tsDir = resolve(__dirname, `${target}/ts/`);
const build_exports: BuildExports = require(`${tsDir}/build_exports.json`);
const asset_map: Record<string, string> = {};
for (const [key, value] of Object.entries(build_exports.ingame_vue)) {
asset_map[key] = `${tsDir}/${value}`;
}
for (const [key, value] of Object.entries(build_exports.ingame)) {
asset_map[key] = `${tsDir}/${value}`;
}
const versionGitPath = resolve(
__dirname,
target,
"d_setting",
"VersionGit.json"
);
const versionValue = (() => {
if (!existsSync(versionGitPath)) {
return undefined;
}
const versionInfo = JSON.parse(readFileSync(versionGitPath, "utf-8"));
return versionInfo.versionGit;
})();
const versionTarget = versionValue ?? `${target}_dynamic`;
const outputPath = resolve(__dirname, 'dist_js', versionTarget);
const config: UserConfigExport = {
build: {
rollupOptions: {
input: asset_map,
},
outDir: outputPath,
assetsDir: 'assets',
manifest: true,
},
resolve: {
alias: {
"@": tsDir,
"@scss": resolve(__dirname, `${target}/scss/`),
"@util": resolve(tsDir, `util`),
},
},
plugins: [vue()],
};
return config;
});