perf: make the most of streamed rendering

This commit is contained in:
Harttle
2021-10-01 18:36:57 +08:00
committed by harttle
parent 4358c9630f
commit aea34418de
13 changed files with 65 additions and 71 deletions
+14 -4
View File
@@ -3,7 +3,7 @@ const { Liquid } = require('liquidjs')
const engine = new Liquid({
root: __dirname,
extname: '.liquid',
globals: {title: 'LiquidJS Demo'}
globals: { title: 'LiquidJS Demo' }
})
engine.registerTag('header', {
@@ -21,6 +21,16 @@ const ctx = {
todos: ['fork and clone', 'make it better', 'make a pull request']
}
engine.renderFile('todolist', ctx)
.then(console.log)
.catch(err => console.error(err.stack))
async function main () {
console.log('==========renderFile===========')
const html = await engine.renderFile('todolist', ctx)
console.log(html)
console.log('===========Streamed===========')
const tpls = await engine.parseFile('todolist')
engine.renderToNodeStream(tpls, ctx)
.on('data', data => process.stdout.write(data))
.on('end', () => console.log(''))
}
main()
+1 -1
View File
@@ -7,6 +7,6 @@
"start": "node index.js"
},
"dependencies": {
"liquidjs": "*"
"liquidjs": "latest"
}
}