如何配置jsreport资产
问题描述:
我正在尝试使用jsreport-assets和jsreport-core。但是,我得到一个错误,当我尝试在我的模板充分利用的资产,就像这样:如何配置jsreport资产
<img class="logo" src="{#asset myimage.png @encoding=dataURI}" />
错误:未找到
我感到困惑在哪里存储我的资产文件,以及如何资产myimage.png配置jsreport-core
和/或jsreport-assets
以利用这些资产。
答
默认情况下jsreport资产扩展仅在本地“数据库”中搜索。您需要启用搜索本地文件,请参阅docs。
const jsreport = require('jsreport-core')()
jsreport.use(require('jsreport-assets')({
searchOnDiskIfNotFoundInStore: true,
allowedFiles: '**/*.*'
}))
jsreport.init().then(async() => {
const res = await jsreport.render({
template: {
content: '{#asset foo.txt}',
engine: 'none',
recipe: 'html'
}
})
console.log(res.content.toString())
})