@intlify/unplugin-vue-i18n 0.8.2 → 0.9.1
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 +57 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.mjs +58 -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,58 @@ 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
|
+
debug("sourcemap", map, sourceMap);
|
|
267
|
+
if (_code === generatedCode)
|
|
268
|
+
return;
|
|
269
|
+
return {
|
|
270
|
+
code: generatedCode,
|
|
271
|
+
map: sourceMap ? map : { mappings: "" }
|
|
272
|
+
};
|
|
273
|
+
} else {
|
|
274
|
+
return result;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
226
278
|
},
|
|
227
279
|
async handleHotUpdate({ file, server }) {
|
|
228
280
|
if (/\.(json5?|ya?ml)$/.test(file)) {
|
|
@@ -346,9 +398,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
346
398
|
let langInfo = defaultSFCLang;
|
|
347
399
|
let inSourceMap;
|
|
348
400
|
if (!query.vue) {
|
|
349
|
-
if (/\.(json5?|ya?ml)$/.test(id) && filter(id)) {
|
|
401
|
+
if (/\.(json5?|ya?ml|[c|m]?js)$/.test(id) && filter(id)) {
|
|
350
402
|
langInfo = pathe.parse(filename).ext;
|
|
351
|
-
const generate =
|
|
403
|
+
const generate = getGenerator(langInfo);
|
|
352
404
|
const parseOptions = getOptions(
|
|
353
405
|
filename,
|
|
354
406
|
isProduction,
|
|
@@ -427,6 +479,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
427
479
|
}
|
|
428
480
|
};
|
|
429
481
|
});
|
|
482
|
+
function getGenerator(ext, defaultGen = bundleUtils.generateJSON) {
|
|
483
|
+
return /\.?json5?$/.test(ext) ? bundleUtils.generateJSON : /\.ya?ml$/.test(ext) ? bundleUtils.generateYAML : /\.([c|m]?js|[c|m]?ts)$/.test(ext) ? bundleUtils.generateJavaScript : defaultGen;
|
|
484
|
+
}
|
|
430
485
|
function normalizeConfigResolveAlias(resolve, framework) {
|
|
431
486
|
if (resolve && resolve.alias) {
|
|
432
487
|
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,58 @@ 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
|
+
debug("sourcemap", map, sourceMap);
|
|
263
|
+
if (_code === generatedCode)
|
|
264
|
+
return;
|
|
265
|
+
return {
|
|
266
|
+
code: generatedCode,
|
|
267
|
+
map: sourceMap ? map : { mappings: "" }
|
|
268
|
+
};
|
|
269
|
+
} else {
|
|
270
|
+
return result;
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
}
|
|
222
274
|
},
|
|
223
275
|
async handleHotUpdate({ file, server }) {
|
|
224
276
|
if (/\.(json5?|ya?ml)$/.test(file)) {
|
|
@@ -342,9 +394,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
342
394
|
let langInfo = defaultSFCLang;
|
|
343
395
|
let inSourceMap;
|
|
344
396
|
if (!query.vue) {
|
|
345
|
-
if (/\.(json5?|ya?ml)$/.test(id) && filter(id)) {
|
|
397
|
+
if (/\.(json5?|ya?ml|[c|m]?js)$/.test(id) && filter(id)) {
|
|
346
398
|
langInfo = parse(filename).ext;
|
|
347
|
-
const generate =
|
|
399
|
+
const generate = getGenerator(langInfo);
|
|
348
400
|
const parseOptions = getOptions(
|
|
349
401
|
filename,
|
|
350
402
|
isProduction,
|
|
@@ -423,6 +475,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
423
475
|
}
|
|
424
476
|
};
|
|
425
477
|
});
|
|
478
|
+
function getGenerator(ext, defaultGen = generateJSON) {
|
|
479
|
+
return /\.?json5?$/.test(ext) ? generateJSON : /\.ya?ml$/.test(ext) ? generateYAML : /\.([c|m]?js|[c|m]?ts)$/.test(ext) ? generateJavaScript : defaultGen;
|
|
480
|
+
}
|
|
426
481
|
function normalizeConfigResolveAlias(resolve, framework) {
|
|
427
482
|
if (resolve && resolve.alias) {
|
|
428
483
|
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.1",
|
|
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",
|