@intlify/unplugin-vue-i18n 0.2.0 → 0.4.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 +84 -3
- package/lib/index.cjs +87 -1
- package/lib/index.mjs +88 -2
- package/lib/types.d.ts +4 -0
- package/package.json +1 -1
- package/CHANGELOG.md +0 -39
package/README.md
CHANGED
|
@@ -28,11 +28,11 @@ npm i @intlify/unplugin-vue-i18n
|
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
30
|
// vite.config.ts
|
|
31
|
-
import
|
|
31
|
+
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
|
|
32
32
|
|
|
33
33
|
export default defineConfig({
|
|
34
34
|
plugins: [
|
|
35
|
-
|
|
35
|
+
VueI18nPlugin({ /* options */ }),
|
|
36
36
|
],
|
|
37
37
|
})
|
|
38
38
|
```
|
|
@@ -56,6 +56,32 @@ module.exports = {
|
|
|
56
56
|
|
|
57
57
|
<br></details>
|
|
58
58
|
|
|
59
|
+
<details>
|
|
60
|
+
<summary>Nuxt</summary><br>
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
// nuxt.config.ts
|
|
64
|
+
import { defineNuxtConfig } from 'nuxt'
|
|
65
|
+
import VueI18nPlugin from '@intlify/unplugin-vue-i18n'
|
|
66
|
+
|
|
67
|
+
export default defineNuxtConfig({
|
|
68
|
+
vite: {
|
|
69
|
+
plugins: [
|
|
70
|
+
VueI18nPlugin.vite({ /* options */ }),
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
// When using Webpack
|
|
74
|
+
// builder: '@nuxt/webpack-builder',
|
|
75
|
+
webpack: {
|
|
76
|
+
plugins: [
|
|
77
|
+
VueI18nPlugin.webpack({ /* options */ }),
|
|
78
|
+
]
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
<br></details>
|
|
84
|
+
|
|
59
85
|
## 🚀 Usage
|
|
60
86
|
|
|
61
87
|
### i18n resources pre-compilation
|
|
@@ -199,6 +225,19 @@ If you want type definition of `@intlify/unplugin-vue-i18n/messages`, add `unplu
|
|
|
199
225
|
}
|
|
200
226
|
```
|
|
201
227
|
|
|
228
|
+
|
|
229
|
+
## 📦 Automatic bundling
|
|
230
|
+
### For Vue I18n
|
|
231
|
+
As noted [here](https://vue-i18n.intlify.dev/installation.html#explanation-of-different-builds), NPM provides many different builds of Vue I18n.
|
|
232
|
+
|
|
233
|
+
This plugin will automatically select and bundle Vue I18n build according to the following behavior:
|
|
234
|
+
|
|
235
|
+
- development: `vue-i18n.esm-bundler.js`
|
|
236
|
+
- production: `vue-i18n.runtime.esm-bundler.js`
|
|
237
|
+
|
|
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
|
+
|
|
240
|
+
|
|
202
241
|
## 🔧 Options
|
|
203
242
|
|
|
204
243
|
### `include`
|
|
@@ -217,6 +256,42 @@ If you want type definition of `@intlify/unplugin-vue-i18n/messages`, add `unplu
|
|
|
217
256
|
|
|
218
257
|
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.
|
|
219
258
|
|
|
259
|
+
### `runtimeOnly`
|
|
260
|
+
|
|
261
|
+
- **Type:** `boolean`
|
|
262
|
+
- **Default:** `true`
|
|
263
|
+
|
|
264
|
+
Whether or not to automatically use Vue I18n **runtime-only** in production build, set `vue-i18n.runtime.esm-bundler.js` in the `vue-i18n` field of bundler config, the below:
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
- vite config: `resolve.alias`
|
|
268
|
+
- webpack config: `resolve.alias`
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
If `false` is specified, Vue I18n (vue-i18n) package.json `module` field will be used.
|
|
272
|
+
|
|
273
|
+
For more details, See [here](#-automatic-bundling)
|
|
274
|
+
|
|
275
|
+
### `compositionOnly`
|
|
276
|
+
|
|
277
|
+
- **Type:** `boolean`
|
|
278
|
+
- **Default:** `true`
|
|
279
|
+
|
|
280
|
+
Whether to make vue-i18n API only composition API. **By default the legacy API is tree-shaken.**
|
|
281
|
+
|
|
282
|
+
For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)
|
|
283
|
+
|
|
284
|
+
### `fullInstall`
|
|
285
|
+
|
|
286
|
+
- **Type:** `boolean`
|
|
287
|
+
- **Default:** `true`
|
|
288
|
+
|
|
289
|
+
Whether to install the full set of APIs, components, etc. provided by Vue I18n. By default, all of them will be installed.
|
|
290
|
+
|
|
291
|
+
If `false` is specified, **buld-in components and directive will not be installed in vue and will be tree-shaken.**
|
|
292
|
+
|
|
293
|
+
For more details, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#reduce-bundle-size-with-feature-build-flags)
|
|
294
|
+
|
|
220
295
|
### `forceStringify`
|
|
221
296
|
|
|
222
297
|
- **Type:** `boolean`
|
|
@@ -339,6 +414,13 @@ If you want type definition of `@intlify/unplugin-vue-i18n/messages`, add `unplu
|
|
|
339
414
|
|
|
340
415
|
> ⚠️ Note that if you set `bridge: true`, the bundle size will increase. It is recommended to disable this mode after the migration from vue-i18n@v8.26 to vue-i18n@v9.x is completed.
|
|
341
416
|
|
|
417
|
+
### `esm`
|
|
418
|
+
|
|
419
|
+
- **Type:** `boolean`
|
|
420
|
+
- **Default:** `true`
|
|
421
|
+
|
|
422
|
+
For `bridge` option is `true`, whether to bundle locale resources with ESM. By default ESM, if you need to bundl with commonjs for especialy webpack, you need to set `false`
|
|
423
|
+
|
|
342
424
|
### `useClassComponent`
|
|
343
425
|
|
|
344
426
|
- **Type:** `boolean`
|
|
@@ -349,7 +431,6 @@ If you want type definition of `@intlify/unplugin-vue-i18n/messages`, add `unplu
|
|
|
349
431
|
|
|
350
432
|
## ✅ TODO
|
|
351
433
|
- [ ] Bundling optimizations
|
|
352
|
-
- [ ] Support nuxt
|
|
353
434
|
|
|
354
435
|
## 📜 Changelog
|
|
355
436
|
|
package/lib/index.cjs
CHANGED
|
@@ -116,12 +116,48 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
116
116
|
const useClassComponent = !!options.useClassComponent;
|
|
117
117
|
const bridge = !!options.bridge;
|
|
118
118
|
debug("bridge", bridge);
|
|
119
|
+
const runtimeOnly = shared.isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
120
|
+
debug("runtimeOnly", runtimeOnly);
|
|
121
|
+
const compositionOnly = shared.isBoolean(options.compositionOnly) ? options.compositionOnly : true;
|
|
122
|
+
debug("compositionOnly", compositionOnly);
|
|
123
|
+
const fullInstall = shared.isBoolean(options.fullInstall) ? options.fullInstall : true;
|
|
124
|
+
debug("fullInstall", fullInstall);
|
|
125
|
+
const esm = shared.isBoolean(options.esm) ? options.esm : true;
|
|
126
|
+
debug("esm", esm);
|
|
119
127
|
let isProduction = false;
|
|
120
128
|
let sourceMap = false;
|
|
121
129
|
return {
|
|
122
130
|
name: "unplugin-vue-i18n",
|
|
123
131
|
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
|
+
},
|
|
124
141
|
vite: {
|
|
142
|
+
config(config, { command }) {
|
|
143
|
+
normalizeConfigResolveAlias(config.resolve, meta.framework);
|
|
144
|
+
if (command === "build" && runtimeOnly) {
|
|
145
|
+
if (shared.isArray(config.resolve.alias)) {
|
|
146
|
+
config.resolve.alias.push({
|
|
147
|
+
find: "vue-i18n",
|
|
148
|
+
replacement: `vue-i18n/dist/vue-i18n.runtime.esm-bundler.js`
|
|
149
|
+
});
|
|
150
|
+
} else if (shared.isObject(config.resolve.alias)) {
|
|
151
|
+
config.resolve.alias["vue-i18n"] = `vue-i18n/dist/vue-i18n.runtime.esm-bundler.js`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
config.define = config.define || {};
|
|
155
|
+
config.define["__VUE_I18N_LEGACY_API__"] = !compositionOnly;
|
|
156
|
+
debug(`set __VUE_I18N_LEGACY_API__ is '${config.define["__VUE_I18N_LEGACY_API__"]}'`);
|
|
157
|
+
config.define["__VUE_I18N_FULL_INSTALL__"] = fullInstall;
|
|
158
|
+
debug(`set __VUE_I18N_FULL_INSTALL__ is '${config.define["__VUE_I18N_FULL_INSTALL__"]}'`);
|
|
159
|
+
config.define["__VUE_I18N_PROD_DEVTOOLS__"] = false;
|
|
160
|
+
},
|
|
125
161
|
configResolved(config) {
|
|
126
162
|
isProduction = config.isProduction;
|
|
127
163
|
sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
|
|
@@ -147,6 +183,23 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
147
183
|
isProduction = compiler.options.mode !== "development";
|
|
148
184
|
sourceMap = !!compiler.options.devtool;
|
|
149
185
|
debug(`webpack: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
|
|
186
|
+
if (isProduction && runtimeOnly) {
|
|
187
|
+
normalizeConfigResolveAlias(compiler.options.resolve, meta.framework);
|
|
188
|
+
compiler.options.resolve.alias["vue-i18n"] = `vue-i18n/dist/vue-i18n.runtime.esm-bundler.js`;
|
|
189
|
+
}
|
|
190
|
+
loadWebpack().then((webpack) => {
|
|
191
|
+
if (webpack) {
|
|
192
|
+
compiler.options.plugins.push(new webpack.DefinePlugin({
|
|
193
|
+
__VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
|
|
194
|
+
__VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
|
|
195
|
+
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
196
|
+
}));
|
|
197
|
+
debug(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
|
|
198
|
+
debug(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
199
|
+
} else {
|
|
200
|
+
debug("ignore vue-i18n feature flags with webpack.DefinePlugin");
|
|
201
|
+
}
|
|
202
|
+
});
|
|
150
203
|
if (compiler.options.module) {
|
|
151
204
|
compiler.options.module.rules.push({
|
|
152
205
|
test: /\.(json5?|ya?ml)$/,
|
|
@@ -178,6 +231,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
178
231
|
const code = await generateBundleResources(resourcePaths, query, isProduction, {
|
|
179
232
|
forceStringify,
|
|
180
233
|
bridge,
|
|
234
|
+
exportESM: esm,
|
|
181
235
|
useClassComponent
|
|
182
236
|
});
|
|
183
237
|
return {
|
|
@@ -189,7 +243,6 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
189
243
|
async transform(code, id) {
|
|
190
244
|
const { filename, query } = parseVueRequest(id);
|
|
191
245
|
debug("transform", id, JSON.stringify(query), filename);
|
|
192
|
-
debug("transform (code)", code);
|
|
193
246
|
let langInfo = defaultSFCLang;
|
|
194
247
|
let inSourceMap;
|
|
195
248
|
if (!query.vue) {
|
|
@@ -201,6 +254,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
201
254
|
isGlobal: globalSFCScope,
|
|
202
255
|
useClassComponent,
|
|
203
256
|
bridge,
|
|
257
|
+
exportESM: esm,
|
|
204
258
|
forceStringify
|
|
205
259
|
});
|
|
206
260
|
debug("parseOptions", parseOptions);
|
|
@@ -233,6 +287,7 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
233
287
|
isGlobal: globalSFCScope,
|
|
234
288
|
useClassComponent,
|
|
235
289
|
bridge,
|
|
290
|
+
exportESM: esm,
|
|
236
291
|
forceStringify
|
|
237
292
|
});
|
|
238
293
|
debug("parseOptions", parseOptions);
|
|
@@ -251,10 +306,38 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
251
306
|
}
|
|
252
307
|
};
|
|
253
308
|
});
|
|
309
|
+
function normalizeConfigResolveAlias(resolve, framework) {
|
|
310
|
+
if (resolve && resolve.alias) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
if (!resolve) {
|
|
314
|
+
if (framework === "vite") {
|
|
315
|
+
resolve = { alias: [] };
|
|
316
|
+
} else if (framework === "webpack") {
|
|
317
|
+
resolve = { alias: {} };
|
|
318
|
+
}
|
|
319
|
+
} else if (!resolve.alias) {
|
|
320
|
+
if (framework === "vite") {
|
|
321
|
+
resolve.alias = [];
|
|
322
|
+
} else if (framework === "webpack") {
|
|
323
|
+
resolve.alias = {};
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
async function loadWebpack() {
|
|
328
|
+
let webpack = null;
|
|
329
|
+
try {
|
|
330
|
+
webpack = await import('webpack').then((m) => m.default || m);
|
|
331
|
+
} catch (e) {
|
|
332
|
+
console.warn(`[@intlify/unplugin-vue-i18n] webpack not found, please install webpack.`);
|
|
333
|
+
}
|
|
334
|
+
return webpack;
|
|
335
|
+
}
|
|
254
336
|
async function generateBundleResources(resources, query, isProduction, {
|
|
255
337
|
forceStringify = false,
|
|
256
338
|
isGlobal = false,
|
|
257
339
|
bridge = false,
|
|
340
|
+
exportESM = true,
|
|
258
341
|
useClassComponent = false
|
|
259
342
|
}) {
|
|
260
343
|
const codes = [];
|
|
@@ -268,6 +351,7 @@ async function generateBundleResources(resources, query, isProduction, {
|
|
|
268
351
|
isGlobal,
|
|
269
352
|
useClassComponent,
|
|
270
353
|
bridge,
|
|
354
|
+
exportESM,
|
|
271
355
|
forceStringify
|
|
272
356
|
});
|
|
273
357
|
parseOptions.type = "bare";
|
|
@@ -316,6 +400,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
316
400
|
forceStringify = false,
|
|
317
401
|
isGlobal = false,
|
|
318
402
|
bridge = false,
|
|
403
|
+
exportESM = true,
|
|
319
404
|
useClassComponent = false
|
|
320
405
|
}) {
|
|
321
406
|
const mode = isProduction ? "production" : "development";
|
|
@@ -326,6 +411,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
326
411
|
forceStringify,
|
|
327
412
|
useClassComponent,
|
|
328
413
|
bridge,
|
|
414
|
+
exportESM,
|
|
329
415
|
env: mode,
|
|
330
416
|
onWarn: (msg) => {
|
|
331
417
|
warn(`${filename} ${msg}`);
|
package/lib/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { createUnplugin } from 'unplugin';
|
|
|
2
2
|
import { normalize, parse } from 'pathe';
|
|
3
3
|
import createDebug from 'debug';
|
|
4
4
|
import fg from 'fast-glob';
|
|
5
|
-
import { isString, isArray, isEmptyObject, isNumber, assign } from '@intlify/shared';
|
|
5
|
+
import { isString, isArray, isBoolean, isObject, isEmptyObject, isNumber, assign } from '@intlify/shared';
|
|
6
6
|
import { createFilter } from '@rollup/pluginutils';
|
|
7
7
|
import { generateJSON, generateYAML } from '@intlify/bundle-utils';
|
|
8
8
|
import { parse as parse$1 } from '@vue/compiler-sfc';
|
|
@@ -105,12 +105,48 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
105
105
|
const useClassComponent = !!options.useClassComponent;
|
|
106
106
|
const bridge = !!options.bridge;
|
|
107
107
|
debug("bridge", bridge);
|
|
108
|
+
const runtimeOnly = isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
109
|
+
debug("runtimeOnly", runtimeOnly);
|
|
110
|
+
const compositionOnly = isBoolean(options.compositionOnly) ? options.compositionOnly : true;
|
|
111
|
+
debug("compositionOnly", compositionOnly);
|
|
112
|
+
const fullInstall = isBoolean(options.fullInstall) ? options.fullInstall : true;
|
|
113
|
+
debug("fullInstall", fullInstall);
|
|
114
|
+
const esm = isBoolean(options.esm) ? options.esm : true;
|
|
115
|
+
debug("esm", esm);
|
|
108
116
|
let isProduction = false;
|
|
109
117
|
let sourceMap = false;
|
|
110
118
|
return {
|
|
111
119
|
name: "unplugin-vue-i18n",
|
|
112
120
|
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
|
+
},
|
|
113
130
|
vite: {
|
|
131
|
+
config(config, { command }) {
|
|
132
|
+
normalizeConfigResolveAlias(config.resolve, meta.framework);
|
|
133
|
+
if (command === "build" && runtimeOnly) {
|
|
134
|
+
if (isArray(config.resolve.alias)) {
|
|
135
|
+
config.resolve.alias.push({
|
|
136
|
+
find: "vue-i18n",
|
|
137
|
+
replacement: `vue-i18n/dist/vue-i18n.runtime.esm-bundler.js`
|
|
138
|
+
});
|
|
139
|
+
} else if (isObject(config.resolve.alias)) {
|
|
140
|
+
config.resolve.alias["vue-i18n"] = `vue-i18n/dist/vue-i18n.runtime.esm-bundler.js`;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
config.define = config.define || {};
|
|
144
|
+
config.define["__VUE_I18N_LEGACY_API__"] = !compositionOnly;
|
|
145
|
+
debug(`set __VUE_I18N_LEGACY_API__ is '${config.define["__VUE_I18N_LEGACY_API__"]}'`);
|
|
146
|
+
config.define["__VUE_I18N_FULL_INSTALL__"] = fullInstall;
|
|
147
|
+
debug(`set __VUE_I18N_FULL_INSTALL__ is '${config.define["__VUE_I18N_FULL_INSTALL__"]}'`);
|
|
148
|
+
config.define["__VUE_I18N_PROD_DEVTOOLS__"] = false;
|
|
149
|
+
},
|
|
114
150
|
configResolved(config) {
|
|
115
151
|
isProduction = config.isProduction;
|
|
116
152
|
sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
|
|
@@ -136,6 +172,23 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
136
172
|
isProduction = compiler.options.mode !== "development";
|
|
137
173
|
sourceMap = !!compiler.options.devtool;
|
|
138
174
|
debug(`webpack: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
|
|
175
|
+
if (isProduction && runtimeOnly) {
|
|
176
|
+
normalizeConfigResolveAlias(compiler.options.resolve, meta.framework);
|
|
177
|
+
compiler.options.resolve.alias["vue-i18n"] = `vue-i18n/dist/vue-i18n.runtime.esm-bundler.js`;
|
|
178
|
+
}
|
|
179
|
+
loadWebpack().then((webpack) => {
|
|
180
|
+
if (webpack) {
|
|
181
|
+
compiler.options.plugins.push(new webpack.DefinePlugin({
|
|
182
|
+
__VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
|
|
183
|
+
__VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
|
|
184
|
+
__INTLIFY_PROD_DEVTOOLS__: "false"
|
|
185
|
+
}));
|
|
186
|
+
debug(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
|
|
187
|
+
debug(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
|
|
188
|
+
} else {
|
|
189
|
+
debug("ignore vue-i18n feature flags with webpack.DefinePlugin");
|
|
190
|
+
}
|
|
191
|
+
});
|
|
139
192
|
if (compiler.options.module) {
|
|
140
193
|
compiler.options.module.rules.push({
|
|
141
194
|
test: /\.(json5?|ya?ml)$/,
|
|
@@ -167,6 +220,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
167
220
|
const code = await generateBundleResources(resourcePaths, query, isProduction, {
|
|
168
221
|
forceStringify,
|
|
169
222
|
bridge,
|
|
223
|
+
exportESM: esm,
|
|
170
224
|
useClassComponent
|
|
171
225
|
});
|
|
172
226
|
return {
|
|
@@ -178,7 +232,6 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
178
232
|
async transform(code, id) {
|
|
179
233
|
const { filename, query } = parseVueRequest(id);
|
|
180
234
|
debug("transform", id, JSON.stringify(query), filename);
|
|
181
|
-
debug("transform (code)", code);
|
|
182
235
|
let langInfo = defaultSFCLang;
|
|
183
236
|
let inSourceMap;
|
|
184
237
|
if (!query.vue) {
|
|
@@ -190,6 +243,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
190
243
|
isGlobal: globalSFCScope,
|
|
191
244
|
useClassComponent,
|
|
192
245
|
bridge,
|
|
246
|
+
exportESM: esm,
|
|
193
247
|
forceStringify
|
|
194
248
|
});
|
|
195
249
|
debug("parseOptions", parseOptions);
|
|
@@ -222,6 +276,7 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
222
276
|
isGlobal: globalSFCScope,
|
|
223
277
|
useClassComponent,
|
|
224
278
|
bridge,
|
|
279
|
+
exportESM: esm,
|
|
225
280
|
forceStringify
|
|
226
281
|
});
|
|
227
282
|
debug("parseOptions", parseOptions);
|
|
@@ -240,10 +295,38 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
240
295
|
}
|
|
241
296
|
};
|
|
242
297
|
});
|
|
298
|
+
function normalizeConfigResolveAlias(resolve, framework) {
|
|
299
|
+
if (resolve && resolve.alias) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if (!resolve) {
|
|
303
|
+
if (framework === "vite") {
|
|
304
|
+
resolve = { alias: [] };
|
|
305
|
+
} else if (framework === "webpack") {
|
|
306
|
+
resolve = { alias: {} };
|
|
307
|
+
}
|
|
308
|
+
} else if (!resolve.alias) {
|
|
309
|
+
if (framework === "vite") {
|
|
310
|
+
resolve.alias = [];
|
|
311
|
+
} else if (framework === "webpack") {
|
|
312
|
+
resolve.alias = {};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
async function loadWebpack() {
|
|
317
|
+
let webpack = null;
|
|
318
|
+
try {
|
|
319
|
+
webpack = await import('webpack').then((m) => m.default || m);
|
|
320
|
+
} catch (e) {
|
|
321
|
+
console.warn(`[@intlify/unplugin-vue-i18n] webpack not found, please install webpack.`);
|
|
322
|
+
}
|
|
323
|
+
return webpack;
|
|
324
|
+
}
|
|
243
325
|
async function generateBundleResources(resources, query, isProduction, {
|
|
244
326
|
forceStringify = false,
|
|
245
327
|
isGlobal = false,
|
|
246
328
|
bridge = false,
|
|
329
|
+
exportESM = true,
|
|
247
330
|
useClassComponent = false
|
|
248
331
|
}) {
|
|
249
332
|
const codes = [];
|
|
@@ -257,6 +340,7 @@ async function generateBundleResources(resources, query, isProduction, {
|
|
|
257
340
|
isGlobal,
|
|
258
341
|
useClassComponent,
|
|
259
342
|
bridge,
|
|
343
|
+
exportESM,
|
|
260
344
|
forceStringify
|
|
261
345
|
});
|
|
262
346
|
parseOptions.type = "bare";
|
|
@@ -305,6 +389,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
305
389
|
forceStringify = false,
|
|
306
390
|
isGlobal = false,
|
|
307
391
|
bridge = false,
|
|
392
|
+
exportESM = true,
|
|
308
393
|
useClassComponent = false
|
|
309
394
|
}) {
|
|
310
395
|
const mode = isProduction ? "production" : "development";
|
|
@@ -315,6 +400,7 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
315
400
|
forceStringify,
|
|
316
401
|
useClassComponent,
|
|
317
402
|
bridge,
|
|
403
|
+
exportESM,
|
|
318
404
|
env: mode,
|
|
319
405
|
onWarn: (msg) => {
|
|
320
406
|
warn(`${filename} ${msg}`);
|
package/lib/types.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
declare type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
|
|
2
2
|
interface PluginOptions {
|
|
3
3
|
include?: string | string[];
|
|
4
|
+
runtimeOnly?: boolean;
|
|
5
|
+
compositionOnly?: boolean;
|
|
6
|
+
fullInstall?: boolean;
|
|
7
|
+
esm?: boolean;
|
|
4
8
|
forceStringify?: boolean;
|
|
5
9
|
defaultSFCLang?: SFCLangFormat;
|
|
6
10
|
globalSFCScope?: boolean;
|
package/package.json
CHANGED
package/CHANGELOG.md
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
## @intlify/unplugin-vue-i18n@0.2.0 (2022-05-06)
|
|
3
|
-
|
|
4
|
-
#### :star: Features
|
|
5
|
-
* [#117](https://github.com/intlify/bundle-tools/pull/117) feat: support virtual resource importing ([@kazupon](https://github.com/kazupon))
|
|
6
|
-
|
|
7
|
-
#### Committers: 1
|
|
8
|
-
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## @intlify/unplugin-vue-i18n@0.1.2 (2022-05-06)
|
|
12
|
-
|
|
13
|
-
#### :bug: Bug Fixes
|
|
14
|
-
* [#115](https://github.com/intlify/bundle-tools/pull/115) fix(unplugin-vue-i18n): export d.ts files ([@kazupon](https://github.com/kazupon))
|
|
15
|
-
|
|
16
|
-
#### Committers: 1
|
|
17
|
-
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
## @intlify/unplugin-vue-i18n@0.1.1 (2022-05-06)
|
|
21
|
-
|
|
22
|
-
#### :bug: Bug Fixes
|
|
23
|
-
* [#114](https://github.com/intlify/bundle-tools/pull/114) fix(unplugin-vue-i18n): export types ([@kazupon](https://github.com/kazupon))
|
|
24
|
-
|
|
25
|
-
#### Committers: 1
|
|
26
|
-
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
## @intlify/unplugin-vue-i18n@0.1.0 (2022-05-06)
|
|
30
|
-
|
|
31
|
-
#### :star: Features
|
|
32
|
-
* [#113](https://github.com/intlify/bundle-tools/pull/113) feat: unplugin basic implementation for vue-i18n ([@kazupon](https://github.com/kazupon))
|
|
33
|
-
|
|
34
|
-
#### Committers: 1
|
|
35
|
-
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
36
|
-
|
|
37
|
-
## @intlify/unplugin-vue-i18n@0.0.0 (2022-05-02)
|
|
38
|
-
|
|
39
|
-
:tada: Initial release.
|