@intlify/unplugin-vue-i18n 5.0.0 → 5.2.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 +21 -7
- package/lib/index.cjs +17 -106
- package/lib/index.d.cts +1 -1
- package/lib/index.d.mts +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.mjs +17 -103
- package/lib/types.d.cts +3 -1
- package/lib/types.d.mts +3 -1
- package/lib/types.d.ts +3 -1
- package/lib/vite.cjs +1 -3
- package/lib/vite.mjs +1 -3
- package/lib/webpack.cjs +1 -3
- package/lib/webpack.mjs +1 -3
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -253,13 +253,6 @@ This plugin will automatically select and bundle Vue I18n build according to the
|
|
|
253
253
|
|
|
254
254
|
About details, See the [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#improve-performance-and-reduce-bundle-size-with-runtime-build-only)
|
|
255
255
|
|
|
256
|
-
### For `petite-vue-i18n`
|
|
257
|
-
|
|
258
|
-
This plugin will automatically select and bundle `petite-vue-i18n` build according to the following vite behavior:
|
|
259
|
-
|
|
260
|
-
- vite dev: `petite-vue-i18n.esm-bundler.js`
|
|
261
|
-
- vite build: `petite-vue-i18n.runtime.esm-bundler.js`
|
|
262
|
-
|
|
263
256
|
|
|
264
257
|
## 🔧 Options
|
|
265
258
|
|
|
@@ -302,6 +295,27 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
|
|
|
302
295
|
> [!WARNING]
|
|
303
296
|
If you use the `js` and `ts` resources formats, set the paths, so your application code is not targeted. We recommend that resources be isolated from the application code.
|
|
304
297
|
|
|
298
|
+
### `module`
|
|
299
|
+
|
|
300
|
+
- **Type:** `string`
|
|
301
|
+
- **Default:** `'vue-i18n'`
|
|
302
|
+
|
|
303
|
+
> [!NOTE]
|
|
304
|
+
This options is supported from v5.1.0, and works with vue-i18n v10 and later.
|
|
305
|
+
|
|
306
|
+
Bundle target vue-i18n module. You can specify either `‘vue-i18n’` or `‘petite-vue-i18n’`.
|
|
307
|
+
|
|
308
|
+
The default is `'vue-i18n'`, and the following installed in node_modules will be bundled.
|
|
309
|
+
|
|
310
|
+
- development: `vue-i18n.esm-bundler.js`
|
|
311
|
+
- production: `vue-i18n.runtime.esm-bundler.js`
|
|
312
|
+
|
|
313
|
+
In the case of `‘petite-vue-i18n’`, the following installed in node_modules will be bundled.
|
|
314
|
+
|
|
315
|
+
- development: `petite-vue-i18n.esm-bundler.js`
|
|
316
|
+
- production: `petite-vue-i18n.runtime.esm-bundler.js`
|
|
317
|
+
|
|
318
|
+
If you are using petite-vue-i18n, you will need to set this value.
|
|
305
319
|
|
|
306
320
|
### `strictMessage`
|
|
307
321
|
|
package/lib/index.cjs
CHANGED
|
@@ -6,12 +6,10 @@ const unplugin$1 = require('unplugin');
|
|
|
6
6
|
const createDebug = require('debug');
|
|
7
7
|
const pc = require('picocolors');
|
|
8
8
|
const path = require('node:path');
|
|
9
|
-
const fs = require('node:fs');
|
|
10
|
-
const module$1 = require('node:module');
|
|
11
9
|
const pathe = require('pathe');
|
|
12
|
-
const mlly = require('mlly');
|
|
13
10
|
const shared = require('@intlify/shared');
|
|
14
11
|
const fg = require('fast-glob');
|
|
12
|
+
const node_fs = require('node:fs');
|
|
15
13
|
const pluginutils = require('@rollup/pluginutils');
|
|
16
14
|
const bundleUtils = require('@intlify/bundle-utils');
|
|
17
15
|
const compilerSfc = require('vue/compiler-sfc');
|
|
@@ -20,14 +18,11 @@ const scopeManager = require('@typescript-eslint/scope-manager');
|
|
|
20
18
|
const typescriptEstree = require('@typescript-eslint/typescript-estree');
|
|
21
19
|
const eslintUitls = require('@eslint-community/eslint-utils');
|
|
22
20
|
|
|
23
|
-
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
24
21
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
25
22
|
|
|
26
23
|
const createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
|
|
27
24
|
const pc__default = /*#__PURE__*/_interopDefaultCompat(pc);
|
|
28
25
|
const path__default = /*#__PURE__*/_interopDefaultCompat(path);
|
|
29
|
-
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
30
|
-
const module__default = /*#__PURE__*/_interopDefaultCompat(module$1);
|
|
31
26
|
const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
|
|
32
27
|
const eslintUitls__default = /*#__PURE__*/_interopDefaultCompat(eslintUitls);
|
|
33
28
|
|
|
@@ -67,93 +62,8 @@ function normalizePath(id) {
|
|
|
67
62
|
return path__default.posix.normalize(isWindows ? slash(id) : id);
|
|
68
63
|
}
|
|
69
64
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
rootPattern: /^node_modules$/,
|
|
73
|
-
reverse: false,
|
|
74
|
-
test: (filePath) => {
|
|
75
|
-
try {
|
|
76
|
-
if (fs.statSync(filePath).isFile()) {
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
} catch {
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
function findFile(filename, _options = {}) {
|
|
84
|
-
const filenames = Array.isArray(filename) ? filename : [filename];
|
|
85
|
-
const options = { ...defaultFindOptions, ..._options };
|
|
86
|
-
const basePath = pathe.resolve(options.startingFrom);
|
|
87
|
-
const leadingSlash = basePath[0] === "/";
|
|
88
|
-
const segments = basePath.split("/").filter(Boolean);
|
|
89
|
-
if (leadingSlash) {
|
|
90
|
-
segments[0] = "/" + segments[0];
|
|
91
|
-
}
|
|
92
|
-
let root = segments.findIndex((r) => r.match(options.rootPattern));
|
|
93
|
-
if (root === -1) {
|
|
94
|
-
root = 0;
|
|
95
|
-
}
|
|
96
|
-
if (options.reverse) {
|
|
97
|
-
for (let index = root + 1; index <= segments.length; index++) {
|
|
98
|
-
for (const filename2 of filenames) {
|
|
99
|
-
const filePath = pathe.join(...segments.slice(0, index), filename2);
|
|
100
|
-
if (options.test(filePath)) {
|
|
101
|
-
return filePath;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
} else {
|
|
106
|
-
for (let index = segments.length; index > root; index--) {
|
|
107
|
-
for (const filename2 of filenames) {
|
|
108
|
-
const filePath = pathe.join(...segments.slice(0, index), filename2);
|
|
109
|
-
if (options.test(filePath)) {
|
|
110
|
-
return filePath;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
throw new Error(
|
|
116
|
-
`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
function findNearestFile(filename, _options = {}) {
|
|
120
|
-
return findFile(filename, _options);
|
|
121
|
-
}
|
|
122
|
-
function resolvePackageJSON(id = process.cwd(), options = {}) {
|
|
123
|
-
const resolvedPath = pathe.isAbsolute(id) ? id : mlly.resolvePathSync(id, options);
|
|
124
|
-
return findNearestFile("package.json", {
|
|
125
|
-
startingFrom: resolvedPath,
|
|
126
|
-
...options
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const _require = module__default.createRequire((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
|
|
131
|
-
function checkInstallPackage(debug) {
|
|
132
|
-
const pkgInfo = resolvePkgPath("vue-i18n", debug) || resolvePkgPath("petite-vue-i18n", debug);
|
|
133
|
-
if (!pkgInfo) {
|
|
134
|
-
throw new Error(
|
|
135
|
-
`requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
|
|
136
|
-
);
|
|
137
|
-
}
|
|
138
|
-
debug("installed package info:", pkgInfo);
|
|
139
|
-
return pkgInfo;
|
|
140
|
-
}
|
|
141
|
-
function resolvePkgPath(id, debug) {
|
|
142
|
-
try {
|
|
143
|
-
const modPath = _require.resolve(id);
|
|
144
|
-
debug("modPath:", modPath, id);
|
|
145
|
-
const pkgJsonPath = resolvePackageJSON(modPath);
|
|
146
|
-
debug("pkgJsonPath:", pkgJsonPath);
|
|
147
|
-
const pkgJson = JSON.parse(fs__default.readFileSync(pkgJsonPath, "utf-8"));
|
|
148
|
-
const pkgName = pkgJson.name.startsWith("vue-i18n") ? "vue-i18n" : pkgJson.name.startsWith("petite-vue-i18n") ? "petite-vue-i18n" : "";
|
|
149
|
-
return pkgJson ? { alias: id, pkg: pkgName } : null;
|
|
150
|
-
} catch (e) {
|
|
151
|
-
debug(`cannot find '${id}'`, e);
|
|
152
|
-
return null;
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function resolveOptions(options, installedPkgInfo) {
|
|
65
|
+
function resolveOptions(options) {
|
|
66
|
+
const moduleType = options.module || "vue-i18n";
|
|
157
67
|
let onlyLocales = [];
|
|
158
68
|
if (options.onlyLocales) {
|
|
159
69
|
onlyLocales = shared.isArray(options.onlyLocales) ? options.onlyLocales : [options.onlyLocales];
|
|
@@ -174,8 +84,8 @@ function resolveOptions(options, installedPkgInfo) {
|
|
|
174
84
|
const globalSFCScope = !!options.globalSFCScope;
|
|
175
85
|
const runtimeOnly = shared.isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
176
86
|
const dropMessageCompiler = !!options.dropMessageCompiler;
|
|
177
|
-
const compositionOnly =
|
|
178
|
-
const fullInstall =
|
|
87
|
+
const compositionOnly = moduleType === "vue-i18n" ? shared.isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
|
|
88
|
+
const fullInstall = moduleType === "vue-i18n" ? shared.isBoolean(options.fullInstall) ? options.fullInstall : true : false;
|
|
179
89
|
const ssrBuild = !!options.ssr;
|
|
180
90
|
const allowDynamic = !!options.allowDynamic;
|
|
181
91
|
const strictMessage = shared.isBoolean(options.strictMessage) ? options.strictMessage : true;
|
|
@@ -186,6 +96,7 @@ function resolveOptions(options, installedPkgInfo) {
|
|
|
186
96
|
return {
|
|
187
97
|
include,
|
|
188
98
|
exclude,
|
|
99
|
+
module: moduleType,
|
|
189
100
|
onlyLocales,
|
|
190
101
|
forceStringify,
|
|
191
102
|
defaultSFCLang,
|
|
@@ -276,6 +187,7 @@ function resourcePlugin({
|
|
|
276
187
|
onlyLocales,
|
|
277
188
|
include,
|
|
278
189
|
exclude,
|
|
190
|
+
module,
|
|
279
191
|
forceStringify,
|
|
280
192
|
defaultSFCLang,
|
|
281
193
|
globalSFCScope,
|
|
@@ -288,14 +200,14 @@ function resourcePlugin({
|
|
|
288
200
|
allowDynamic,
|
|
289
201
|
escapeHtml,
|
|
290
202
|
transformI18nBlock
|
|
291
|
-
}, meta
|
|
203
|
+
}, meta) {
|
|
292
204
|
const filter = pluginutils.createFilter(include, exclude);
|
|
293
205
|
const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
|
|
294
|
-
return `${
|
|
206
|
+
return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
|
|
295
207
|
};
|
|
296
208
|
let isProduction = false;
|
|
297
209
|
let sourceMap = false;
|
|
298
|
-
const vueI18nAliasName =
|
|
210
|
+
const vueI18nAliasName = module;
|
|
299
211
|
debug$2(`vue-i18n alias name: ${vueI18nAliasName}`);
|
|
300
212
|
let vuePlugin = null;
|
|
301
213
|
const getSfcParser = () => {
|
|
@@ -412,12 +324,12 @@ function resourcePlugin({
|
|
|
412
324
|
},
|
|
413
325
|
async handleHotUpdate({ file, server }) {
|
|
414
326
|
if (/\.(json5?|ya?ml)$/.test(file)) {
|
|
415
|
-
const
|
|
327
|
+
const module2 = server.moduleGraph.getModuleById(
|
|
416
328
|
asVirtualId(INTLIFY_BUNDLE_IMPORT_ID, meta.framework)
|
|
417
329
|
);
|
|
418
|
-
if (
|
|
419
|
-
server.moduleGraph.invalidateModule(
|
|
420
|
-
return [
|
|
330
|
+
if (module2) {
|
|
331
|
+
server.moduleGraph.invalidateModule(module2);
|
|
332
|
+
return [module2];
|
|
421
333
|
}
|
|
422
334
|
}
|
|
423
335
|
}
|
|
@@ -782,7 +694,7 @@ function asVirtualId(id, framework = "vite") {
|
|
|
782
694
|
return framework === "vite" ? VIRTUAL_PREFIX + id : id;
|
|
783
695
|
}
|
|
784
696
|
async function getRaw(path) {
|
|
785
|
-
return
|
|
697
|
+
return node_fs.promises.readFile(path, { encoding: "utf-8" });
|
|
786
698
|
}
|
|
787
699
|
|
|
788
700
|
const debug$1 = createDebug__default(resolveNamespace("directive"));
|
|
@@ -1053,16 +965,15 @@ function resolveIdentifier(localVariables, returnVariable) {
|
|
|
1053
965
|
}
|
|
1054
966
|
|
|
1055
967
|
const debug = createDebug__default(resolveNamespace("root"));
|
|
1056
|
-
const installedPkgInfo = checkInstallPackage(debug);
|
|
1057
968
|
const unpluginFactory = (options = {}, meta) => {
|
|
1058
969
|
debug("meta framework", meta.framework);
|
|
1059
970
|
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
1060
971
|
raiseError(`This plugin is supported 'vite' and 'webpack' only`);
|
|
1061
972
|
}
|
|
1062
973
|
debug("plugin options (resolving):", options);
|
|
1063
|
-
const resolvedOptions = resolveOptions(options
|
|
974
|
+
const resolvedOptions = resolveOptions(options);
|
|
1064
975
|
debug("plugin options (resolved):", resolvedOptions);
|
|
1065
|
-
const plugins = [resourcePlugin(resolvedOptions, meta
|
|
976
|
+
const plugins = [resourcePlugin(resolvedOptions, meta)];
|
|
1066
977
|
if (resolvedOptions.optimizeTranslationDirective) {
|
|
1067
978
|
if (meta.framework === "webpack") {
|
|
1068
979
|
raiseError(
|
package/lib/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnpluginFactory, UnpluginInstance } from 'unplugin';
|
|
2
2
|
import { PluginOptions } from './types.cjs';
|
|
3
|
-
export { SFCLangFormat } from './types.cjs';
|
|
3
|
+
export { SFCLangFormat, VueI18nModule } from './types.cjs';
|
|
4
4
|
|
|
5
5
|
declare const unpluginFactory: UnpluginFactory<PluginOptions | undefined>;
|
|
6
6
|
declare const unplugin: UnpluginInstance<PluginOptions | undefined, boolean>;
|
package/lib/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnpluginFactory, UnpluginInstance } from 'unplugin';
|
|
2
2
|
import { PluginOptions } from './types.mjs';
|
|
3
|
-
export { SFCLangFormat } from './types.mjs';
|
|
3
|
+
export { SFCLangFormat, VueI18nModule } from './types.mjs';
|
|
4
4
|
|
|
5
5
|
declare const unpluginFactory: UnpluginFactory<PluginOptions | undefined>;
|
|
6
6
|
declare const unplugin: UnpluginInstance<PluginOptions | undefined, boolean>;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UnpluginFactory, UnpluginInstance } from 'unplugin';
|
|
2
2
|
import { PluginOptions } from './types.js';
|
|
3
|
-
export { SFCLangFormat } from './types.js';
|
|
3
|
+
export { SFCLangFormat, VueI18nModule } from './types.js';
|
|
4
4
|
|
|
5
5
|
declare const unpluginFactory: UnpluginFactory<PluginOptions | undefined>;
|
|
6
6
|
declare const unplugin: UnpluginInstance<PluginOptions | undefined, boolean>;
|
package/lib/index.mjs
CHANGED
|
@@ -2,12 +2,10 @@ import { createUnplugin } from 'unplugin';
|
|
|
2
2
|
import createDebug from 'debug';
|
|
3
3
|
import pc from 'picocolors';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import
|
|
6
|
-
import module from 'node:module';
|
|
7
|
-
import { isAbsolute, resolve, join, normalize, parse } from 'pathe';
|
|
8
|
-
import { resolvePathSync } from 'mlly';
|
|
5
|
+
import { normalize, parse } from 'pathe';
|
|
9
6
|
import { isArray, isString, isBoolean, assign, isNumber, isEmptyObject, generateCodeFrame } from '@intlify/shared';
|
|
10
7
|
import fg from 'fast-glob';
|
|
8
|
+
import { promises } from 'node:fs';
|
|
11
9
|
import { createFilter } from '@rollup/pluginutils';
|
|
12
10
|
import { generateJSON, generateYAML, generateJavaScript } from '@intlify/bundle-utils';
|
|
13
11
|
import { parse as parse$1 } from 'vue/compiler-sfc';
|
|
@@ -52,93 +50,8 @@ function normalizePath(id) {
|
|
|
52
50
|
return path.posix.normalize(isWindows ? slash(id) : id);
|
|
53
51
|
}
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
rootPattern: /^node_modules$/,
|
|
58
|
-
reverse: false,
|
|
59
|
-
test: (filePath) => {
|
|
60
|
-
try {
|
|
61
|
-
if (statSync(filePath).isFile()) {
|
|
62
|
-
return true;
|
|
63
|
-
}
|
|
64
|
-
} catch {
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
function findFile(filename, _options = {}) {
|
|
69
|
-
const filenames = Array.isArray(filename) ? filename : [filename];
|
|
70
|
-
const options = { ...defaultFindOptions, ..._options };
|
|
71
|
-
const basePath = resolve(options.startingFrom);
|
|
72
|
-
const leadingSlash = basePath[0] === "/";
|
|
73
|
-
const segments = basePath.split("/").filter(Boolean);
|
|
74
|
-
if (leadingSlash) {
|
|
75
|
-
segments[0] = "/" + segments[0];
|
|
76
|
-
}
|
|
77
|
-
let root = segments.findIndex((r) => r.match(options.rootPattern));
|
|
78
|
-
if (root === -1) {
|
|
79
|
-
root = 0;
|
|
80
|
-
}
|
|
81
|
-
if (options.reverse) {
|
|
82
|
-
for (let index = root + 1; index <= segments.length; index++) {
|
|
83
|
-
for (const filename2 of filenames) {
|
|
84
|
-
const filePath = join(...segments.slice(0, index), filename2);
|
|
85
|
-
if (options.test(filePath)) {
|
|
86
|
-
return filePath;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
} else {
|
|
91
|
-
for (let index = segments.length; index > root; index--) {
|
|
92
|
-
for (const filename2 of filenames) {
|
|
93
|
-
const filePath = join(...segments.slice(0, index), filename2);
|
|
94
|
-
if (options.test(filePath)) {
|
|
95
|
-
return filePath;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
throw new Error(
|
|
101
|
-
`Cannot find matching ${filename} in ${options.startingFrom} or parent directories`
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
function findNearestFile(filename, _options = {}) {
|
|
105
|
-
return findFile(filename, _options);
|
|
106
|
-
}
|
|
107
|
-
function resolvePackageJSON(id = process.cwd(), options = {}) {
|
|
108
|
-
const resolvedPath = isAbsolute(id) ? id : resolvePathSync(id, options);
|
|
109
|
-
return findNearestFile("package.json", {
|
|
110
|
-
startingFrom: resolvedPath,
|
|
111
|
-
...options
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const _require = module.createRequire(import.meta.url);
|
|
116
|
-
function checkInstallPackage(debug) {
|
|
117
|
-
const pkgInfo = resolvePkgPath("vue-i18n", debug) || resolvePkgPath("petite-vue-i18n", debug);
|
|
118
|
-
if (!pkgInfo) {
|
|
119
|
-
throw new Error(
|
|
120
|
-
`requires 'vue-i18n' or 'petite-vue-i18n' to be present in the dependency tree.`
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
debug("installed package info:", pkgInfo);
|
|
124
|
-
return pkgInfo;
|
|
125
|
-
}
|
|
126
|
-
function resolvePkgPath(id, debug) {
|
|
127
|
-
try {
|
|
128
|
-
const modPath = _require.resolve(id);
|
|
129
|
-
debug("modPath:", modPath, id);
|
|
130
|
-
const pkgJsonPath = resolvePackageJSON(modPath);
|
|
131
|
-
debug("pkgJsonPath:", pkgJsonPath);
|
|
132
|
-
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, "utf-8"));
|
|
133
|
-
const pkgName = pkgJson.name.startsWith("vue-i18n") ? "vue-i18n" : pkgJson.name.startsWith("petite-vue-i18n") ? "petite-vue-i18n" : "";
|
|
134
|
-
return pkgJson ? { alias: id, pkg: pkgName } : null;
|
|
135
|
-
} catch (e) {
|
|
136
|
-
debug(`cannot find '${id}'`, e);
|
|
137
|
-
return null;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function resolveOptions(options, installedPkgInfo) {
|
|
53
|
+
function resolveOptions(options) {
|
|
54
|
+
const moduleType = options.module || "vue-i18n";
|
|
142
55
|
let onlyLocales = [];
|
|
143
56
|
if (options.onlyLocales) {
|
|
144
57
|
onlyLocales = isArray(options.onlyLocales) ? options.onlyLocales : [options.onlyLocales];
|
|
@@ -159,8 +72,8 @@ function resolveOptions(options, installedPkgInfo) {
|
|
|
159
72
|
const globalSFCScope = !!options.globalSFCScope;
|
|
160
73
|
const runtimeOnly = isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
161
74
|
const dropMessageCompiler = !!options.dropMessageCompiler;
|
|
162
|
-
const compositionOnly =
|
|
163
|
-
const fullInstall =
|
|
75
|
+
const compositionOnly = moduleType === "vue-i18n" ? isBoolean(options.compositionOnly) ? options.compositionOnly : true : true;
|
|
76
|
+
const fullInstall = moduleType === "vue-i18n" ? isBoolean(options.fullInstall) ? options.fullInstall : true : false;
|
|
164
77
|
const ssrBuild = !!options.ssr;
|
|
165
78
|
const allowDynamic = !!options.allowDynamic;
|
|
166
79
|
const strictMessage = isBoolean(options.strictMessage) ? options.strictMessage : true;
|
|
@@ -171,6 +84,7 @@ function resolveOptions(options, installedPkgInfo) {
|
|
|
171
84
|
return {
|
|
172
85
|
include,
|
|
173
86
|
exclude,
|
|
87
|
+
module: moduleType,
|
|
174
88
|
onlyLocales,
|
|
175
89
|
forceStringify,
|
|
176
90
|
defaultSFCLang,
|
|
@@ -261,6 +175,7 @@ function resourcePlugin({
|
|
|
261
175
|
onlyLocales,
|
|
262
176
|
include,
|
|
263
177
|
exclude,
|
|
178
|
+
module,
|
|
264
179
|
forceStringify,
|
|
265
180
|
defaultSFCLang,
|
|
266
181
|
globalSFCScope,
|
|
@@ -273,14 +188,14 @@ function resourcePlugin({
|
|
|
273
188
|
allowDynamic,
|
|
274
189
|
escapeHtml,
|
|
275
190
|
transformI18nBlock
|
|
276
|
-
}, meta
|
|
191
|
+
}, meta) {
|
|
277
192
|
const filter = createFilter(include, exclude);
|
|
278
193
|
const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
|
|
279
|
-
return `${
|
|
194
|
+
return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
|
|
280
195
|
};
|
|
281
196
|
let isProduction = false;
|
|
282
197
|
let sourceMap = false;
|
|
283
|
-
const vueI18nAliasName =
|
|
198
|
+
const vueI18nAliasName = module;
|
|
284
199
|
debug$2(`vue-i18n alias name: ${vueI18nAliasName}`);
|
|
285
200
|
let vuePlugin = null;
|
|
286
201
|
const getSfcParser = () => {
|
|
@@ -397,12 +312,12 @@ function resourcePlugin({
|
|
|
397
312
|
},
|
|
398
313
|
async handleHotUpdate({ file, server }) {
|
|
399
314
|
if (/\.(json5?|ya?ml)$/.test(file)) {
|
|
400
|
-
const
|
|
315
|
+
const module2 = server.moduleGraph.getModuleById(
|
|
401
316
|
asVirtualId(INTLIFY_BUNDLE_IMPORT_ID, meta.framework)
|
|
402
317
|
);
|
|
403
|
-
if (
|
|
404
|
-
server.moduleGraph.invalidateModule(
|
|
405
|
-
return [
|
|
318
|
+
if (module2) {
|
|
319
|
+
server.moduleGraph.invalidateModule(module2);
|
|
320
|
+
return [module2];
|
|
406
321
|
}
|
|
407
322
|
}
|
|
408
323
|
}
|
|
@@ -1038,16 +953,15 @@ function resolveIdentifier(localVariables, returnVariable) {
|
|
|
1038
953
|
}
|
|
1039
954
|
|
|
1040
955
|
const debug = createDebug(resolveNamespace("root"));
|
|
1041
|
-
const installedPkgInfo = checkInstallPackage(debug);
|
|
1042
956
|
const unpluginFactory = (options = {}, meta) => {
|
|
1043
957
|
debug("meta framework", meta.framework);
|
|
1044
958
|
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
1045
959
|
raiseError(`This plugin is supported 'vite' and 'webpack' only`);
|
|
1046
960
|
}
|
|
1047
961
|
debug("plugin options (resolving):", options);
|
|
1048
|
-
const resolvedOptions = resolveOptions(options
|
|
962
|
+
const resolvedOptions = resolveOptions(options);
|
|
1049
963
|
debug("plugin options (resolved):", resolvedOptions);
|
|
1050
|
-
const plugins = [resourcePlugin(resolvedOptions, meta
|
|
964
|
+
const plugins = [resourcePlugin(resolvedOptions, meta)];
|
|
1051
965
|
if (resolvedOptions.optimizeTranslationDirective) {
|
|
1052
966
|
if (meta.framework === "webpack") {
|
|
1053
967
|
raiseError(
|
package/lib/types.d.cts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
|
|
2
|
+
type VueI18nModule = 'vue-i18n' | 'petite-vue-i18n';
|
|
2
3
|
interface PluginOptions {
|
|
3
4
|
include?: string | string[];
|
|
4
5
|
onlyLocales?: string | string[];
|
|
5
6
|
allowDynamic?: boolean;
|
|
7
|
+
module?: VueI18nModule;
|
|
6
8
|
dropMessageCompiler?: boolean;
|
|
7
9
|
runtimeOnly?: boolean;
|
|
8
10
|
compositionOnly?: boolean;
|
|
@@ -17,4 +19,4 @@ interface PluginOptions {
|
|
|
17
19
|
transformI18nBlock?: (src: string | Buffer) => string;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
export type { PluginOptions, SFCLangFormat };
|
|
22
|
+
export type { PluginOptions, SFCLangFormat, VueI18nModule };
|
package/lib/types.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
|
|
2
|
+
type VueI18nModule = 'vue-i18n' | 'petite-vue-i18n';
|
|
2
3
|
interface PluginOptions {
|
|
3
4
|
include?: string | string[];
|
|
4
5
|
onlyLocales?: string | string[];
|
|
5
6
|
allowDynamic?: boolean;
|
|
7
|
+
module?: VueI18nModule;
|
|
6
8
|
dropMessageCompiler?: boolean;
|
|
7
9
|
runtimeOnly?: boolean;
|
|
8
10
|
compositionOnly?: boolean;
|
|
@@ -17,4 +19,4 @@ interface PluginOptions {
|
|
|
17
19
|
transformI18nBlock?: (src: string | Buffer) => string;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
export type { PluginOptions, SFCLangFormat };
|
|
22
|
+
export type { PluginOptions, SFCLangFormat, VueI18nModule };
|
package/lib/types.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
|
|
2
|
+
type VueI18nModule = 'vue-i18n' | 'petite-vue-i18n';
|
|
2
3
|
interface PluginOptions {
|
|
3
4
|
include?: string | string[];
|
|
4
5
|
onlyLocales?: string | string[];
|
|
5
6
|
allowDynamic?: boolean;
|
|
7
|
+
module?: VueI18nModule;
|
|
6
8
|
dropMessageCompiler?: boolean;
|
|
7
9
|
runtimeOnly?: boolean;
|
|
8
10
|
compositionOnly?: boolean;
|
|
@@ -17,4 +19,4 @@ interface PluginOptions {
|
|
|
17
19
|
transformI18nBlock?: (src: string | Buffer) => string;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
export type { PluginOptions, SFCLangFormat };
|
|
22
|
+
export type { PluginOptions, SFCLangFormat, VueI18nModule };
|
package/lib/vite.cjs
CHANGED
|
@@ -5,12 +5,10 @@ const index = require('./index.cjs');
|
|
|
5
5
|
require('debug');
|
|
6
6
|
require('picocolors');
|
|
7
7
|
require('node:path');
|
|
8
|
-
require('node:fs');
|
|
9
|
-
require('node:module');
|
|
10
8
|
require('pathe');
|
|
11
|
-
require('mlly');
|
|
12
9
|
require('@intlify/shared');
|
|
13
10
|
require('fast-glob');
|
|
11
|
+
require('node:fs');
|
|
14
12
|
require('@rollup/pluginutils');
|
|
15
13
|
require('@intlify/bundle-utils');
|
|
16
14
|
require('vue/compiler-sfc');
|
package/lib/vite.mjs
CHANGED
|
@@ -3,12 +3,10 @@ import { unpluginFactory } from './index.mjs';
|
|
|
3
3
|
import 'debug';
|
|
4
4
|
import 'picocolors';
|
|
5
5
|
import 'node:path';
|
|
6
|
-
import 'node:fs';
|
|
7
|
-
import 'node:module';
|
|
8
6
|
import 'pathe';
|
|
9
|
-
import 'mlly';
|
|
10
7
|
import '@intlify/shared';
|
|
11
8
|
import 'fast-glob';
|
|
9
|
+
import 'node:fs';
|
|
12
10
|
import '@rollup/pluginutils';
|
|
13
11
|
import '@intlify/bundle-utils';
|
|
14
12
|
import 'vue/compiler-sfc';
|
package/lib/webpack.cjs
CHANGED
|
@@ -5,12 +5,10 @@ const index = require('./index.cjs');
|
|
|
5
5
|
require('debug');
|
|
6
6
|
require('picocolors');
|
|
7
7
|
require('node:path');
|
|
8
|
-
require('node:fs');
|
|
9
|
-
require('node:module');
|
|
10
8
|
require('pathe');
|
|
11
|
-
require('mlly');
|
|
12
9
|
require('@intlify/shared');
|
|
13
10
|
require('fast-glob');
|
|
11
|
+
require('node:fs');
|
|
14
12
|
require('@rollup/pluginutils');
|
|
15
13
|
require('@intlify/bundle-utils');
|
|
16
14
|
require('vue/compiler-sfc');
|
package/lib/webpack.mjs
CHANGED
|
@@ -3,12 +3,10 @@ import { unpluginFactory } from './index.mjs';
|
|
|
3
3
|
import 'debug';
|
|
4
4
|
import 'picocolors';
|
|
5
5
|
import 'node:path';
|
|
6
|
-
import 'node:fs';
|
|
7
|
-
import 'node:module';
|
|
8
6
|
import 'pathe';
|
|
9
|
-
import 'mlly';
|
|
10
7
|
import '@intlify/shared';
|
|
11
8
|
import 'fast-glob';
|
|
9
|
+
import 'node:fs';
|
|
12
10
|
import '@rollup/pluginutils';
|
|
13
11
|
import '@intlify/bundle-utils';
|
|
14
12
|
import 'vue/compiler-sfc';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "unplugin for Vue I18n",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"@eslint-community/eslint-utils": "^4.4.0",
|
|
27
27
|
"@intlify/bundle-utils": "^9.0.0-beta.0",
|
|
28
28
|
"@intlify/shared": "next",
|
|
29
|
-
"@intlify/vue-i18n-extensions": "^
|
|
29
|
+
"@intlify/vue-i18n-extensions": "^7.0.0",
|
|
30
30
|
"@rollup/pluginutils": "^5.1.0",
|
|
31
31
|
"@typescript-eslint/scope-manager": "^7.13.0",
|
|
32
32
|
"@typescript-eslint/typescript-estree": "^7.13.0",
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
"fast-glob": "^3.2.12",
|
|
35
35
|
"js-yaml": "^4.1.0",
|
|
36
36
|
"json5": "^2.2.3",
|
|
37
|
-
"mlly": "^1.7.1",
|
|
38
37
|
"pathe": "^1.0.0",
|
|
39
38
|
"picocolors": "^1.0.0",
|
|
40
39
|
"source-map-js": "^1.0.2",
|