Skip to content

Commit 2aa15d1

Browse files
committed
Fix runtime erros with empty ftl file
1 parent 699f625 commit 2aa15d1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rollup-plugin-fluent-vue",
3-
"version": "3.1.0-1",
3+
"version": "3.1.0-2",
44
"description": "Rollup and Vite plugin for custom block support for fluent-vue",
55
"keywords": [
66
"localization",

src/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,20 @@ export default function fluentPlugin({ blockType = 'fluent', external }: PluginO
6666
},
6767
async load(id) {
6868
if (id.endsWith('.ftl')) {
69+
let ftl
6970
try {
70-
const ftl = await fs.readFile(id, 'utf8')
71-
return `
72-
import { FluentResource } from '@fluent/bundle'
73-
export default new FluentResource(${JSON.stringify(ftl)})
74-
`
71+
ftl = await fs.readFile(id, 'utf8')
7572
}
7673
catch (e) {
7774
if (external?.warnMissing === true)
7875
this.warn(`Missing ftl file: ${id}`)
79-
return 'export default null'
76+
ftl = ''
8077
}
78+
79+
return `
80+
import { FluentResource } from '@fluent/bundle'
81+
export default new FluentResource(${JSON.stringify(ftl)})
82+
`
8183
}
8284
},
8385
async transform(code, id) {

0 commit comments

Comments
 (0)