@intlify/unplugin-vue-i18n 11.0.0-beta.3 → 11.0.0-beta.4

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 CHANGED
@@ -10,6 +10,7 @@ const pluginutils = require('@rollup/pluginutils');
10
10
  const fg = require('fast-glob');
11
11
  const node_fs = require('node:fs');
12
12
  const path = require('node:path');
13
+ const pathe = require('pathe');
13
14
  const compilerSfc = require('vue/compiler-sfc');
14
15
  const pc = require('picocolors');
15
16
  const eslintUitls = require('@eslint-community/eslint-utils');
@@ -194,17 +195,64 @@ function resourcePlugin({
194
195
  escapeHtml,
195
196
  transformI18nBlock
196
197
  }, meta) {
197
- function resolveInclude() {
198
+ let viteModule = null;
199
+ async function getViteModule() {
200
+ if (viteModule != null) {
201
+ return viteModule;
202
+ }
203
+ try {
204
+ viteModule = await import('vite');
205
+ } catch (e) {
206
+ error(`vite not found, please install vite.`, e.message);
207
+ throw e;
208
+ }
209
+ return viteModule;
210
+ }
211
+ function resolveIncludeExclude() {
198
212
  const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
199
213
  if (shared.isArray(include)) {
200
- return [...include, customBlockInclude];
214
+ return [[...include, customBlockInclude], exclude];
201
215
  } else if (shared.isString(include)) {
202
- return [include, customBlockInclude];
216
+ return [[include, customBlockInclude], exclude];
203
217
  } else {
204
- return [RE_RESOURCE_FORMAT, customBlockInclude];
218
+ return [[RE_RESOURCE_FORMAT, customBlockInclude], exclude];
205
219
  }
206
220
  }
207
- const filter = pluginutils.createFilter(resolveInclude(), exclude);
221
+ function resolveIncludeExcludeForLegacy() {
222
+ const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
223
+ let _include = void 0;
224
+ let _exclude = void 0;
225
+ if (include) {
226
+ if (shared.isArray(include)) {
227
+ _include = [...include.map((item) => pathe.normalize(item)), customBlockInclude];
228
+ } else if (shared.isString(include)) {
229
+ _include = [pathe.normalize(include), customBlockInclude];
230
+ }
231
+ } else {
232
+ _exclude = "**/**";
233
+ }
234
+ return [_include, _exclude];
235
+ }
236
+ let _filter = null;
237
+ async function getFilter() {
238
+ if (_filter != null) {
239
+ return _filter;
240
+ }
241
+ if (meta.framework == "webpack") {
242
+ debug$2("Using filter for webpack");
243
+ _filter = pluginutils.createFilter(...resolveIncludeExclude());
244
+ } else {
245
+ const viteModule2 = await getViteModule();
246
+ if (viteModule2.rolldownVersion) {
247
+ debug$2("Using filter for rolldown-vite");
248
+ _filter = pluginutils.createFilter(...resolveIncludeExclude());
249
+ } else {
250
+ debug$2("Using filter for rollup-vite");
251
+ _filter = pluginutils.createFilter(...resolveIncludeExcludeForLegacy());
252
+ }
253
+ }
254
+ return _filter;
255
+ }
208
256
  const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
209
257
  return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
210
258
  };
@@ -224,7 +272,7 @@ function resourcePlugin({
224
272
  * For vite, If we have json (including SFC's custom block),
225
273
  * transform it first because it will be transformed into javascript code by `vite:json` plugin.
226
274
  *
227
- * For webpack, This plugin will handle with ‘post’, because vue-loader generate the request query.
275
+ * For webpack, This plugin will handle with 'post', because vue-loader generate the request query.
228
276
  */
229
277
  enforce: meta.framework === "vite" ? "pre" : "post",
230
278
  vite: {
@@ -251,7 +299,7 @@ function resourcePlugin({
251
299
  debug$2("alias Config:", aliasConfig);
252
300
  return shared.assign(defineConfig, aliasConfig);
253
301
  },
254
- configResolved(config) {
302
+ async configResolved(config) {
255
303
  vuePlugin = getVitePlugin(config, "vite:vue");
256
304
  if (!checkVuePlugin(vuePlugin)) {
257
305
  return;
@@ -259,6 +307,30 @@ function resourcePlugin({
259
307
  isProduction = config.isProduction;
260
308
  sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
261
309
  debug$2(`configResolved: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
310
+ const isRolldownVite = !!(await getViteModule()).rolldownVersion;
311
+ debug$2(`Using ${isRolldownVite ? "rolldown-vite" : "vite"} for the build`);
312
+ if (!isRolldownVite) {
313
+ const jsonPlugin = getVitePlugin(config, "vite:json");
314
+ if (jsonPlugin) {
315
+ const orgTransform = "handler" in jsonPlugin.transform ? jsonPlugin.transform.handler : jsonPlugin.transform;
316
+ async function overrideJson(code, id) {
317
+ const filter = await getFilter();
318
+ if (!/\.json$/.test(id) || filter(id)) {
319
+ return;
320
+ }
321
+ const { query } = parseVueRequest(id);
322
+ if (query.vue) {
323
+ return;
324
+ }
325
+ debug$2("org json plugin");
326
+ return orgTransform.apply(this, [code, id]);
327
+ }
328
+ jsonPlugin.transform = overrideJson;
329
+ if ("handler" in jsonPlugin.transform) {
330
+ jsonPlugin.transform.handler = overrideJson;
331
+ }
332
+ }
333
+ }
262
334
  },
263
335
  async handleHotUpdate({ file, server }) {
264
336
  if (RE_RESOURCE_FORMAT.test(file)) {
@@ -290,26 +362,22 @@ function resourcePlugin({
290
362
  runtimeOnly
291
363
  })}`
292
364
  );
293
- loadWebpack().then((webpack) => {
294
- if (webpack) {
295
- compiler.options.plugins.push(
296
- new webpack.DefinePlugin({
297
- __VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
298
- __VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
299
- __INTLIFY_PROD_DEVTOOLS__: "false"
300
- })
301
- );
302
- debug$2(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
303
- debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
304
- } else {
305
- debug$2("ignore vue-i18n feature flags with webpack.DefinePlugin");
306
- }
307
- });
365
+ compiler.options.plugins.push(
366
+ new compiler.webpack.DefinePlugin({
367
+ __VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
368
+ __VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
369
+ __INTLIFY_PROD_DEVTOOLS__: "false"
370
+ })
371
+ );
372
+ debug$2(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
373
+ debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
374
+ const filter = pluginutils.createFilter(...resolveIncludeExclude());
308
375
  if (compiler.options.module) {
309
376
  compiler.options.module.rules.push({
310
377
  test: RE_RESOURCE_FORMAT,
311
378
  type: "javascript/auto",
312
379
  include(resource) {
380
+ debug$2("webpack resource include", resource);
313
381
  return filter(resource);
314
382
  }
315
383
  });
@@ -350,13 +418,11 @@ function resourcePlugin({
350
418
  }
351
419
  },
352
420
  transform: {
353
- filter: {
354
- id: {
355
- include: resolveInclude(),
356
- exclude
357
- }
358
- },
359
421
  async handler(code, id) {
422
+ const filter = await getFilter();
423
+ if (!filter(id)) {
424
+ return;
425
+ }
360
426
  const { filename, query } = parseVueRequest(id);
361
427
  debug$2("transform", id, JSON.stringify(query), filename);
362
428
  let langInfo = defaultSFCLang;
@@ -483,15 +549,6 @@ function normalizeConfigResolveAlias(resolve, framework) {
483
549
  }
484
550
  }
485
551
  }
486
- async function loadWebpack() {
487
- let webpack = null;
488
- try {
489
- webpack = await import('webpack').then((m) => m.default || m);
490
- } catch (_e) {
491
- warn(`webpack not found, please install webpack.`);
492
- }
493
- return webpack;
494
- }
495
552
  async function generateBundleResources(resources, isProduction, {
496
553
  forceStringify = false,
497
554
  isGlobal = false,
package/lib/index.mjs CHANGED
@@ -6,6 +6,7 @@ import { createFilter } from '@rollup/pluginutils';
6
6
  import fg from 'fast-glob';
7
7
  import { promises } from 'node:fs';
8
8
  import path, { parse } from 'node:path';
9
+ import { normalize } from 'pathe';
9
10
  import { parse as parse$1 } from 'vue/compiler-sfc';
10
11
  import pc from 'picocolors';
11
12
  import eslintUitls from '@eslint-community/eslint-utils';
@@ -182,17 +183,64 @@ function resourcePlugin({
182
183
  escapeHtml,
183
184
  transformI18nBlock
184
185
  }, meta) {
185
- function resolveInclude() {
186
+ let viteModule = null;
187
+ async function getViteModule() {
188
+ if (viteModule != null) {
189
+ return viteModule;
190
+ }
191
+ try {
192
+ viteModule = await import('vite');
193
+ } catch (e) {
194
+ error(`vite not found, please install vite.`, e.message);
195
+ throw e;
196
+ }
197
+ return viteModule;
198
+ }
199
+ function resolveIncludeExclude() {
186
200
  const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
187
201
  if (isArray(include)) {
188
- return [...include, customBlockInclude];
202
+ return [[...include, customBlockInclude], exclude];
189
203
  } else if (isString(include)) {
190
- return [include, customBlockInclude];
204
+ return [[include, customBlockInclude], exclude];
191
205
  } else {
192
- return [RE_RESOURCE_FORMAT, customBlockInclude];
206
+ return [[RE_RESOURCE_FORMAT, customBlockInclude], exclude];
193
207
  }
194
208
  }
195
- const filter = createFilter(resolveInclude(), exclude);
209
+ function resolveIncludeExcludeForLegacy() {
210
+ const customBlockInclude = meta.framework === "vite" ? RE_SFC_I18N_CUSTOM_BLOCK : RE_SFC_I18N_WEBPACK_CUSTOM_BLOCK;
211
+ let _include = void 0;
212
+ let _exclude = void 0;
213
+ if (include) {
214
+ if (isArray(include)) {
215
+ _include = [...include.map((item) => normalize(item)), customBlockInclude];
216
+ } else if (isString(include)) {
217
+ _include = [normalize(include), customBlockInclude];
218
+ }
219
+ } else {
220
+ _exclude = "**/**";
221
+ }
222
+ return [_include, _exclude];
223
+ }
224
+ let _filter = null;
225
+ async function getFilter() {
226
+ if (_filter != null) {
227
+ return _filter;
228
+ }
229
+ if (meta.framework == "webpack") {
230
+ debug$2("Using filter for webpack");
231
+ _filter = createFilter(...resolveIncludeExclude());
232
+ } else {
233
+ const viteModule2 = await getViteModule();
234
+ if (viteModule2.rolldownVersion) {
235
+ debug$2("Using filter for rolldown-vite");
236
+ _filter = createFilter(...resolveIncludeExclude());
237
+ } else {
238
+ debug$2("Using filter for rollup-vite");
239
+ _filter = createFilter(...resolveIncludeExcludeForLegacy());
240
+ }
241
+ }
242
+ return _filter;
243
+ }
196
244
  const getVueI18nAliasPath = ({ ssr = false, runtimeOnly: runtimeOnly2 = false }) => {
197
245
  return `${module}/dist/${module}${runtimeOnly2 ? ".runtime" : ""}.${!ssr ? "esm-bundler.js" : "node.mjs"}`;
198
246
  };
@@ -212,7 +260,7 @@ function resourcePlugin({
212
260
  * For vite, If we have json (including SFC's custom block),
213
261
  * transform it first because it will be transformed into javascript code by `vite:json` plugin.
214
262
  *
215
- * For webpack, This plugin will handle with ‘post’, because vue-loader generate the request query.
263
+ * For webpack, This plugin will handle with 'post', because vue-loader generate the request query.
216
264
  */
217
265
  enforce: meta.framework === "vite" ? "pre" : "post",
218
266
  vite: {
@@ -239,7 +287,7 @@ function resourcePlugin({
239
287
  debug$2("alias Config:", aliasConfig);
240
288
  return assign(defineConfig, aliasConfig);
241
289
  },
242
- configResolved(config) {
290
+ async configResolved(config) {
243
291
  vuePlugin = getVitePlugin(config, "vite:vue");
244
292
  if (!checkVuePlugin(vuePlugin)) {
245
293
  return;
@@ -247,6 +295,30 @@ function resourcePlugin({
247
295
  isProduction = config.isProduction;
248
296
  sourceMap = config.command === "build" ? !!config.build.sourcemap : false;
249
297
  debug$2(`configResolved: isProduction = ${isProduction}, sourceMap = ${sourceMap}`);
298
+ const isRolldownVite = !!(await getViteModule()).rolldownVersion;
299
+ debug$2(`Using ${isRolldownVite ? "rolldown-vite" : "vite"} for the build`);
300
+ if (!isRolldownVite) {
301
+ const jsonPlugin = getVitePlugin(config, "vite:json");
302
+ if (jsonPlugin) {
303
+ const orgTransform = "handler" in jsonPlugin.transform ? jsonPlugin.transform.handler : jsonPlugin.transform;
304
+ async function overrideJson(code, id) {
305
+ const filter = await getFilter();
306
+ if (!/\.json$/.test(id) || filter(id)) {
307
+ return;
308
+ }
309
+ const { query } = parseVueRequest(id);
310
+ if (query.vue) {
311
+ return;
312
+ }
313
+ debug$2("org json plugin");
314
+ return orgTransform.apply(this, [code, id]);
315
+ }
316
+ jsonPlugin.transform = overrideJson;
317
+ if ("handler" in jsonPlugin.transform) {
318
+ jsonPlugin.transform.handler = overrideJson;
319
+ }
320
+ }
321
+ }
250
322
  },
251
323
  async handleHotUpdate({ file, server }) {
252
324
  if (RE_RESOURCE_FORMAT.test(file)) {
@@ -278,26 +350,22 @@ function resourcePlugin({
278
350
  runtimeOnly
279
351
  })}`
280
352
  );
281
- loadWebpack().then((webpack) => {
282
- if (webpack) {
283
- compiler.options.plugins.push(
284
- new webpack.DefinePlugin({
285
- __VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
286
- __VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
287
- __INTLIFY_PROD_DEVTOOLS__: "false"
288
- })
289
- );
290
- debug$2(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
291
- debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
292
- } else {
293
- debug$2("ignore vue-i18n feature flags with webpack.DefinePlugin");
294
- }
295
- });
353
+ compiler.options.plugins.push(
354
+ new compiler.webpack.DefinePlugin({
355
+ __VUE_I18N_LEGACY_API__: JSON.stringify(compositionOnly),
356
+ __VUE_I18N_FULL_INSTALL__: JSON.stringify(fullInstall),
357
+ __INTLIFY_PROD_DEVTOOLS__: "false"
358
+ })
359
+ );
360
+ debug$2(`set __VUE_I18N_LEGACY_API__ is '${compositionOnly}'`);
361
+ debug$2(`set __VUE_I18N_FULL_INSTALL__ is '${fullInstall}'`);
362
+ const filter = createFilter(...resolveIncludeExclude());
296
363
  if (compiler.options.module) {
297
364
  compiler.options.module.rules.push({
298
365
  test: RE_RESOURCE_FORMAT,
299
366
  type: "javascript/auto",
300
367
  include(resource) {
368
+ debug$2("webpack resource include", resource);
301
369
  return filter(resource);
302
370
  }
303
371
  });
@@ -338,13 +406,11 @@ function resourcePlugin({
338
406
  }
339
407
  },
340
408
  transform: {
341
- filter: {
342
- id: {
343
- include: resolveInclude(),
344
- exclude
345
- }
346
- },
347
409
  async handler(code, id) {
410
+ const filter = await getFilter();
411
+ if (!filter(id)) {
412
+ return;
413
+ }
348
414
  const { filename, query } = parseVueRequest(id);
349
415
  debug$2("transform", id, JSON.stringify(query), filename);
350
416
  let langInfo = defaultSFCLang;
@@ -471,15 +537,6 @@ function normalizeConfigResolveAlias(resolve, framework) {
471
537
  }
472
538
  }
473
539
  }
474
- async function loadWebpack() {
475
- let webpack = null;
476
- try {
477
- webpack = await import('webpack').then((m) => m.default || m);
478
- } catch (_e) {
479
- warn(`webpack not found, please install webpack.`);
480
- }
481
- return webpack;
482
- }
483
540
  async function generateBundleResources(resources, isProduction, {
484
541
  forceStringify = false,
485
542
  isGlobal = false,
package/lib/vite.cjs CHANGED
@@ -9,6 +9,7 @@ require('@rollup/pluginutils');
9
9
  require('fast-glob');
10
10
  require('node:fs');
11
11
  require('node:path');
12
+ require('pathe');
12
13
  require('vue/compiler-sfc');
13
14
  require('picocolors');
14
15
  require('@eslint-community/eslint-utils');
package/lib/vite.mjs CHANGED
@@ -7,6 +7,7 @@ import '@rollup/pluginutils';
7
7
  import 'fast-glob';
8
8
  import 'node:fs';
9
9
  import 'node:path';
10
+ import 'pathe';
10
11
  import 'vue/compiler-sfc';
11
12
  import 'picocolors';
12
13
  import '@eslint-community/eslint-utils';
package/lib/webpack.cjs CHANGED
@@ -9,6 +9,7 @@ require('@rollup/pluginutils');
9
9
  require('fast-glob');
10
10
  require('node:fs');
11
11
  require('node:path');
12
+ require('pathe');
12
13
  require('vue/compiler-sfc');
13
14
  require('picocolors');
14
15
  require('@eslint-community/eslint-utils');
package/lib/webpack.mjs CHANGED
@@ -7,6 +7,7 @@ import '@rollup/pluginutils';
7
7
  import 'fast-glob';
8
8
  import 'node:fs';
9
9
  import 'node:path';
10
+ import 'pathe';
10
11
  import 'vue/compiler-sfc';
11
12
  import 'picocolors';
12
13
  import '@eslint-community/eslint-utils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
- "version": "11.0.0-beta.3",
3
+ "version": "11.0.0-beta.4",
4
4
  "description": "unplugin for Vue I18n",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
@@ -30,11 +30,12 @@
30
30
  "@typescript-eslint/scope-manager": "^8.13.0",
31
31
  "@typescript-eslint/typescript-estree": "^8.13.0",
32
32
  "debug": "^4.3.3",
33
+ "pathe": "^2.0.3",
33
34
  "fast-glob": "^3.2.12",
34
35
  "picocolors": "^1.0.0",
35
36
  "unplugin": "^2.3.4",
36
37
  "vue": "^3.5.14",
37
- "@intlify/bundle-utils": "11.0.0-beta.3"
38
+ "@intlify/bundle-utils": "11.0.0-beta.4"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@intlify/core-base": "next",
@@ -49,6 +50,7 @@
49
50
  "ts-loader": "^9.5.2",
50
51
  "unbuild": "^3.5.0",
51
52
  "vite": "^6.3.5",
53
+ "rollup-vite": "npm:vite@^6.3.5",
52
54
  "vue-loader": "^17.4.2",
53
55
  "webpack": "^5.99.8",
54
56
  "webpack-merge": "^5.9.0"