This repository was archived by the owner on Sep 17, 2022. It is now read-only.
File tree 1 file changed +10
-4
lines changed
1 file changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,7 @@ function getInsertInfo(source: string): InsertInfo {
35
35
vue = 2
36
36
}
37
37
else {
38
- insertPos = source . indexOf ( 'script.render = render ' )
38
+ insertPos = source . indexOf ( 'script.__file ' )
39
39
vue = 3
40
40
}
41
41
@@ -56,11 +56,17 @@ export default function fluentPlugin({ blockType = 'fluent', external }: PluginO
56
56
} ,
57
57
async load ( id ) {
58
58
if ( id . endsWith ( '.ftl' ) ) {
59
- const ftl = await fs . readFile ( id , 'utf8' )
60
- return `
59
+ try {
60
+ const ftl = await fs . readFile ( id , 'utf8' )
61
+ return `
61
62
import { FluentResource } from '@fluent/bundle'
62
63
export default new FluentResource(${ JSON . stringify ( ftl ) } )
63
64
`
65
+ }
66
+ catch ( e ) {
67
+ this . warn ( `Missing ftl file: ${ id } ` )
68
+ return 'export default null'
69
+ }
64
70
}
65
71
} ,
66
72
async transform ( code , id ) {
@@ -79,7 +85,7 @@ export default new FluentResource(${JSON.stringify(ftl)})
79
85
magic . prepend ( 'import { FluentResource } from \'@fluent/bundle\';\n' )
80
86
81
87
const { insertPos, target } = getInsertInfo ( code )
82
- magic . appendLeft ( insertPos - 1 , `${ target } .fluent = { ${ external . locales . map ( locale => `${ locale } : ${ locale } _ftl` ) . join ( ', ' ) } }` )
88
+ magic . appendLeft ( insertPos , `${ target } .fluent = { ${ external . locales . map ( locale => `${ locale } : ${ locale } _ftl` ) . join ( ', ' ) } };\n ` )
83
89
84
90
return {
85
91
code : magic . toString ( ) ,
You can’t perform that action at this time.
0 commit comments