diff --git a/packages/vite-plugin/dist/index.js b/packages/vite-plugin/dist/index.js index 11e8215..a5d27ee 100644 --- a/packages/vite-plugin/dist/index.js +++ b/packages/vite-plugin/dist/index.js @@ -1815,6 +1815,23 @@ if (typeof window !== 'undefined') { "/": "-slash-", ":": "-colon-", }; + /** + * 特殊字符映射表(国际化) + */ + const SAFE_CHAR_MAP_LOCALE = { + "[": "-bracket-start-", + "]": "-bracket-end-", + "(": "-paren-start-", + ")": "-paren-end-", + "{": "-brace-start-", + "}": "-brace-end-", + $: "-dollar-", + "#": "-hash-", + "!": "-important-", + "/": "-slash-", + ":": "-colon-", + " ": "-space-", + }; // @ts-ignore /** @@ -2146,9 +2163,9 @@ if (typeof window !== 'undefined') { if (id.includes("/cool/ctx/index.ts")) { const ctx = await createCtx(); const theme = await readFile(rootDir("theme.json"), true); - ctx["SAFE_CHAR_MAP"] = []; - for (const i in SAFE_CHAR_MAP) { - ctx["SAFE_CHAR_MAP"].push([i, SAFE_CHAR_MAP[i]]); + ctx["SAFE_CHAR_MAP_LOCALE"] = []; + for (const i in SAFE_CHAR_MAP_LOCALE) { + ctx["SAFE_CHAR_MAP_LOCALE"].push([i, SAFE_CHAR_MAP_LOCALE[i]]); } ctx["theme"] = theme; code = code.replace("const ctx = {}", `const ctx = ${JSON.stringify(ctx, null, 4)}`); @@ -2168,8 +2185,8 @@ if (typeof window !== 'undefined') { const d = JSON.parse(code); for (let i in d) { let k = i; - for (let j in SAFE_CHAR_MAP) { - k = k.replaceAll(j, SAFE_CHAR_MAP[j]); + for (let j in SAFE_CHAR_MAP_LOCALE) { + k = k.replaceAll(j, SAFE_CHAR_MAP_LOCALE[j]); } if (k != i) { d[k] = d[i]; diff --git a/packages/vite-plugin/dist/uniapp-x/config.d.ts b/packages/vite-plugin/dist/uniapp-x/config.d.ts index bbe38b4..3d46074 100644 --- a/packages/vite-plugin/dist/uniapp-x/config.d.ts +++ b/packages/vite-plugin/dist/uniapp-x/config.d.ts @@ -2,3 +2,7 @@ * 特殊字符映射表 */ export declare const SAFE_CHAR_MAP: Record; +/** + * 特殊字符映射表(国际化) + */ +export declare const SAFE_CHAR_MAP_LOCALE: Record; diff --git a/packages/vite-plugin/src/uniapp-x/code.ts b/packages/vite-plugin/src/uniapp-x/code.ts index f54f6c6..92c8905 100644 --- a/packages/vite-plugin/src/uniapp-x/code.ts +++ b/packages/vite-plugin/src/uniapp-x/code.ts @@ -1,11 +1,9 @@ import type { Plugin } from "vite"; -import { SAFE_CHAR_MAP } from "./config"; +import { SAFE_CHAR_MAP_LOCALE } from "./config"; import { createCtx } from "../ctx"; import { readFile, rootDir } from "../utils"; import { createEps } from "../eps"; -import { isEmpty, uniq } from "lodash"; -import { config } from "../config"; -import axios from "axios"; +import { uniq } from "lodash"; export function codePlugin(): Plugin[] { return [ @@ -17,9 +15,9 @@ export function codePlugin(): Plugin[] { const ctx = await createCtx(); const theme = await readFile(rootDir("theme.json"), true); - ctx["SAFE_CHAR_MAP"] = []; - for (const i in SAFE_CHAR_MAP) { - ctx["SAFE_CHAR_MAP"].push([i, SAFE_CHAR_MAP[i]]); + ctx["SAFE_CHAR_MAP_LOCALE"] = []; + for (const i in SAFE_CHAR_MAP_LOCALE) { + ctx["SAFE_CHAR_MAP_LOCALE"].push([i, SAFE_CHAR_MAP_LOCALE[i]]); } ctx["theme"] = theme; @@ -50,8 +48,8 @@ export function codePlugin(): Plugin[] { for (let i in d) { let k = i; - for (let j in SAFE_CHAR_MAP) { - k = k.replaceAll(j, SAFE_CHAR_MAP[j]); + for (let j in SAFE_CHAR_MAP_LOCALE) { + k = k.replaceAll(j, SAFE_CHAR_MAP_LOCALE[j]); } if (k != i) { diff --git a/packages/vite-plugin/src/uniapp-x/config.ts b/packages/vite-plugin/src/uniapp-x/config.ts index dbdbfed..954ad71 100644 --- a/packages/vite-plugin/src/uniapp-x/config.ts +++ b/packages/vite-plugin/src/uniapp-x/config.ts @@ -14,3 +14,21 @@ export const SAFE_CHAR_MAP: Record = { "/": "-slash-", ":": "-colon-", }; + +/** + * 特殊字符映射表(国际化) + */ +export const SAFE_CHAR_MAP_LOCALE: Record = { + "[": "-bracket-start-", + "]": "-bracket-end-", + "(": "-paren-start-", + ")": "-paren-end-", + "{": "-brace-start-", + "}": "-brace-end-", + $: "-dollar-", + "#": "-hash-", + "!": "-important-", + "/": "-slash-", + ":": "-colon-", + " ": "-space-", +};