@intlify/unplugin-vue-i18n 0.8.2 → 0.9.0
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.
- package/README.md +25 -0
- package/lib/index.cjs +58 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.mjs +59 -3
- package/lib/vite.d.ts +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -213,6 +213,20 @@ const app = createApp()
|
|
|
213
213
|
app.use(i18n).mount('#app')
|
|
214
214
|
```
|
|
215
215
|
|
|
216
|
+
Change your vite.config.ts file accordingly to import all the files from locales folder on the root. Change `'./locales/**'` to path of your locales.
|
|
217
|
+
```ts
|
|
218
|
+
// vite.config.ts
|
|
219
|
+
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
|
|
220
|
+
import path from 'path'
|
|
221
|
+
|
|
222
|
+
export default defineConfig({
|
|
223
|
+
plugins: [
|
|
224
|
+
VueI18nPlugin({
|
|
225
|
+
include: [path.resolve(__dirname, './locales/**')],
|
|
226
|
+
}),
|
|
227
|
+
],
|
|
228
|
+
})
|
|
229
|
+
```
|
|
216
230
|
### Types
|
|
217
231
|
|
|
218
232
|
If you want type definition of `@intlify/unplugin-vue-i18n/messages`, add `unplugin-vue-i18n/messages` to `compilerOptions.types` of your tsconfig:
|
|
@@ -259,10 +273,21 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
|
|
|
259
273
|
- json5
|
|
260
274
|
- yaml
|
|
261
275
|
- yml
|
|
276
|
+
- js
|
|
277
|
+
- ts
|
|
262
278
|
```
|
|
263
279
|
|
|
264
280
|
Note `json` resources matches this option, it will be handled **before the internal json plugin of bundler, and will not be processed afterwards**, else the option doesn't match, the bundler side will handle.
|
|
265
281
|
|
|
282
|
+
Note that `js` and `ts` resources are limited to **simple export (`export default`) as locale messages object only**, such as programmatically dynamic resource construction is not guaranteed to work currently.
|
|
283
|
+
|
|
284
|
+
```js
|
|
285
|
+
export default {
|
|
286
|
+
hello: 'Hello, {name}!',
|
|
287
|
+
// ...
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
266
291
|
If nothing is specified for this option, i.e. `undefined`, nothing is done to the resource in the above format.
|
|
267
292
|
|
|
268
293
|
### `runtimeOnly`
|
package/lib/index.cjs
CHANGED
|
@@ -223,6 +223,59 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
223
223
|
return orgTransform.apply(this, [code, id]);
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
+
const esbuildPlugin = config.plugins.find(
|
|
227
|
+
(p) => p.name === "vite:esbuild"
|
|
228
|
+
);
|
|
229
|
+
if (esbuildPlugin) {
|
|
230
|
+
const orgTransform = esbuildPlugin.transform;
|
|
231
|
+
esbuildPlugin.transform = async function(code, id) {
|
|
232
|
+
const result = await orgTransform.apply(this, [
|
|
233
|
+
code,
|
|
234
|
+
id
|
|
235
|
+
]);
|
|
236
|
+
if (result == null) {
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
const { filename, query } = parseVueRequest(id);
|
|
240
|
+
if (!query.vue && filter(id) && /\.[c|m]?ts$/.test(id)) {
|
|
241
|
+
const [_code, inSourceMap] = shared.isString(result) ? [result, void 0] : [result.code, result.map];
|
|
242
|
+
let langInfo = defaultSFCLang;
|
|
243
|
+
langInfo = pathe.parse(filename).ext;
|
|
244
|
+
const generate = getGenerator(langInfo);
|
|
245
|
+
const parseOptions = getOptions(
|
|
246
|
+
filename,
|
|
247
|
+
isProduction,
|
|
248
|
+
query,
|
|
249
|
+
sourceMap,
|
|
250
|
+
{
|
|
251
|
+
inSourceMap,
|
|
252
|
+
isGlobal: globalSFCScope,
|
|
253
|
+
useClassComponent,
|
|
254
|
+
bridge,
|
|
255
|
+
exportESM: esm,
|
|
256
|
+
forceStringify
|
|
257
|
+
}
|
|
258
|
+
);
|
|
259
|
+
debug("parseOptions", parseOptions);
|
|
260
|
+
const { code: generatedCode, map } = generate(
|
|
261
|
+
_code,
|
|
262
|
+
parseOptions,
|
|
263
|
+
bridge ? createBridgeCodeGenerator(_code, query) : void 0
|
|
264
|
+
);
|
|
265
|
+
debug("generated code", generatedCode);
|
|
266
|
+
console.log("generated code", generatedCode);
|
|
267
|
+
debug("sourcemap", map, sourceMap);
|
|
268
|
+
if (_code === generatedCode)
|
|
269
|
+
return;
|
|
270
|
+
return {
|
|
271
|
+
code: generatedCode,
|
|
272
|
+
map: sourceMap ? map : { mappings: "" }
|
|
273
|
+
};
|
|
274
|
+
} else {
|
|
275
|
+
return result;
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
}
|
|
226
279
|
},
|
|
227
280
|
async handleHotUpdate({ file, server }) {
|
|
228
281
|
if (/\.(json5?|ya?ml)$/.test(file)) {
|
|
@@ -346,9 +399,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
346
399
|
let langInfo = defaultSFCLang;
|
|
347
400
|
let inSourceMap;
|
|
348
401
|
if (!query.vue) {
|
|
349
|
-
if (/\.(json5?|ya?ml)$/.test(id) && filter(id)) {
|
|
402
|
+
if (/\.(json5?|ya?ml|[c|m]?js)$/.test(id) && filter(id)) {
|
|
350
403
|
langInfo = pathe.parse(filename).ext;
|
|
351
|
-
const generate =
|
|
404
|
+
const generate = getGenerator(langInfo);
|
|
352
405
|
const parseOptions = getOptions(
|
|
353
406
|
filename,
|
|
354
407
|
isProduction,
|
|
@@ -427,6 +480,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
427
480
|
}
|
|
428
481
|
};
|
|
429
482
|
});
|
|
483
|
+
function getGenerator(ext, defaultGen = bundleUtils.generateJSON) {
|
|
484
|
+
return /\.?json5?$/.test(ext) ? bundleUtils.generateJSON : /\.ya?ml$/.test(ext) ? bundleUtils.generateYAML : /\.([c|m]?js|[c|m]?ts)$/.test(ext) ? bundleUtils.generateJavaScript : defaultGen;
|
|
485
|
+
}
|
|
430
486
|
function normalizeConfigResolveAlias(resolve, framework) {
|
|
431
487
|
if (resolve && resolve.alias) {
|
|
432
488
|
return resolve;
|
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import * as _unplugin from 'unplugin';
|
|
|
2
2
|
import { PluginOptions } from './types.js';
|
|
3
3
|
export { PluginOptions, SFCLangFormat } from './types.js';
|
|
4
4
|
|
|
5
|
-
declare const unplugin: _unplugin.UnpluginInstance<PluginOptions,
|
|
5
|
+
declare const unplugin: _unplugin.UnpluginInstance<PluginOptions, boolean>;
|
|
6
6
|
|
|
7
7
|
export { unplugin as default, unplugin };
|
package/lib/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import createDebug from 'debug';
|
|
|
4
4
|
import fg from 'fast-glob';
|
|
5
5
|
import { isString, isArray, isBoolean, isObject, isNumber, isEmptyObject, assign, generateCodeFrame } from '@intlify/shared';
|
|
6
6
|
import { createFilter } from '@rollup/pluginutils';
|
|
7
|
-
import { checkInstallPackage, checkVueI18nBridgeInstallPackage, getVueI18nVersion, generateJSON, generateYAML } from '@intlify/bundle-utils';
|
|
7
|
+
import { checkInstallPackage, checkVueI18nBridgeInstallPackage, getVueI18nVersion, generateJSON, generateYAML, generateJavaScript } from '@intlify/bundle-utils';
|
|
8
8
|
import { parse as parse$1 } from '@vue/compiler-sfc';
|
|
9
9
|
import JSON5 from 'json5';
|
|
10
10
|
import yaml from 'js-yaml';
|
|
@@ -219,6 +219,59 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
219
219
|
return orgTransform.apply(this, [code, id]);
|
|
220
220
|
};
|
|
221
221
|
}
|
|
222
|
+
const esbuildPlugin = config.plugins.find(
|
|
223
|
+
(p) => p.name === "vite:esbuild"
|
|
224
|
+
);
|
|
225
|
+
if (esbuildPlugin) {
|
|
226
|
+
const orgTransform = esbuildPlugin.transform;
|
|
227
|
+
esbuildPlugin.transform = async function(code, id) {
|
|
228
|
+
const result = await orgTransform.apply(this, [
|
|
229
|
+
code,
|
|
230
|
+
id
|
|
231
|
+
]);
|
|
232
|
+
if (result == null) {
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
const { filename, query } = parseVueRequest(id);
|
|
236
|
+
if (!query.vue && filter(id) && /\.[c|m]?ts$/.test(id)) {
|
|
237
|
+
const [_code, inSourceMap] = isString(result) ? [result, void 0] : [result.code, result.map];
|
|
238
|
+
let langInfo = defaultSFCLang;
|
|
239
|
+
langInfo = parse(filename).ext;
|
|
240
|
+
const generate = getGenerator(langInfo);
|
|
241
|
+
const parseOptions = getOptions(
|
|
242
|
+
filename,
|
|
243
|
+
isProduction,
|
|
244
|
+
query,
|
|
245
|
+
sourceMap,
|
|
246
|
+
{
|
|
247
|
+
inSourceMap,
|
|
248
|
+
isGlobal: globalSFCScope,
|
|
249
|
+
useClassComponent,
|
|
250
|
+
bridge,
|
|
251
|
+
exportESM: esm,
|
|
252
|
+
forceStringify
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
debug("parseOptions", parseOptions);
|
|
256
|
+
const { code: generatedCode, map } = generate(
|
|
257
|
+
_code,
|
|
258
|
+
parseOptions,
|
|
259
|
+
bridge ? createBridgeCodeGenerator(_code, query) : void 0
|
|
260
|
+
);
|
|
261
|
+
debug("generated code", generatedCode);
|
|
262
|
+
console.log("generated code", generatedCode);
|
|
263
|
+
debug("sourcemap", map, sourceMap);
|
|
264
|
+
if (_code === generatedCode)
|
|
265
|
+
return;
|
|
266
|
+
return {
|
|
267
|
+
code: generatedCode,
|
|
268
|
+
map: sourceMap ? map : { mappings: "" }
|
|
269
|
+
};
|
|
270
|
+
} else {
|
|
271
|
+
return result;
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
}
|
|
222
275
|
},
|
|
223
276
|
async handleHotUpdate({ file, server }) {
|
|
224
277
|
if (/\.(json5?|ya?ml)$/.test(file)) {
|
|
@@ -342,9 +395,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
342
395
|
let langInfo = defaultSFCLang;
|
|
343
396
|
let inSourceMap;
|
|
344
397
|
if (!query.vue) {
|
|
345
|
-
if (/\.(json5?|ya?ml)$/.test(id) && filter(id)) {
|
|
398
|
+
if (/\.(json5?|ya?ml|[c|m]?js)$/.test(id) && filter(id)) {
|
|
346
399
|
langInfo = parse(filename).ext;
|
|
347
|
-
const generate =
|
|
400
|
+
const generate = getGenerator(langInfo);
|
|
348
401
|
const parseOptions = getOptions(
|
|
349
402
|
filename,
|
|
350
403
|
isProduction,
|
|
@@ -423,6 +476,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
423
476
|
}
|
|
424
477
|
};
|
|
425
478
|
});
|
|
479
|
+
function getGenerator(ext, defaultGen = generateJSON) {
|
|
480
|
+
return /\.?json5?$/.test(ext) ? generateJSON : /\.ya?ml$/.test(ext) ? generateYAML : /\.([c|m]?js|[c|m]?ts)$/.test(ext) ? generateJavaScript : defaultGen;
|
|
481
|
+
}
|
|
426
482
|
function normalizeConfigResolveAlias(resolve, framework) {
|
|
427
483
|
if (resolve && resolve.alias) {
|
|
428
484
|
return resolve;
|
package/lib/vite.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "unplugin for Vue I18n",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
@@ -26,18 +26,18 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@intlify/bundle-utils": "^
|
|
29
|
+
"@intlify/bundle-utils": "^5.0.0",
|
|
30
30
|
"@intlify/shared": "next",
|
|
31
|
-
"@rollup/pluginutils": "^
|
|
32
|
-
"@vue/compiler-sfc": "^3.2.
|
|
33
|
-
"debug": "^4.3.
|
|
34
|
-
"fast-glob": "^3.2.
|
|
31
|
+
"@rollup/pluginutils": "^5.0.2",
|
|
32
|
+
"@vue/compiler-sfc": "^3.2.47",
|
|
33
|
+
"debug": "^4.3.3",
|
|
34
|
+
"fast-glob": "^3.2.12",
|
|
35
35
|
"js-yaml": "^4.1.0",
|
|
36
|
-
"json5": "^2.2.
|
|
36
|
+
"json5": "^2.2.3",
|
|
37
37
|
"pathe": "^1.0.0",
|
|
38
38
|
"picocolors": "^1.0.0",
|
|
39
39
|
"source-map": "0.6.1",
|
|
40
|
-
"unplugin": "^1.
|
|
40
|
+
"unplugin": "^1.1.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"mlly": "^1.0.0",
|