Skip to content

Commit

Permalink
build: separate lang modules
Browse files Browse the repository at this point in the history
  • Loading branch information
StarHeartHunt committed Dec 2, 2023
1 parent 2ec016a commit 43c5acd
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { readdirSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { dirname, join, resolve, parse } from "node:path";
import { fileURLToPath } from "node:url";

import legacy from "@vitejs/plugin-legacy";
import vue from "@vitejs/plugin-vue";
import { visualizer } from "rollup-plugin-visualizer";
import UnoCSS from "unocss/vite";
import { defineConfig } from "vite";

const TARGET = ["chrome70", "edge81", "firefox70", "safari12", "ios12"];
const TARGET_LANG = new Set(["enUS", "jaJP", "koKR", "zhCN", "zhTW"]);

const entries = readdirSync(
join(dirname(fileURLToPath(import.meta.url)), "src/entries/"),
);
Expand All @@ -16,6 +19,7 @@ const input: Record<string, string> = {};
for (const entry of entries) {
input[entry.replace(".ts", "")] = `src/entries/${entry}`;
}

// https://vitejs.dev/config/
export default defineConfig({
resolve: {
Expand Down Expand Up @@ -51,6 +55,10 @@ export default defineConfig({
sourcemapBaseUrl: "https://static.prts.wiki/widgets/release/",
manualChunks(id) {
if (id.includes("sentry")) return "sentry";
if (id.includes("naive-ui/es/locales/")) {
const lang = parse(id).name;
if (TARGET_LANG.has(lang)) return `locales-${lang}`;
}
if (id.includes("naive-ui")) return "naive-ui";
if (id.includes("hammer")) return;
if (id.includes("node_modules")) return "vendor";
Expand Down

0 comments on commit 43c5acd

Please sign in to comment.