|
7 | 7 | assign,
|
8 | 8 | generateCodeFrame,
|
9 | 9 | isEmptyObject,
|
10 |
| - isNumber, |
11 | 10 | isString
|
12 | 11 | } from '@intlify/shared'
|
13 | 12 | import { createFilter } from '@rollup/pluginutils'
|
@@ -61,6 +60,15 @@ export function resourcePlugin(
|
61 | 60 | return vuePlugin ? getVueCompiler(vuePlugin).parse : parse
|
62 | 61 | }
|
63 | 62 |
|
| 63 | + const resourcePaths = new Set<string>() |
| 64 | + if (opts.include) { |
| 65 | + for (const inc of opts.include) { |
| 66 | + for (const resourcePath of fg.sync(inc)) { |
| 67 | + resourcePaths.add(resourcePath) |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
64 | 72 | return {
|
65 | 73 | name: resolveNamespace('resource'),
|
66 | 74 |
|
@@ -221,27 +229,26 @@ export function resourcePlugin(
|
221 | 229 | return INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework)
|
222 | 230 | },
|
223 | 231 |
|
224 |
| - async load(id: string) { |
| 232 | + load(id: string) { |
225 | 233 | debug('load', id)
|
226 | 234 | if (
|
227 | 235 | INTLIFY_BUNDLE_IMPORT_ID === getVirtualId(id, meta.framework) &&
|
228 |
| - opts.include |
| 236 | + resourcePaths.size > 0 |
229 | 237 | ) {
|
230 |
| - const resourcePaths = new Set<string>() |
231 |
| - for (const inc of opts.include) { |
232 |
| - for (const resourcePath of await fg(inc)) { |
233 |
| - resourcePaths.add(resourcePath) |
234 |
| - } |
235 |
| - } |
236 |
| - |
237 | 238 | const code = generateBundleResources(resourcePaths, prod, opts)
|
238 | 239 |
|
239 | 240 | // TODO: support virtual import identifier
|
240 | 241 | // for virtual import identifier (@intlify/unplugin-vue-i18n/messages)
|
241 |
| - return { |
242 |
| - code, |
243 |
| - map: { mappings: '' } |
| 242 | + if (meta.framework === 'vite') { |
| 243 | + return { code, map: { mappings: '' } } |
| 244 | + } |
| 245 | + |
| 246 | + // watch resources to invalidate on change (webpack) |
| 247 | + for (const p of resourcePaths) { |
| 248 | + this.addWatchFile(p) |
244 | 249 | }
|
| 250 | + |
| 251 | + return { code } |
245 | 252 | }
|
246 | 253 | },
|
247 | 254 |
|
@@ -285,11 +292,10 @@ export function resourcePlugin(
|
285 | 292 |
|
286 | 293 | if (code === generatedCode) return
|
287 | 294 |
|
288 |
| - return { |
289 |
| - code: generatedCode, |
290 |
| - // prettier-ignore |
291 |
| - map: { mappings: '' } |
| 295 | + if (meta.framework === 'vite') { |
| 296 | + return { code: generatedCode, map: { mappings: '' } } |
292 | 297 | }
|
| 298 | + return { code: generatedCode } |
293 | 299 | } else {
|
294 | 300 | // TODO: support virtual import identifier
|
295 | 301 | // for virtual import identifier (@intlify/unplugin-vue-i18n/messages)
|
@@ -347,11 +353,10 @@ export function resourcePlugin(
|
347 | 353 |
|
348 | 354 | if (code === generatedCode) return
|
349 | 355 |
|
350 |
| - return { |
351 |
| - code: generatedCode, |
352 |
| - // prettier-ignore |
353 |
| - map: { mappings: '' } |
| 356 | + if (meta.framework === 'vite') { |
| 357 | + return { code: generatedCode, map: { mappings: '' } } |
354 | 358 | }
|
| 359 | + return { code: generatedCode } |
355 | 360 | }
|
356 | 361 | }
|
357 | 362 | }
|
@@ -518,7 +523,7 @@ function getCode(
|
518 | 523 | parser: ReturnType<typeof getVueCompiler>['parse'],
|
519 | 524 | framework: UnpluginContextMeta['framework'] = 'vite'
|
520 | 525 | ): string {
|
521 |
| - if (!isNumber(index)) { |
| 526 | + if (index == null) { |
522 | 527 | raiseError(`unexpected index: ${index}`)
|
523 | 528 | }
|
524 | 529 |
|
@@ -566,30 +571,28 @@ function getOptions(
|
566 | 571 | filename,
|
567 | 572 | jit: true,
|
568 | 573 | env: mode,
|
569 |
| - onWarn: msg => { |
570 |
| - warn(`${filename} ${msg}`) |
571 |
| - }, |
| 574 | + onWarn: msg => warn(`${filename} ${msg}`), |
572 | 575 | onError: (msg, extra) => {
|
573 | 576 | const codeFrame = generateCodeFrame(
|
574 | 577 | extra?.source || extra?.location?.source || '',
|
575 | 578 | extra?.location?.start.column,
|
576 | 579 | extra?.location?.end.column
|
577 | 580 | )
|
578 |
| - const errMssage = `${msg} (error code: ${extra?.code}) in ${filename} |
| 581 | + const errMessage = `${msg} (error code: ${extra?.code}) in ${filename} |
579 | 582 | target message: ${extra?.source}
|
580 | 583 | target message path: ${extra?.path}
|
581 | 584 |
|
582 | 585 | ${codeFrame}
|
583 | 586 | `
|
584 |
| - error(errMssage) |
585 |
| - throw new Error(errMssage) |
| 587 | + error(errMessage) |
| 588 | + throw new Error(errMessage) |
586 | 589 | }
|
587 | 590 | }
|
588 | 591 |
|
589 | 592 | if (isCustomBlock(query)) {
|
590 | 593 | return assign(baseOptions, {
|
591 | 594 | type: 'sfc' as const,
|
592 |
| - locale: isString(query.locale) ? query.locale : '', |
| 595 | + locale: query.locale ?? '', |
593 | 596 | isGlobal: opts.globalSFCScope || !!query.global
|
594 | 597 | })
|
595 | 598 | }
|
|
0 commit comments