@intlify/unplugin-vue-i18n 0.7.1 → 0.7.3
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/lib/index.cjs +66 -18
- package/lib/index.mjs +67 -19
- package/package.json +4 -4
package/lib/index.cjs
CHANGED
|
@@ -103,6 +103,7 @@ const VIRTUAL_PREFIX = "\0";
|
|
|
103
103
|
const debug = createDebug__default("unplugin-vue-i18n");
|
|
104
104
|
const installedPkg = bundleUtils.checkInstallPackage("@intlify/unplugin-vue-i18n", debug);
|
|
105
105
|
const installedVueI18nBridge = bundleUtils.checkVueI18nBridgeInstallPackage(debug);
|
|
106
|
+
const vueI18nVersion = bundleUtils.getVueI18nVersion(debug);
|
|
106
107
|
const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
107
108
|
debug("plugin options:", options, meta.framework);
|
|
108
109
|
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
@@ -137,42 +138,66 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
137
138
|
warn(`'useVueI18nImportName' option is experimental`);
|
|
138
139
|
}
|
|
139
140
|
debug("useVueI18nImportName", useVueI18nImportName);
|
|
140
|
-
const
|
|
141
|
+
const getVueI18nAliasName = () => vueI18nVersion === "9" || vueI18nVersion === "8" ? "vue-i18n" : vueI18nVersion === "unknown" && installedPkg === "petite-vue-i18n" && shared.isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : installedPkg;
|
|
142
|
+
const getVueI18nBridgeAliasPath = () => `vue-i18n-bridge/dist/vue-i18n-bridge.runtime.esm-bundler.js`;
|
|
143
|
+
const getVueI18nAliasPath = (aliasName) => vueI18nVersion === "8" ? `${aliasName}/dist/${aliasName}.esm.js` : `${aliasName}/dist/${installedPkg}.runtime.esm-bundler.js`;
|
|
141
144
|
const esm = shared.isBoolean(options.esm) ? options.esm : true;
|
|
142
145
|
debug("esm", esm);
|
|
143
146
|
let isProduction = false;
|
|
144
147
|
let sourceMap = false;
|
|
148
|
+
const vueI18nAliasName = getVueI18nAliasName();
|
|
145
149
|
return {
|
|
146
150
|
name: "unplugin-vue-i18n",
|
|
147
151
|
enforce: meta.framework === "vite" ? "pre" : "post",
|
|
148
152
|
vite: {
|
|
149
153
|
config(config, { command }) {
|
|
150
|
-
|
|
154
|
+
config.resolve = normalizeConfigResolveAlias(
|
|
155
|
+
config.resolve,
|
|
156
|
+
meta.framework
|
|
157
|
+
);
|
|
151
158
|
if (command === "build" && runtimeOnly) {
|
|
152
|
-
|
|
153
|
-
debug(`alias name: ${aliasName}`);
|
|
159
|
+
debug(`vue-i18n alias name: ${vueI18nAliasName}`);
|
|
154
160
|
if (shared.isArray(config.resolve.alias)) {
|
|
155
161
|
config.resolve.alias.push({
|
|
156
|
-
find:
|
|
157
|
-
replacement:
|
|
162
|
+
find: vueI18nAliasName,
|
|
163
|
+
replacement: getVueI18nAliasPath(vueI18nAliasName)
|
|
158
164
|
});
|
|
165
|
+
if (installedVueI18nBridge) {
|
|
166
|
+
config.resolve.alias.push({
|
|
167
|
+
find: "vue-i18n-bridge",
|
|
168
|
+
replacement: getVueI18nBridgeAliasPath()
|
|
169
|
+
});
|
|
170
|
+
}
|
|
159
171
|
} else if (shared.isObject(config.resolve.alias)) {
|
|
160
|
-
config.resolve.alias[
|
|
172
|
+
config.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName);
|
|
173
|
+
if (installedVueI18nBridge) {
|
|
174
|
+
config.resolve.alias["vue-i18n-bridge"] = getVueI18nBridgeAliasPath();
|
|
175
|
+
}
|
|
161
176
|
}
|
|
162
177
|
debug(
|
|
163
|
-
`set ${
|
|
178
|
+
`set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
|
|
179
|
+
vueI18nAliasName
|
|
180
|
+
)}`
|
|
164
181
|
);
|
|
182
|
+
if (installedVueI18nBridge) {
|
|
183
|
+
debug(
|
|
184
|
+
`set vue-i18n-bridge runtime only: ${getVueI18nBridgeAliasPath()}`
|
|
185
|
+
);
|
|
186
|
+
}
|
|
165
187
|
} else if (command === "serve" && installedPkg === "petite-vue-i18n" && useVueI18nImportName) {
|
|
166
|
-
|
|
188
|
+
config.resolve = normalizeConfigResolveAlias(
|
|
189
|
+
config.resolve,
|
|
190
|
+
meta.framework
|
|
191
|
+
);
|
|
167
192
|
if (shared.isArray(config.resolve.alias)) {
|
|
168
193
|
config.resolve.alias.push({
|
|
169
|
-
find:
|
|
194
|
+
find: vueI18nAliasName,
|
|
170
195
|
replacement: `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`
|
|
171
196
|
});
|
|
172
197
|
} else {
|
|
173
|
-
config.resolve.alias[
|
|
198
|
+
config.resolve.alias[vueI18nAliasName] = `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`;
|
|
174
199
|
}
|
|
175
|
-
debug(`alias name: ${
|
|
200
|
+
debug(`petite-vue-i18n alias name: ${vueI18nAliasName}`);
|
|
176
201
|
}
|
|
177
202
|
config.define = config.define || {};
|
|
178
203
|
config.define["__VUE_I18N_LEGACY_API__"] = !compositionOnly;
|
|
@@ -223,9 +248,28 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
223
248
|
isProduction = compiler.options.mode !== "development";
|
|
224
249
|
sourceMap = !!compiler.options.devtool;
|
|
225
250
|
debug(`webpack: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
|
|
251
|
+
compiler.options.resolve = normalizeConfigResolveAlias(
|
|
252
|
+
compiler.options.resolve,
|
|
253
|
+
meta.framework
|
|
254
|
+
);
|
|
226
255
|
if (isProduction && runtimeOnly) {
|
|
227
|
-
|
|
228
|
-
|
|
256
|
+
compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName);
|
|
257
|
+
if (installedVueI18nBridge) {
|
|
258
|
+
compiler.options.resolve.alias["vue-i18n-bridge"] = getVueI18nBridgeAliasPath();
|
|
259
|
+
}
|
|
260
|
+
debug(
|
|
261
|
+
`set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
|
|
262
|
+
vueI18nAliasName
|
|
263
|
+
)}`
|
|
264
|
+
);
|
|
265
|
+
if (installedVueI18nBridge) {
|
|
266
|
+
debug(
|
|
267
|
+
`set vue-i18n-bridge runtime only: ${getVueI18nBridgeAliasPath()}`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
} else if (!isProduction && installedPkg === "petite-vue-i18n" && useVueI18nImportName) {
|
|
271
|
+
compiler.options.resolve.alias[vueI18nAliasName] = `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`;
|
|
272
|
+
debug(`petite-vue-i18n alias name: ${vueI18nAliasName}`);
|
|
229
273
|
}
|
|
230
274
|
loadWebpack().then((webpack) => {
|
|
231
275
|
if (webpack) {
|
|
@@ -246,7 +290,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
246
290
|
compiler.options.module.rules.push({
|
|
247
291
|
test: /\.(json5?|ya?ml)$/,
|
|
248
292
|
type: "javascript/auto",
|
|
249
|
-
|
|
293
|
+
include(resource) {
|
|
294
|
+
return filter(resource);
|
|
295
|
+
}
|
|
250
296
|
});
|
|
251
297
|
}
|
|
252
298
|
},
|
|
@@ -396,19 +442,21 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
396
442
|
});
|
|
397
443
|
function normalizeConfigResolveAlias(resolve, framework) {
|
|
398
444
|
if (resolve && resolve.alias) {
|
|
399
|
-
return;
|
|
445
|
+
return resolve;
|
|
400
446
|
}
|
|
401
447
|
if (!resolve) {
|
|
402
448
|
if (framework === "vite") {
|
|
403
|
-
|
|
449
|
+
return { alias: [] };
|
|
404
450
|
} else if (framework === "webpack") {
|
|
405
|
-
|
|
451
|
+
return { alias: {} };
|
|
406
452
|
}
|
|
407
453
|
} else if (!resolve.alias) {
|
|
408
454
|
if (framework === "vite") {
|
|
409
455
|
resolve.alias = [];
|
|
456
|
+
return resolve;
|
|
410
457
|
} else if (framework === "webpack") {
|
|
411
458
|
resolve.alias = {};
|
|
459
|
+
return resolve;
|
|
412
460
|
}
|
|
413
461
|
}
|
|
414
462
|
}
|
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, generateJSON, generateYAML } from '@intlify/bundle-utils';
|
|
7
|
+
import { checkInstallPackage, checkVueI18nBridgeInstallPackage, getVueI18nVersion, 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';
|
|
@@ -91,6 +91,7 @@ const VIRTUAL_PREFIX = "\0";
|
|
|
91
91
|
const debug = createDebug("unplugin-vue-i18n");
|
|
92
92
|
const installedPkg = checkInstallPackage("@intlify/unplugin-vue-i18n", debug);
|
|
93
93
|
const installedVueI18nBridge = checkVueI18nBridgeInstallPackage(debug);
|
|
94
|
+
const vueI18nVersion = getVueI18nVersion(debug);
|
|
94
95
|
const unplugin = createUnplugin((options = {}, meta) => {
|
|
95
96
|
debug("plugin options:", options, meta.framework);
|
|
96
97
|
if (!["vite", "webpack"].includes(meta.framework)) {
|
|
@@ -125,42 +126,66 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
125
126
|
warn(`'useVueI18nImportName' option is experimental`);
|
|
126
127
|
}
|
|
127
128
|
debug("useVueI18nImportName", useVueI18nImportName);
|
|
128
|
-
const
|
|
129
|
+
const getVueI18nAliasName = () => vueI18nVersion === "9" || vueI18nVersion === "8" ? "vue-i18n" : vueI18nVersion === "unknown" && installedPkg === "petite-vue-i18n" && isBoolean(useVueI18nImportName) && useVueI18nImportName ? "vue-i18n" : installedPkg;
|
|
130
|
+
const getVueI18nBridgeAliasPath = () => `vue-i18n-bridge/dist/vue-i18n-bridge.runtime.esm-bundler.js`;
|
|
131
|
+
const getVueI18nAliasPath = (aliasName) => vueI18nVersion === "8" ? `${aliasName}/dist/${aliasName}.esm.js` : `${aliasName}/dist/${installedPkg}.runtime.esm-bundler.js`;
|
|
129
132
|
const esm = isBoolean(options.esm) ? options.esm : true;
|
|
130
133
|
debug("esm", esm);
|
|
131
134
|
let isProduction = false;
|
|
132
135
|
let sourceMap = false;
|
|
136
|
+
const vueI18nAliasName = getVueI18nAliasName();
|
|
133
137
|
return {
|
|
134
138
|
name: "unplugin-vue-i18n",
|
|
135
139
|
enforce: meta.framework === "vite" ? "pre" : "post",
|
|
136
140
|
vite: {
|
|
137
141
|
config(config, { command }) {
|
|
138
|
-
|
|
142
|
+
config.resolve = normalizeConfigResolveAlias(
|
|
143
|
+
config.resolve,
|
|
144
|
+
meta.framework
|
|
145
|
+
);
|
|
139
146
|
if (command === "build" && runtimeOnly) {
|
|
140
|
-
|
|
141
|
-
debug(`alias name: ${aliasName}`);
|
|
147
|
+
debug(`vue-i18n alias name: ${vueI18nAliasName}`);
|
|
142
148
|
if (isArray(config.resolve.alias)) {
|
|
143
149
|
config.resolve.alias.push({
|
|
144
|
-
find:
|
|
145
|
-
replacement:
|
|
150
|
+
find: vueI18nAliasName,
|
|
151
|
+
replacement: getVueI18nAliasPath(vueI18nAliasName)
|
|
146
152
|
});
|
|
153
|
+
if (installedVueI18nBridge) {
|
|
154
|
+
config.resolve.alias.push({
|
|
155
|
+
find: "vue-i18n-bridge",
|
|
156
|
+
replacement: getVueI18nBridgeAliasPath()
|
|
157
|
+
});
|
|
158
|
+
}
|
|
147
159
|
} else if (isObject(config.resolve.alias)) {
|
|
148
|
-
config.resolve.alias[
|
|
160
|
+
config.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName);
|
|
161
|
+
if (installedVueI18nBridge) {
|
|
162
|
+
config.resolve.alias["vue-i18n-bridge"] = getVueI18nBridgeAliasPath();
|
|
163
|
+
}
|
|
149
164
|
}
|
|
150
165
|
debug(
|
|
151
|
-
`set ${
|
|
166
|
+
`set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
|
|
167
|
+
vueI18nAliasName
|
|
168
|
+
)}`
|
|
152
169
|
);
|
|
170
|
+
if (installedVueI18nBridge) {
|
|
171
|
+
debug(
|
|
172
|
+
`set vue-i18n-bridge runtime only: ${getVueI18nBridgeAliasPath()}`
|
|
173
|
+
);
|
|
174
|
+
}
|
|
153
175
|
} else if (command === "serve" && installedPkg === "petite-vue-i18n" && useVueI18nImportName) {
|
|
154
|
-
|
|
176
|
+
config.resolve = normalizeConfigResolveAlias(
|
|
177
|
+
config.resolve,
|
|
178
|
+
meta.framework
|
|
179
|
+
);
|
|
155
180
|
if (isArray(config.resolve.alias)) {
|
|
156
181
|
config.resolve.alias.push({
|
|
157
|
-
find:
|
|
182
|
+
find: vueI18nAliasName,
|
|
158
183
|
replacement: `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`
|
|
159
184
|
});
|
|
160
185
|
} else {
|
|
161
|
-
config.resolve.alias[
|
|
186
|
+
config.resolve.alias[vueI18nAliasName] = `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`;
|
|
162
187
|
}
|
|
163
|
-
debug(`alias name: ${
|
|
188
|
+
debug(`petite-vue-i18n alias name: ${vueI18nAliasName}`);
|
|
164
189
|
}
|
|
165
190
|
config.define = config.define || {};
|
|
166
191
|
config.define["__VUE_I18N_LEGACY_API__"] = !compositionOnly;
|
|
@@ -211,9 +236,28 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
211
236
|
isProduction = compiler.options.mode !== "development";
|
|
212
237
|
sourceMap = !!compiler.options.devtool;
|
|
213
238
|
debug(`webpack: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
|
|
239
|
+
compiler.options.resolve = normalizeConfigResolveAlias(
|
|
240
|
+
compiler.options.resolve,
|
|
241
|
+
meta.framework
|
|
242
|
+
);
|
|
214
243
|
if (isProduction && runtimeOnly) {
|
|
215
|
-
|
|
216
|
-
|
|
244
|
+
compiler.options.resolve.alias[vueI18nAliasName] = getVueI18nAliasPath(vueI18nAliasName);
|
|
245
|
+
if (installedVueI18nBridge) {
|
|
246
|
+
compiler.options.resolve.alias["vue-i18n-bridge"] = getVueI18nBridgeAliasPath();
|
|
247
|
+
}
|
|
248
|
+
debug(
|
|
249
|
+
`set ${vueI18nAliasName} runtime only: ${getVueI18nAliasPath(
|
|
250
|
+
vueI18nAliasName
|
|
251
|
+
)}`
|
|
252
|
+
);
|
|
253
|
+
if (installedVueI18nBridge) {
|
|
254
|
+
debug(
|
|
255
|
+
`set vue-i18n-bridge runtime only: ${getVueI18nBridgeAliasPath()}`
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
} else if (!isProduction && installedPkg === "petite-vue-i18n" && useVueI18nImportName) {
|
|
259
|
+
compiler.options.resolve.alias[vueI18nAliasName] = `petite-vue-i18n/dist/petite-vue-i18n.esm-bundler.js`;
|
|
260
|
+
debug(`petite-vue-i18n alias name: ${vueI18nAliasName}`);
|
|
217
261
|
}
|
|
218
262
|
loadWebpack().then((webpack) => {
|
|
219
263
|
if (webpack) {
|
|
@@ -234,7 +278,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
234
278
|
compiler.options.module.rules.push({
|
|
235
279
|
test: /\.(json5?|ya?ml)$/,
|
|
236
280
|
type: "javascript/auto",
|
|
237
|
-
|
|
281
|
+
include(resource) {
|
|
282
|
+
return filter(resource);
|
|
283
|
+
}
|
|
238
284
|
});
|
|
239
285
|
}
|
|
240
286
|
},
|
|
@@ -384,19 +430,21 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
384
430
|
});
|
|
385
431
|
function normalizeConfigResolveAlias(resolve, framework) {
|
|
386
432
|
if (resolve && resolve.alias) {
|
|
387
|
-
return;
|
|
433
|
+
return resolve;
|
|
388
434
|
}
|
|
389
435
|
if (!resolve) {
|
|
390
436
|
if (framework === "vite") {
|
|
391
|
-
|
|
437
|
+
return { alias: [] };
|
|
392
438
|
} else if (framework === "webpack") {
|
|
393
|
-
|
|
439
|
+
return { alias: {} };
|
|
394
440
|
}
|
|
395
441
|
} else if (!resolve.alias) {
|
|
396
442
|
if (framework === "vite") {
|
|
397
443
|
resolve.alias = [];
|
|
444
|
+
return resolve;
|
|
398
445
|
} else if (framework === "webpack") {
|
|
399
446
|
resolve.alias = {};
|
|
447
|
+
return resolve;
|
|
400
448
|
}
|
|
401
449
|
}
|
|
402
450
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"description": "unplugin for Vue I18n",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
@@ -26,15 +26,15 @@
|
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@intlify/bundle-utils": "^3.
|
|
29
|
+
"@intlify/bundle-utils": "^3.4.0",
|
|
30
30
|
"@intlify/shared": "next",
|
|
31
31
|
"@rollup/pluginutils": "^4.2.0",
|
|
32
|
-
"@vue/compiler-sfc": "^3.2.
|
|
32
|
+
"@vue/compiler-sfc": "^3.2.45",
|
|
33
33
|
"debug": "^4.3.1",
|
|
34
34
|
"fast-glob": "^3.2.5",
|
|
35
35
|
"js-yaml": "^4.1.0",
|
|
36
36
|
"json5": "^2.2.0",
|
|
37
|
-
"pathe": "^0.
|
|
37
|
+
"pathe": "^0.3.9",
|
|
38
38
|
"picocolors": "^1.0.0",
|
|
39
39
|
"source-map": "0.6.1",
|
|
40
40
|
"unplugin": "^0.8.0"
|