vite-intlayer 9.8.2 → 9.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -142,6 +142,7 @@ const intlayerChunk = (intlayerConfig) => {
|
|
|
142
142
|
apply: (_viteConfig, env) => intlayerConfig.build.chunkGrouping && env.command === "build",
|
|
143
143
|
config: () => {
|
|
144
144
|
return { environments: { client: { build: { rolldownOptions: { output: { codeSplitting: { groups: [{
|
|
145
|
+
debugName: "intlayer-dictionaries",
|
|
145
146
|
name: (moduleId, context) => {
|
|
146
147
|
const dictionary = parseDictionaryModule(moduleId);
|
|
147
148
|
if (!dictionary) return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerChunkPlugin.mjs","names":[],"sources":["../../src/intlayerChunkPlugin.ts"],"sourcesContent":["import { DYNAMIC_DICTIONARIES_JSON_SUBDIR } from '@intlayer/config/defaultValues';\nimport { colorizeNumber, getAppLogger } from '@intlayer/config/logger';\nimport { normalizePath } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Plugin } from 'vite';\n\n/**\n * Module-graph accessor Rolldown passes to a chunk-name function.\n *\n * Declared structurally rather than imported from `rolldown` so this plugin\n * keeps working against the Rolldown bundled inside Vite, whose types are not\n * re-exported.\n */\nexport type ChunkingContext = {\n getModuleInfo: (moduleId: string) => ModuleGraphNode | null;\n};\n\nexport type ModuleGraphNode = {\n id: string;\n isEntry: boolean;\n /** Ids of the modules that statically `import` this one. */\n importers: string[];\n /** Ids of the modules that reach this one through `import()`. */\n dynamicImporters: string[];\n};\n\n/** A per-locale dictionary chunk, identified from its module id. */\nexport type DictionaryModule = {\n key: string;\n locale: string;\n};\n\n/**\n * Builds the parser that recognises a per-locale dictionary chunk emitted in\n * `dynamic` import mode.\n *\n * The layout is read relative to `dynamicDictionariesDir` rather than matched\n * anywhere in the path, so an application file that happens to sit under its own\n * `json/<something>/<something>.json` cannot be mistaken for a dictionary.\n * Everything between the key and the locale is a qualifier dimension\n * (collections, variants), which is why the middle segments are skipped instead\n * of being required to be absent.\n *\n * @param dynamicDictionariesDir - Absolute, POSIX-normalized dictionaries root.\n * @returns Parser returning the key and locale, or `null` for any other module.\n */\nexport const createDictionaryModuleParser = (\n dynamicDictionariesDir: string\n): ((moduleId: string) => DictionaryModule | null) => {\n const prefix = `${dynamicDictionariesDir}/${DYNAMIC_DICTIONARIES_JSON_SUBDIR}/`;\n\n return (moduleId) => {\n // Vite appends query suffixes (`?import`, `?url`) to module ids.\n const posixId = normalizePath(moduleId.split('?', 1)[0] ?? moduleId);\n if (!posixId.startsWith(prefix)) return null;\n\n const segments = posixId.slice(prefix.length).split('/');\n // `<key>/…qualifier segments…/<locale>.json` — at least a key and a file.\n if (segments.length < 2) return null;\n\n const fileName = segments[segments.length - 1]!;\n if (!fileName.endsWith('.json')) return null;\n\n return {\n key: segments[0]!,\n locale: fileName.slice(0, -'.json'.length),\n };\n };\n};\n\n/** Characters that are unsafe in a chunk file name. */\nconst UNSAFE_NAME_CHARACTERS = /[^a-zA-Z0-9]+/g;\n\n/**\n * Short, stable digest of a module id, appended to a boundary name so two\n * boundaries sharing a basename (`index.tsx` and `index.tsx`) do not collapse\n * into a single chunk.\n */\nconst digest = (value: string): string => {\n let hash = 5381;\n for (let index = 0; index < value.length; index++) {\n hash = ((hash << 5) + hash + value.charCodeAt(index)) >>> 0;\n }\n return hash.toString(36).slice(0, 6);\n};\n\n/** Turns a boundary module id into a readable chunk-name fragment. */\nexport const toBoundaryName = (moduleId: string): string => {\n const fileName = normalizePath(moduleId).split('/').pop() ?? 'chunk';\n const base = fileName\n .replace(/\\.[^.]+$/, '')\n .replace(UNSAFE_NAME_CHARACTERS, '-')\n .replace(/^-+|-+$/g, '');\n return `${base || 'chunk'}-${digest(moduleId)}`;\n};\n\n/**\n * Walks up the import graph from a dictionary JSON to the code-split boundaries\n * that reach it.\n *\n * A module pulled in through `import()` — a `React.lazy` section, a split\n * route — begins its own chunk, so it is the unit whose dictionaries should\n * travel together: one request per Suspense boundary rather than one per\n * dictionary. The walk deliberately starts from the JSON's importers rather\n * than the JSON itself, because *every* dictionary is reached through\n * `import()` and would otherwise be read as its own boundary.\n *\n * @returns Boundary ids reaching this dictionary, empty when the graph is\n * unavailable (the module was pruned, or resolution failed).\n */\nexport const resolveBoundaries = (\n jsonModuleId: string,\n context: ChunkingContext\n): string[] => {\n const jsonNode = context.getModuleInfo(jsonModuleId);\n if (!jsonNode) return [];\n\n const visited = new Set<string>();\n const boundaries = new Set<string>();\n const queue: string[] = [...jsonNode.dynamicImporters, ...jsonNode.importers];\n\n while (queue.length > 0) {\n const currentId = queue.pop() as string;\n if (visited.has(currentId)) continue;\n visited.add(currentId);\n\n const node = context.getModuleInfo(currentId);\n if (!node) continue;\n\n const isCodeSplitBoundary = node.dynamicImporters.length > 0;\n const isGraphRoot = node.isEntry || node.importers.length === 0;\n\n if (isCodeSplitBoundary || isGraphRoot) {\n boundaries.add(currentId);\n continue;\n }\n\n queue.push(...node.importers);\n }\n\n return [...boundaries].sort();\n};\n\n/**\n * Groups dynamically imported dictionaries by the code-split boundary that\n * consumes them, so each lazily loaded page or section fetches its content in\n * a single request instead of one per dictionary.\n *\n * Without this, `importMode: 'dynamic'` emits a chunk per dictionary per\n * locale. A page assembled from many components then issues dozens of ~3 KB\n * requests, and because each is discovered only once its consumer has\n * executed, they land in the last wave of the request waterfall — page text\n * arrives after everything else.\n *\n * Switching to `importMode: 'static'` would collapse those requests but inline\n * every locale into the bundle, which does not scale past a handful of\n * languages. Grouping keeps the per-locale split and removes the fragmentation.\n *\n * Dictionaries reached from more than one boundary are placed in a shared\n * chunk, so no page ships another page's content and the bytes are not\n * duplicated across chunks.\n *\n * Because a boundary's dictionaries share one chunk, warming that chunk warms\n * the whole boundary in a single request — which is why the top-level-await\n * preload (`intlayerPreload`) costs one request per boundary rather than one\n * per dictionary, without any page loading content belonging to another.\n *\n * @param intlayerConfig - Resolved Intlayer configuration.\n */\nexport const intlayerChunk = (intlayerConfig: IntlayerConfig): Plugin => {\n const dynamicDictionariesDir = normalizePath(\n intlayerConfig.system.dynamicDictionariesDir\n );\n\n const parseDictionaryModule = createDictionaryModuleParser(\n dynamicDictionariesDir\n );\n\n const appLogger = getAppLogger(intlayerConfig);\n\n /** Dictionary modules assigned to each group, for the build summary. */\n const grouped = new Map<string, string[]>();\n /** Dictionaries the graph walk could not attribute to any boundary. */\n const unresolved: string[] = [];\n\n /** Records a dictionary against its group and returns the group name. */\n const assign = (groupName: string, dictionaryKey: string): string => {\n const members = grouped.get(groupName) ?? [];\n members.push(dictionaryKey);\n grouped.set(groupName, members);\n return groupName;\n };\n\n const isDictionaryModule = (moduleId: string): boolean =>\n parseDictionaryModule(moduleId) !== null;\n\n return {\n name: 'vite-intlayer-chunk-plugin',\n\n /**\n * Grouping only exists to undo build-time fragmentation, so the dev server —\n * which serves modules unbundled — is skipped.\n *\n * The build is deliberately *not* gated on the configured `importMode`: a\n * `.content` file can set `importMode: 'dynamic'` on a single dictionary\n * under a `static` or `fetch` global mode, and those dictionaries fragment\n * exactly like a fully dynamic build. Modules that reach the graph are the\n * honest signal, so the group's `test` does the gating instead — it simply\n * matches nothing when no dictionary resolves to dynamic.\n */\n apply: (_viteConfig, env) =>\n intlayerConfig.build.chunkGrouping && env.command === 'build',\n\n config: () => {\n return {\n // Scoped to the client build. Dictionary chunks only exist to be\n // fetched by a browser, and `build` at the top level would apply to\n // every environment — re-chunking the server bundle too, where\n // reordering a dependency's modules can break their initialisation.\n environments: {\n client: {\n build: {\n rolldownOptions: {\n output: {\n codeSplitting: {\n groups: [\n {\n name: (moduleId: string, context: ChunkingContext) => {\n const dictionary = parseDictionaryModule(moduleId);\n if (!dictionary) return null;\n\n const boundaries = resolveBoundaries(\n moduleId,\n context\n );\n if (boundaries.length === 0) {\n unresolved.push(moduleId);\n return null;\n }\n\n const scope =\n boundaries.length > 1\n ? 'shared'\n : toBoundaryName(boundaries[0]!);\n const groupName = `intlayer-${scope}-${dictionary.locale}`;\n\n return assign(groupName, dictionary.key);\n },\n test: isDictionaryModule,\n // Dictionaries are small individually; the point is to\n // group them, so the surrounding build's size floor must\n // not dissolve these chunks back into their parents.\n minSize: 0,\n minShareCount: 1,\n priority: 50,\n },\n ],\n },\n },\n },\n },\n },\n },\n };\n },\n\n /**\n * Reports what the grouping actually did. Silence here means the group\n * never matched — the usual cause is an `importMode` that emits no\n * per-dictionary chunks at all.\n */\n closeBundle() {\n const groupCount = grouped.size;\n if (groupCount === 0 && unresolved.length === 0) return;\n\n const dictionaryCount = [...grouped.values()].reduce(\n (total, members) => total + members.length,\n 0\n );\n\n appLogger(\n `Grouped ${colorizeNumber(dictionaryCount)} dictionary chunks into ${colorizeNumber(groupCount)} per-boundary chunks.`\n );\n\n if (unresolved.length > 0) {\n appLogger(\n `${unresolved.length} dictionaries had no resolvable boundary and kept their own chunk.`,\n { level: 'warn' }\n );\n }\n\n grouped.clear();\n unresolved.length = 0;\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8CA,MAAa,gCACX,2BACoD;CACpD,MAAM,SAAS,GAAG,uBAAuB,GAAG,iCAAiC;CAE7E,QAAQ,aAAa;EAEnB,MAAM,UAAU,cAAc,SAAS,MAAM,KAAK,CAAC,CAAC,CAAC,MAAM,QAAQ;EACnE,IAAI,CAAC,QAAQ,WAAW,MAAM,GAAG,OAAO;EAExC,MAAM,WAAW,QAAQ,MAAM,OAAO,MAAM,CAAC,CAAC,MAAM,GAAG;EAEvD,IAAI,SAAS,SAAS,GAAG,OAAO;EAEhC,MAAM,WAAW,SAAS,SAAS,SAAS;EAC5C,IAAI,CAAC,SAAS,SAAS,OAAO,GAAG,OAAO;EAExC,OAAO;GACL,KAAK,SAAS;GACd,QAAQ,SAAS,MAAM,GAAG,EAAe;EAC3C;CACF;AACF;;AAGA,MAAM,yBAAyB;;;;;;AAO/B,MAAM,UAAU,UAA0B;CACxC,IAAI,OAAO;CACX,K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E,GAAG,WAAW,OAAO,qEACrB,EAAE,OAAO,OAAO,CAClB;GAGF,QAAQ,MAAM;GACd,WAAW,SAAS;EACtB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"intlayerChunkPlugin.mjs","names":[],"sources":["../../src/intlayerChunkPlugin.ts"],"sourcesContent":["import { DYNAMIC_DICTIONARIES_JSON_SUBDIR } from '@intlayer/config/defaultValues';\nimport { colorizeNumber, getAppLogger } from '@intlayer/config/logger';\nimport { normalizePath } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types/config';\nimport type { Plugin } from 'vite';\n\n/**\n * Module-graph accessor Rolldown passes to a chunk-name function.\n *\n * Declared structurally rather than imported from `rolldown` so this plugin\n * keeps working against the Rolldown bundled inside Vite, whose types are not\n * re-exported.\n */\nexport type ChunkingContext = {\n getModuleInfo: (moduleId: string) => ModuleGraphNode | null;\n};\n\nexport type ModuleGraphNode = {\n id: string;\n isEntry: boolean;\n /** Ids of the modules that statically `import` this one. */\n importers: string[];\n /** Ids of the modules that reach this one through `import()`. */\n dynamicImporters: string[];\n};\n\n/** A per-locale dictionary chunk, identified from its module id. */\nexport type DictionaryModule = {\n key: string;\n locale: string;\n};\n\n/**\n * Builds the parser that recognises a per-locale dictionary chunk emitted in\n * `dynamic` import mode.\n *\n * The layout is read relative to `dynamicDictionariesDir` rather than matched\n * anywhere in the path, so an application file that happens to sit under its own\n * `json/<something>/<something>.json` cannot be mistaken for a dictionary.\n * Everything between the key and the locale is a qualifier dimension\n * (collections, variants), which is why the middle segments are skipped instead\n * of being required to be absent.\n *\n * @param dynamicDictionariesDir - Absolute, POSIX-normalized dictionaries root.\n * @returns Parser returning the key and locale, or `null` for any other module.\n */\nexport const createDictionaryModuleParser = (\n dynamicDictionariesDir: string\n): ((moduleId: string) => DictionaryModule | null) => {\n const prefix = `${dynamicDictionariesDir}/${DYNAMIC_DICTIONARIES_JSON_SUBDIR}/`;\n\n return (moduleId) => {\n // Vite appends query suffixes (`?import`, `?url`) to module ids.\n const posixId = normalizePath(moduleId.split('?', 1)[0] ?? moduleId);\n if (!posixId.startsWith(prefix)) return null;\n\n const segments = posixId.slice(prefix.length).split('/');\n // `<key>/…qualifier segments…/<locale>.json` — at least a key and a file.\n if (segments.length < 2) return null;\n\n const fileName = segments[segments.length - 1]!;\n if (!fileName.endsWith('.json')) return null;\n\n return {\n key: segments[0]!,\n locale: fileName.slice(0, -'.json'.length),\n };\n };\n};\n\n/** Characters that are unsafe in a chunk file name. */\nconst UNSAFE_NAME_CHARACTERS = /[^a-zA-Z0-9]+/g;\n\n/**\n * Short, stable digest of a module id, appended to a boundary name so two\n * boundaries sharing a basename (`index.tsx` and `index.tsx`) do not collapse\n * into a single chunk.\n */\nconst digest = (value: string): string => {\n let hash = 5381;\n for (let index = 0; index < value.length; index++) {\n hash = ((hash << 5) + hash + value.charCodeAt(index)) >>> 0;\n }\n return hash.toString(36).slice(0, 6);\n};\n\n/** Turns a boundary module id into a readable chunk-name fragment. */\nexport const toBoundaryName = (moduleId: string): string => {\n const fileName = normalizePath(moduleId).split('/').pop() ?? 'chunk';\n const base = fileName\n .replace(/\\.[^.]+$/, '')\n .replace(UNSAFE_NAME_CHARACTERS, '-')\n .replace(/^-+|-+$/g, '');\n return `${base || 'chunk'}-${digest(moduleId)}`;\n};\n\n/**\n * Walks up the import graph from a dictionary JSON to the code-split boundaries\n * that reach it.\n *\n * A module pulled in through `import()` — a `React.lazy` section, a split\n * route — begins its own chunk, so it is the unit whose dictionaries should\n * travel together: one request per Suspense boundary rather than one per\n * dictionary. The walk deliberately starts from the JSON's importers rather\n * than the JSON itself, because *every* dictionary is reached through\n * `import()` and would otherwise be read as its own boundary.\n *\n * @returns Boundary ids reaching this dictionary, empty when the graph is\n * unavailable (the module was pruned, or resolution failed).\n */\nexport const resolveBoundaries = (\n jsonModuleId: string,\n context: ChunkingContext\n): string[] => {\n const jsonNode = context.getModuleInfo(jsonModuleId);\n if (!jsonNode) return [];\n\n const visited = new Set<string>();\n const boundaries = new Set<string>();\n const queue: string[] = [...jsonNode.dynamicImporters, ...jsonNode.importers];\n\n while (queue.length > 0) {\n const currentId = queue.pop() as string;\n if (visited.has(currentId)) continue;\n visited.add(currentId);\n\n const node = context.getModuleInfo(currentId);\n if (!node) continue;\n\n const isCodeSplitBoundary = node.dynamicImporters.length > 0;\n const isGraphRoot = node.isEntry || node.importers.length === 0;\n\n if (isCodeSplitBoundary || isGraphRoot) {\n boundaries.add(currentId);\n continue;\n }\n\n queue.push(...node.importers);\n }\n\n return [...boundaries].sort();\n};\n\n/**\n * Groups dynamically imported dictionaries by the code-split boundary that\n * consumes them, so each lazily loaded page or section fetches its content in\n * a single request instead of one per dictionary.\n *\n * Without this, `importMode: 'dynamic'` emits a chunk per dictionary per\n * locale. A page assembled from many components then issues dozens of ~3 KB\n * requests, and because each is discovered only once its consumer has\n * executed, they land in the last wave of the request waterfall — page text\n * arrives after everything else.\n *\n * Switching to `importMode: 'static'` would collapse those requests but inline\n * every locale into the bundle, which does not scale past a handful of\n * languages. Grouping keeps the per-locale split and removes the fragmentation.\n *\n * Dictionaries reached from more than one boundary are placed in a shared\n * chunk, so no page ships another page's content and the bytes are not\n * duplicated across chunks.\n *\n * Because a boundary's dictionaries share one chunk, warming that chunk warms\n * the whole boundary in a single request — which is why the top-level-await\n * preload (`intlayerPreload`) costs one request per boundary rather than one\n * per dictionary, without any page loading content belonging to another.\n *\n * @param intlayerConfig - Resolved Intlayer configuration.\n */\nexport const intlayerChunk = (intlayerConfig: IntlayerConfig): Plugin => {\n const dynamicDictionariesDir = normalizePath(\n intlayerConfig.system.dynamicDictionariesDir\n );\n\n const parseDictionaryModule = createDictionaryModuleParser(\n dynamicDictionariesDir\n );\n\n const appLogger = getAppLogger(intlayerConfig);\n\n /** Dictionary modules assigned to each group, for the build summary. */\n const grouped = new Map<string, string[]>();\n /** Dictionaries the graph walk could not attribute to any boundary. */\n const unresolved: string[] = [];\n\n /** Records a dictionary against its group and returns the group name. */\n const assign = (groupName: string, dictionaryKey: string): string => {\n const members = grouped.get(groupName) ?? [];\n members.push(dictionaryKey);\n grouped.set(groupName, members);\n return groupName;\n };\n\n const isDictionaryModule = (moduleId: string): boolean =>\n parseDictionaryModule(moduleId) !== null;\n\n return {\n name: 'vite-intlayer-chunk-plugin',\n\n /**\n * Grouping only exists to undo build-time fragmentation, so the dev server —\n * which serves modules unbundled — is skipped.\n *\n * The build is deliberately *not* gated on the configured `importMode`: a\n * `.content` file can set `importMode: 'dynamic'` on a single dictionary\n * under a `static` or `fetch` global mode, and those dictionaries fragment\n * exactly like a fully dynamic build. Modules that reach the graph are the\n * honest signal, so the group's `test` does the gating instead — it simply\n * matches nothing when no dictionary resolves to dynamic.\n */\n apply: (_viteConfig, env) =>\n intlayerConfig.build.chunkGrouping && env.command === 'build',\n\n config: () => {\n return {\n // Scoped to the client build. Dictionary chunks only exist to be\n // fetched by a browser, and `build` at the top level would apply to\n // every environment — re-chunking the server bundle too, where\n // reordering a dependency's modules can break their initialisation.\n environments: {\n client: {\n build: {\n rolldownOptions: {\n output: {\n codeSplitting: {\n groups: [\n {\n // `name` is a function, so Rolldown needs a static\n // label for its bundler timing report.\n debugName: 'intlayer-dictionaries',\n name: (moduleId: string, context: ChunkingContext) => {\n const dictionary = parseDictionaryModule(moduleId);\n if (!dictionary) return null;\n\n const boundaries = resolveBoundaries(\n moduleId,\n context\n );\n if (boundaries.length === 0) {\n unresolved.push(moduleId);\n return null;\n }\n\n const scope =\n boundaries.length > 1\n ? 'shared'\n : toBoundaryName(boundaries[0]!);\n const groupName = `intlayer-${scope}-${dictionary.locale}`;\n\n return assign(groupName, dictionary.key);\n },\n test: isDictionaryModule,\n // Dictionaries are small individually; the point is to\n // group them, so the surrounding build's size floor must\n // not dissolve these chunks back into their parents.\n minSize: 0,\n minShareCount: 1,\n priority: 50,\n },\n ],\n },\n },\n },\n },\n },\n },\n };\n },\n\n /**\n * Reports what the grouping actually did. Silence here means the group\n * never matched — the usual cause is an `importMode` that emits no\n * per-dictionary chunks at all.\n */\n closeBundle() {\n const groupCount = grouped.size;\n if (groupCount === 0 && unresolved.length === 0) return;\n\n const dictionaryCount = [...grouped.values()].reduce(\n (total, members) => total + members.length,\n 0\n );\n\n appLogger(\n `Grouped ${colorizeNumber(dictionaryCount)} dictionary chunks into ${colorizeNumber(groupCount)} per-boundary chunks.`\n );\n\n if (unresolved.length > 0) {\n appLogger(\n `${unresolved.length} dictionaries had no resolvable boundary and kept their own chunk.`,\n { level: 'warn' }\n );\n }\n\n grouped.clear();\n unresolved.length = 0;\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA8CA,MAAa,gCACX,2BACoD;CACpD,MAAM,SAAS,GAAG,uBAAuB,GAAG,iCAAiC;CAE7E,QAAQ,aAAa;EAEnB,MAAM,UAAU,cAAc,SAAS,MAAM,KAAK,CAAC,CAAC,CAAC,MAAM,QAAQ;EACnE,IAAI,CAAC,QAAQ,WAAW,MAAM,GAAG,OAAO;EAExC,MAAM,WAAW,QAAQ,MAAM,OAAO,MAAM,CAAC,CAAC,MAAM,GAAG;EAEvD,IAAI,SAAS,SAAS,GAAG,OAAO;EAEhC,MAAM,WAAW,SAAS,SAAS,SAAS;EAC5C,IAAI,CAAC,SAAS,SAAS,OAAO,GAAG,OAAO;EAExC,OAAO;GACL,KAAK,SAAS;GACd,QAAQ,SAAS,MAAM,GAAG,EAAe;EAC3C;CACF;AACF;;AAGA,MAAM,yBAAyB;;;;;;AAO/B,MAAM,UAAU,UAA0B;CACxC,IAAI,OAAO;CACX,KAAK,IAAI,QAAQ,GAAG,QAAQ,MAAM,QAAQ,SACxC,QAAS,QAAQ,KAAK,OAAO,MAAM,WAAW,KAAK,MAAO;CAE5D,OAAO,KAAK,SAAS,EAAE,CAAC,CAAC,MAAM,GAAG,CAAC;AACrC;;AAGA,MAAa,kBAAkB,aAA6B;CAM1D,OAAO,IALU,cAAc,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,KAAK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
5
|
"description": "A Vite plugin for seamless internationalization (i18n), providing locale detection, redirection, and environment-based configuration",
|
|
6
6
|
"keywords": [
|
|
@@ -87,12 +87,12 @@
|
|
|
87
87
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
|
-
"@intlayer/babel": "9.8.
|
|
91
|
-
"@intlayer/config": "9.8.
|
|
92
|
-
"@intlayer/core": "9.8.
|
|
93
|
-
"@intlayer/dictionaries-entry": "9.8.
|
|
94
|
-
"@intlayer/engine": "9.8.
|
|
95
|
-
"@intlayer/types": "9.8.
|
|
90
|
+
"@intlayer/babel": "9.8.4",
|
|
91
|
+
"@intlayer/config": "9.8.4",
|
|
92
|
+
"@intlayer/core": "9.8.4",
|
|
93
|
+
"@intlayer/dictionaries-entry": "9.8.4",
|
|
94
|
+
"@intlayer/engine": "9.8.4",
|
|
95
|
+
"@intlayer/types": "9.8.4"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
98
|
"@types/node": "^26",
|
|
@@ -106,8 +106,8 @@
|
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
108
|
"@babel/core": ">=6.0.0",
|
|
109
|
-
"@intlayer/svelte-compiler": "9.8.
|
|
110
|
-
"@intlayer/vue-compiler": "9.8.
|
|
109
|
+
"@intlayer/svelte-compiler": "9.8.4",
|
|
110
|
+
"@intlayer/vue-compiler": "9.8.4",
|
|
111
111
|
"h3": ">=1.0.0",
|
|
112
112
|
"vite": ">=4.0.0"
|
|
113
113
|
},
|