@intlify/unplugin-vue-i18n 0.4.0 → 0.5.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/CHANGELOG.md +85 -0
- package/README.md +15 -2
- package/lib/index.cjs +49 -20
- package/lib/index.mjs +49 -21
- package/lib/types.d.ts +1 -0
- package/lib/vite.cjs +1 -0
- package/lib/vite.mjs +1 -0
- package/lib/webpack.cjs +1 -0
- package/lib/webpack.mjs +1 -0
- package/package.json +4 -3
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
|
|
2
|
+
## @intlify/unplugin-vue-i18n@0.5.0 (2022-07-26)
|
|
3
|
+
|
|
4
|
+
#### :star: Features
|
|
5
|
+
* [#156](https://github.com/intlify/bundle-tools/pull/156) feat(unplugin-vue-i18n): support petite-vue-i18n and useVueI18nImportName option ([@kazupon](https://github.com/kazupon))
|
|
6
|
+
|
|
7
|
+
#### :zap: Improvement Features
|
|
8
|
+
* [#155](https://github.com/intlify/bundle-tools/pull/155) fix(unplugin-vue-i18n): improve wrong virtual module implementation ([@kazupon](https://github.com/kazupon))
|
|
9
|
+
* [#154](https://github.com/intlify/bundle-tools/pull/154) fix(unplugin-vue-i18n): support unplugin v0.8 ([@kazupon](https://github.com/kazupon))
|
|
10
|
+
|
|
11
|
+
#### Committers: 1
|
|
12
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
## @intlify/unplugin-vue-i18n@0.4.0 (2022-07-07)
|
|
16
|
+
|
|
17
|
+
#### :star: Features
|
|
18
|
+
* [#138](https://github.com/intlify/bundle-tools/pull/138) feat(unplugin-vue-i18n): support esm options for bridge ([@kazupon](https://github.com/kazupon))
|
|
19
|
+
|
|
20
|
+
#### Committers: 1
|
|
21
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## @intlify/unplugin-vue-i18n@0.3.0 (2022-07-07)
|
|
25
|
+
|
|
26
|
+
#### :star: Features
|
|
27
|
+
* [#136](https://github.com/intlify/bundle-tools/pull/136) feat(unplugin-vue-i18n): support fullinstall option ([@kazupon](https://github.com/kazupon))
|
|
28
|
+
* [#135](https://github.com/intlify/bundle-tools/pull/135) feat(unplugin-vue-i18n): support composition only option ([@kazupon](https://github.com/kazupon))
|
|
29
|
+
* [#134](https://github.com/intlify/bundle-tools/pull/134) feat(unplugin-vue-i18n): support runtimeOnly option ([@kazupon](https://github.com/kazupon))
|
|
30
|
+
|
|
31
|
+
#### :pencil: Documentation
|
|
32
|
+
* [#133](https://github.com/intlify/bundle-tools/pull/133) docs: consistent plugin name and add Nuxt ([@Atinux](https://github.com/Atinux))
|
|
33
|
+
|
|
34
|
+
#### Committers: 2
|
|
35
|
+
- Sébastien Chopin ([@Atinux](https://github.com/Atinux))
|
|
36
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## @intlify/unplugin-vue-i18n@0.2.1 (2022-05-07)
|
|
40
|
+
|
|
41
|
+
#### :bug: Bug Fixes
|
|
42
|
+
* [#118](https://github.com/intlify/bundle-tools/pull/118) fix(unplugin-vue-i18n): code transforming strictly ([@kazupon](https://github.com/kazupon))
|
|
43
|
+
|
|
44
|
+
#### Committers: 1
|
|
45
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
## @intlify/unplugin-vue-i18n@0.2.0 (2022-05-06)
|
|
49
|
+
|
|
50
|
+
#### :star: Features
|
|
51
|
+
* [#117](https://github.com/intlify/bundle-tools/pull/117) feat: support virtual resource importing ([@kazupon](https://github.com/kazupon))
|
|
52
|
+
|
|
53
|
+
#### Committers: 1
|
|
54
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## @intlify/unplugin-vue-i18n@0.1.2 (2022-05-06)
|
|
58
|
+
|
|
59
|
+
#### :bug: Bug Fixes
|
|
60
|
+
* [#115](https://github.com/intlify/bundle-tools/pull/115) fix(unplugin-vue-i18n): export d.ts files ([@kazupon](https://github.com/kazupon))
|
|
61
|
+
|
|
62
|
+
#### Committers: 1
|
|
63
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## @intlify/unplugin-vue-i18n@0.1.1 (2022-05-06)
|
|
67
|
+
|
|
68
|
+
#### :bug: Bug Fixes
|
|
69
|
+
* [#114](https://github.com/intlify/bundle-tools/pull/114) fix(unplugin-vue-i18n): export types ([@kazupon](https://github.com/kazupon))
|
|
70
|
+
|
|
71
|
+
#### Committers: 1
|
|
72
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## @intlify/unplugin-vue-i18n@0.1.0 (2022-05-06)
|
|
76
|
+
|
|
77
|
+
#### :star: Features
|
|
78
|
+
* [#113](https://github.com/intlify/bundle-tools/pull/113) feat: unplugin basic implementation for vue-i18n ([@kazupon](https://github.com/kazupon))
|
|
79
|
+
|
|
80
|
+
#### Committers: 1
|
|
81
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
82
|
+
|
|
83
|
+
## @intlify/unplugin-vue-i18n@0.0.0 (2022-05-02)
|
|
84
|
+
|
|
85
|
+
:tada: Initial release.
|
package/README.md
CHANGED
|
@@ -237,6 +237,13 @@ This plugin will automatically select and bundle Vue I18n build according to the
|
|
|
237
237
|
|
|
238
238
|
About details, See the [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#improve-performance-and-reduce-bundle-size-with-runtime-build-only)
|
|
239
239
|
|
|
240
|
+
### For `petite-vue-i18n`
|
|
241
|
+
|
|
242
|
+
This plugin will automatically select and bundle `petite-vue-i18n` build according to the following vite behavior:
|
|
243
|
+
|
|
244
|
+
- vite dev: `petite-vue-i18n.esm-bundler.js`
|
|
245
|
+
- vite build: `petite-vue-i18n.runtime.esm-bundler.js`
|
|
246
|
+
|
|
240
247
|
|
|
241
248
|
## 🔧 Options
|
|
242
249
|
|
|
@@ -428,9 +435,15 @@ About details, See the [here](https://vue-i18n.intlify.dev/guide/advanced/optimi
|
|
|
428
435
|
|
|
429
436
|
This option that to use i18n custom blocks in `vue-class-component`.
|
|
430
437
|
|
|
438
|
+
### `useVueI18nImportName` (Experimental)
|
|
439
|
+
|
|
440
|
+
- **Type:** `boolean`
|
|
441
|
+
- **Default:** `false`
|
|
442
|
+
|
|
443
|
+
Whether to use the import name of `petite-vue-i18n` with the same import name as vue-i18n (`import { xxx } from 'vue-i18n'`).
|
|
444
|
+
|
|
445
|
+
This option allows a smooth migration from `petite-vue-i18n` to `vue-i18n` and allows progressive enhacement.
|
|
431
446
|
|
|
432
|
-
## ✅ TODO
|
|
433
|
-
- [ ] Bundling optimizations
|
|
434
447
|
|
|
435
448
|
## 📜 Changelog
|
|
436
449
|
|
package/lib/index.cjs
CHANGED
|
@@ -13,6 +13,7 @@ const compilerSfc = require('@vue/compiler-sfc');
|
|
|
13
13
|
const JSON5 = require('json5');
|
|
14
14
|
const yaml = require('js-yaml');
|
|
15
15
|
const fs = require('fs');
|
|
16
|
+
const pc = require('picocolors');
|
|
16
17
|
|
|
17
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
18
19
|
|
|
@@ -20,6 +21,7 @@ const createDebug__default = /*#__PURE__*/_interopDefaultLegacy(createDebug);
|
|
|
20
21
|
const fg__default = /*#__PURE__*/_interopDefaultLegacy(fg);
|
|
21
22
|
const JSON5__default = /*#__PURE__*/_interopDefaultLegacy(JSON5);
|
|
22
23
|
const yaml__default = /*#__PURE__*/_interopDefaultLegacy(yaml);
|
|
24
|
+
const pc__default = /*#__PURE__*/_interopDefaultLegacy(pc);
|
|
23
25
|
|
|
24
26
|
function parseVueRequest(id) {
|
|
25
27
|
const [filename, rawQuery] = id.split(`?`, 2);
|
|
@@ -81,10 +83,10 @@ function convert(source, lang) {
|
|
|
81
83
|
}
|
|
82
84
|
|
|
83
85
|
function warn(...args) {
|
|
84
|
-
console.warn(`[unplugin-vue-i18n]
|
|
86
|
+
console.warn(pc__default.yellow(pc__default.bold(`[unplugin-vue-i18n] `)), ...args);
|
|
85
87
|
}
|
|
86
88
|
function error(...args) {
|
|
87
|
-
console.error(`[unplugin-vue-i18n]
|
|
89
|
+
console.error(pc__default.red(pc__default.bold(`[unplugin-vue-i18n] `)), ...args);
|
|
88
90
|
}
|
|
89
91
|
async function getRaw(path) {
|
|
90
92
|
return fs.promises.readFile(path, { encoding: "utf-8" });
|
|
@@ -95,7 +97,9 @@ function raiseError(message) {
|
|
|
95
97
|
|
|
96
98
|
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
97
99
|
const INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID = "@intlify/vite-plugin-vue-i18n/messages";
|
|
100
|
+
const VIRTUAL_PREFIX = "\0";
|
|
98
101
|
const debug = createDebug__default("unplugin-vue-i18n");
|
|
102
|
+
const installedPkg = bundleUtils.checkInstallPackage("@intlify/unplugin-vue-i18n", debug);
|
|
99
103
|
const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
100
104
|
debug("plugin options:", options, meta.framework);
|
|
101
105
|
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
@@ -118,10 +122,16 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
118
122
|
debug("bridge", bridge);
|
|
119
123
|
const runtimeOnly = shared.isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
120
124
|
debug("runtimeOnly", runtimeOnly);
|
|
121
|
-
const compositionOnly = shared.isBoolean(options.compositionOnly) ? options.compositionOnly : true;
|
|
125
|
+
const compositionOnly = installedPkg === "vue-i18n" ? shared.isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
|
|
122
126
|
debug("compositionOnly", compositionOnly);
|
|
123
|
-
const fullInstall = shared.isBoolean(options.fullInstall) ? options.fullInstall : true;
|
|
127
|
+
const fullInstall = installedPkg === "vue-i18n" ? shared.isBoolean(options.fullInstall) ? options.fullInstall : true : false;
|
|
124
128
|
debug("fullInstall", fullInstall);
|
|
129
|
+
const useVueI18nImportName = options.useVueI18nImportName;
|
|
130
|
+
if (useVueI18nImportName != null) {
|
|
131
|
+
warn(`'useVueI18nImportName' option is experimental`);
|
|
132
|
+
}
|
|
133
|
+
debug("useVueI18nImportName", useVueI18nImportName);
|
|
134
|
+
const getAliasName = () => installedPkg === "petite-vue-i18n" && shared.isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : `${installedPkg}`;
|
|
125
135
|
const esm = shared.isBoolean(options.esm) ? options.esm : true;
|
|
126
136
|
debug("esm", esm);
|
|
127
137
|
let isProduction = false;
|
|
@@ -129,27 +139,31 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
129
139
|
return {
|
|
130
140
|
name: "unplugin-vue-i18n",
|
|
131
141
|
enforce: meta.framework === "vite" ? "pre" : "post",
|
|
132
|
-
transformInclude(id) {
|
|
133
|
-
debug("transformInclude", id);
|
|
134
|
-
if (meta.framework === "vite") {
|
|
135
|
-
return true;
|
|
136
|
-
} else {
|
|
137
|
-
const { filename } = parseVueRequest(id);
|
|
138
|
-
return filename.endsWith("vue") || filename.endsWith(INTLIFY_BUNDLE_IMPORT_ID) || filename.endsWith(INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) ? true : /\.(json5?|ya?ml)$/.test(id) && filter(id);
|
|
139
|
-
}
|
|
140
|
-
},
|
|
141
142
|
vite: {
|
|
142
143
|
config(config, { command }) {
|
|
143
144
|
normalizeConfigResolveAlias(config.resolve, meta.framework);
|
|
144
145
|
if (command === "build" && runtimeOnly) {
|
|
145
146
|
if (shared.isArray(config.resolve.alias)) {
|
|
146
147
|
config.resolve.alias.push({
|
|
147
|
-
find:
|
|
148
|
-
replacement:
|
|
148
|
+
find: getAliasName(),
|
|
149
|
+
replacement: `${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`
|
|
149
150
|
});
|
|
150
151
|
} else if (shared.isObject(config.resolve.alias)) {
|
|
151
|
-
config.resolve.alias[
|
|
152
|
+
config.resolve.alias[getAliasName()] = `${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`;
|
|
152
153
|
}
|
|
154
|
+
debug(`alias name: ${getAliasName()}`);
|
|
155
|
+
debug(`set ${installedPkg} runtime only: ${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`);
|
|
156
|
+
} else if (command === "serve" && installedPkg === "petite-vue-i18n" && useVueI18nImportName) {
|
|
157
|
+
normalizeConfigResolveAlias(config.resolve, meta.framework);
|
|
158
|
+
if (shared.isArray(config.resolve.alias)) {
|
|
159
|
+
config.resolve.alias.push({
|
|
160
|
+
find: "vue-i18n",
|
|
161
|
+
replacement: `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`
|
|
162
|
+
});
|
|
163
|
+
} else {
|
|
164
|
+
config.resolve.alias["vue-i18n"] = `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`;
|
|
165
|
+
}
|
|
166
|
+
debug(`alias name: ${getAliasName()}`);
|
|
153
167
|
}
|
|
154
168
|
config.define = config.define || {};
|
|
155
169
|
config.define["__VUE_I18N_LEGACY_API__"] = !compositionOnly;
|
|
@@ -212,16 +226,16 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
212
226
|
debug("resolveId", id, importer);
|
|
213
227
|
if (id === INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) {
|
|
214
228
|
warn(`deprected '${INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID}', you should switch to '${INTLIFY_BUNDLE_IMPORT_ID}'`);
|
|
215
|
-
return id;
|
|
229
|
+
return asVirtualId(id, meta.framework);
|
|
216
230
|
}
|
|
217
231
|
if (id === INTLIFY_BUNDLE_IMPORT_ID) {
|
|
218
|
-
return id;
|
|
232
|
+
return asVirtualId(id, meta.framework);
|
|
219
233
|
}
|
|
220
234
|
},
|
|
221
235
|
async load(id) {
|
|
222
236
|
debug("load", id);
|
|
223
237
|
const { query } = parseVueRequest(id);
|
|
224
|
-
if ([INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(id) && include) {
|
|
238
|
+
if ([INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(getVirtualId(id, meta.framework)) && include) {
|
|
225
239
|
let resourcePaths = [];
|
|
226
240
|
const includePaths = shared.isArray(include) ? include : [include];
|
|
227
241
|
for (const inc of includePaths) {
|
|
@@ -240,6 +254,15 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
240
254
|
};
|
|
241
255
|
}
|
|
242
256
|
},
|
|
257
|
+
transformInclude(id) {
|
|
258
|
+
debug("transformInclude", id);
|
|
259
|
+
if (meta.framework === "vite") {
|
|
260
|
+
return true;
|
|
261
|
+
} else {
|
|
262
|
+
const { filename } = parseVueRequest(id);
|
|
263
|
+
return filename.endsWith("vue") || filename.endsWith(INTLIFY_BUNDLE_IMPORT_ID) || filename.endsWith(INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) || /\.(json5?|ya?ml)$/.test(filename) && filter(filename);
|
|
264
|
+
}
|
|
265
|
+
},
|
|
243
266
|
async transform(code, id) {
|
|
244
267
|
const { filename, query } = parseVueRequest(id);
|
|
245
268
|
debug("transform", id, JSON.stringify(query), filename);
|
|
@@ -329,7 +352,7 @@ async function loadWebpack() {
|
|
|
329
352
|
try {
|
|
330
353
|
webpack = await import('webpack').then((m) => m.default || m);
|
|
331
354
|
} catch (e) {
|
|
332
|
-
|
|
355
|
+
warn(`webpack not found, please install webpack.`);
|
|
333
356
|
}
|
|
334
357
|
return webpack;
|
|
335
358
|
}
|
|
@@ -433,6 +456,12 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
433
456
|
});
|
|
434
457
|
}
|
|
435
458
|
}
|
|
459
|
+
function getVirtualId(id, framework = "vite") {
|
|
460
|
+
return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
|
|
461
|
+
}
|
|
462
|
+
function asVirtualId(id, framework = "vite") {
|
|
463
|
+
return framework === "vite" ? VIRTUAL_PREFIX + id : id;
|
|
464
|
+
}
|
|
436
465
|
|
|
437
466
|
exports["default"] = unplugin;
|
|
438
467
|
exports.unplugin = unplugin;
|
package/lib/index.mjs
CHANGED
|
@@ -4,11 +4,12 @@ import createDebug from 'debug';
|
|
|
4
4
|
import fg from 'fast-glob';
|
|
5
5
|
import { isString, isArray, isBoolean, isObject, isEmptyObject, isNumber, assign } from '@intlify/shared';
|
|
6
6
|
import { createFilter } from '@rollup/pluginutils';
|
|
7
|
-
import { generateJSON, generateYAML } from '@intlify/bundle-utils';
|
|
7
|
+
import { checkInstallPackage, generateJSON, generateYAML } 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';
|
|
11
11
|
import { promises } from 'fs';
|
|
12
|
+
import pc from 'picocolors';
|
|
12
13
|
|
|
13
14
|
function parseVueRequest(id) {
|
|
14
15
|
const [filename, rawQuery] = id.split(`?`, 2);
|
|
@@ -70,10 +71,10 @@ function convert(source, lang) {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
function warn(...args) {
|
|
73
|
-
console.warn(`[unplugin-vue-i18n]
|
|
74
|
+
console.warn(pc.yellow(pc.bold(`[unplugin-vue-i18n] `)), ...args);
|
|
74
75
|
}
|
|
75
76
|
function error(...args) {
|
|
76
|
-
console.error(`[unplugin-vue-i18n]
|
|
77
|
+
console.error(pc.red(pc.bold(`[unplugin-vue-i18n] `)), ...args);
|
|
77
78
|
}
|
|
78
79
|
async function getRaw(path) {
|
|
79
80
|
return promises.readFile(path, { encoding: "utf-8" });
|
|
@@ -84,7 +85,9 @@ function raiseError(message) {
|
|
|
84
85
|
|
|
85
86
|
const INTLIFY_BUNDLE_IMPORT_ID = "@intlify/unplugin-vue-i18n/messages";
|
|
86
87
|
const INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID = "@intlify/vite-plugin-vue-i18n/messages";
|
|
88
|
+
const VIRTUAL_PREFIX = "\0";
|
|
87
89
|
const debug = createDebug("unplugin-vue-i18n");
|
|
90
|
+
const installedPkg = checkInstallPackage("@intlify/unplugin-vue-i18n", debug);
|
|
88
91
|
const unplugin = createUnplugin((options = {}, meta) => {
|
|
89
92
|
debug("plugin options:", options, meta.framework);
|
|
90
93
|
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
@@ -107,10 +110,16 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
107
110
|
debug("bridge", bridge);
|
|
108
111
|
const runtimeOnly = isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
109
112
|
debug("runtimeOnly", runtimeOnly);
|
|
110
|
-
const compositionOnly = isBoolean(options.compositionOnly) ? options.compositionOnly : true;
|
|
113
|
+
const compositionOnly = installedPkg === "vue-i18n" ? isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
|
|
111
114
|
debug("compositionOnly", compositionOnly);
|
|
112
|
-
const fullInstall = isBoolean(options.fullInstall) ? options.fullInstall : true;
|
|
115
|
+
const fullInstall = installedPkg === "vue-i18n" ? isBoolean(options.fullInstall) ? options.fullInstall : true : false;
|
|
113
116
|
debug("fullInstall", fullInstall);
|
|
117
|
+
const useVueI18nImportName = options.useVueI18nImportName;
|
|
118
|
+
if (useVueI18nImportName != null) {
|
|
119
|
+
warn(`'useVueI18nImportName' option is experimental`);
|
|
120
|
+
}
|
|
121
|
+
debug("useVueI18nImportName", useVueI18nImportName);
|
|
122
|
+
const getAliasName = () => installedPkg === "petite-vue-i18n" && isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : `${installedPkg}`;
|
|
114
123
|
const esm = isBoolean(options.esm) ? options.esm : true;
|
|
115
124
|
debug("esm", esm);
|
|
116
125
|
let isProduction = false;
|
|
@@ -118,27 +127,31 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
118
127
|
return {
|
|
119
128
|
name: "unplugin-vue-i18n",
|
|
120
129
|
enforce: meta.framework === "vite" ? "pre" : "post",
|
|
121
|
-
transformInclude(id) {
|
|
122
|
-
debug("transformInclude", id);
|
|
123
|
-
if (meta.framework === "vite") {
|
|
124
|
-
return true;
|
|
125
|
-
} else {
|
|
126
|
-
const { filename } = parseVueRequest(id);
|
|
127
|
-
return filename.endsWith("vue") || filename.endsWith(INTLIFY_BUNDLE_IMPORT_ID) || filename.endsWith(INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) ? true : /\.(json5?|ya?ml)$/.test(id) && filter(id);
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
130
|
vite: {
|
|
131
131
|
config(config, { command }) {
|
|
132
132
|
normalizeConfigResolveAlias(config.resolve, meta.framework);
|
|
133
133
|
if (command === "build" && runtimeOnly) {
|
|
134
134
|
if (isArray(config.resolve.alias)) {
|
|
135
135
|
config.resolve.alias.push({
|
|
136
|
-
find:
|
|
137
|
-
replacement:
|
|
136
|
+
find: getAliasName(),
|
|
137
|
+
replacement: `${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`
|
|
138
138
|
});
|
|
139
139
|
} else if (isObject(config.resolve.alias)) {
|
|
140
|
-
config.resolve.alias[
|
|
140
|
+
config.resolve.alias[getAliasName()] = `${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`;
|
|
141
141
|
}
|
|
142
|
+
debug(`alias name: ${getAliasName()}`);
|
|
143
|
+
debug(`set ${installedPkg} runtime only: ${installedPkg}/dist/${installedPkg}.runtime.esm-bundler.js`);
|
|
144
|
+
} else if (command === "serve" && installedPkg === "petite-vue-i18n" && useVueI18nImportName) {
|
|
145
|
+
normalizeConfigResolveAlias(config.resolve, meta.framework);
|
|
146
|
+
if (isArray(config.resolve.alias)) {
|
|
147
|
+
config.resolve.alias.push({
|
|
148
|
+
find: "vue-i18n",
|
|
149
|
+
replacement: `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`
|
|
150
|
+
});
|
|
151
|
+
} else {
|
|
152
|
+
config.resolve.alias["vue-i18n"] = `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`;
|
|
153
|
+
}
|
|
154
|
+
debug(`alias name: ${getAliasName()}`);
|
|
142
155
|
}
|
|
143
156
|
config.define = config.define || {};
|
|
144
157
|
config.define["__VUE_I18N_LEGACY_API__"] = !compositionOnly;
|
|
@@ -201,16 +214,16 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
201
214
|
debug("resolveId", id, importer);
|
|
202
215
|
if (id === INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) {
|
|
203
216
|
warn(`deprected '${INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID}', you should switch to '${INTLIFY_BUNDLE_IMPORT_ID}'`);
|
|
204
|
-
return id;
|
|
217
|
+
return asVirtualId(id, meta.framework);
|
|
205
218
|
}
|
|
206
219
|
if (id === INTLIFY_BUNDLE_IMPORT_ID) {
|
|
207
|
-
return id;
|
|
220
|
+
return asVirtualId(id, meta.framework);
|
|
208
221
|
}
|
|
209
222
|
},
|
|
210
223
|
async load(id) {
|
|
211
224
|
debug("load", id);
|
|
212
225
|
const { query } = parseVueRequest(id);
|
|
213
|
-
if ([INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(id) && include) {
|
|
226
|
+
if ([INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID, INTLIFY_BUNDLE_IMPORT_ID].includes(getVirtualId(id, meta.framework)) && include) {
|
|
214
227
|
let resourcePaths = [];
|
|
215
228
|
const includePaths = isArray(include) ? include : [include];
|
|
216
229
|
for (const inc of includePaths) {
|
|
@@ -229,6 +242,15 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
229
242
|
};
|
|
230
243
|
}
|
|
231
244
|
},
|
|
245
|
+
transformInclude(id) {
|
|
246
|
+
debug("transformInclude", id);
|
|
247
|
+
if (meta.framework === "vite") {
|
|
248
|
+
return true;
|
|
249
|
+
} else {
|
|
250
|
+
const { filename } = parseVueRequest(id);
|
|
251
|
+
return filename.endsWith("vue") || filename.endsWith(INTLIFY_BUNDLE_IMPORT_ID) || filename.endsWith(INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) || /\.(json5?|ya?ml)$/.test(filename) && filter(filename);
|
|
252
|
+
}
|
|
253
|
+
},
|
|
232
254
|
async transform(code, id) {
|
|
233
255
|
const { filename, query } = parseVueRequest(id);
|
|
234
256
|
debug("transform", id, JSON.stringify(query), filename);
|
|
@@ -318,7 +340,7 @@ async function loadWebpack() {
|
|
|
318
340
|
try {
|
|
319
341
|
webpack = await import('webpack').then((m) => m.default || m);
|
|
320
342
|
} catch (e) {
|
|
321
|
-
|
|
343
|
+
warn(`webpack not found, please install webpack.`);
|
|
322
344
|
}
|
|
323
345
|
return webpack;
|
|
324
346
|
}
|
|
@@ -422,5 +444,11 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
422
444
|
});
|
|
423
445
|
}
|
|
424
446
|
}
|
|
447
|
+
function getVirtualId(id, framework = "vite") {
|
|
448
|
+
return framework === "vite" ? id.startsWith(VIRTUAL_PREFIX) ? id.slice(VIRTUAL_PREFIX.length) : "" : id;
|
|
449
|
+
}
|
|
450
|
+
function asVirtualId(id, framework = "vite") {
|
|
451
|
+
return framework === "vite" ? VIRTUAL_PREFIX + id : id;
|
|
452
|
+
}
|
|
425
453
|
|
|
426
454
|
export { unplugin as default, unplugin };
|
package/lib/types.d.ts
CHANGED
package/lib/vite.cjs
CHANGED
package/lib/vite.mjs
CHANGED
package/lib/webpack.cjs
CHANGED
package/lib/webpack.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "unplugin for Vue I18n",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
@@ -31,15 +31,16 @@
|
|
|
31
31
|
"js-yaml": "^4.1.0",
|
|
32
32
|
"json5": "^2.2.0",
|
|
33
33
|
"pathe": "^0.2.0",
|
|
34
|
+
"picocolors": "^1.0.0",
|
|
34
35
|
"source-map": "0.6.1",
|
|
35
|
-
"unplugin": "^0.
|
|
36
|
+
"unplugin": "^0.8.0"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
38
39
|
"mlly": "^0.5.2",
|
|
39
40
|
"unbuild": "^0.7.4"
|
|
40
41
|
},
|
|
41
42
|
"engines": {
|
|
42
|
-
"node": ">=
|
|
43
|
+
"node": ">= 14.16"
|
|
43
44
|
},
|
|
44
45
|
"files": [
|
|
45
46
|
"lib",
|