75 lines
1.9 KiB
TypeScript
75 lines
1.9 KiB
TypeScript
import { defineConfig, UserConfigExport } from "vite";
|
|
import vue from "@vitejs/plugin-vue";
|
|
import { resolve } from "node:path";
|
|
import { map } from "lodash";
|
|
import { existsSync, fstat, readFileSync } from "node:fs";
|
|
|
|
type ExportKey = "ingame" | "ingame_vue";
|
|
type BuildExports = Record<ExportKey, Record<string, string>>;
|
|
|
|
// https://vitejs.dev/config/
|
|
export default defineConfig(({ mode }) => {
|
|
const target = (()=>{
|
|
if(mode === "production" || mode === 'development'){
|
|
return "hwe";
|
|
}
|
|
if(existsSync(mode)){
|
|
return mode;
|
|
}
|
|
throw `invalid mode: ${mode}`;
|
|
})();
|
|
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": `${target}/scss/`,
|
|
"@util": resolve(tsDir, `util`),
|
|
},
|
|
},
|
|
plugins: [vue()],
|
|
publicDir: false,
|
|
server: {
|
|
middlewareMode: "html",
|
|
}
|
|
};
|
|
|
|
return config;
|
|
});
|