napajs
napajs copied to clipboard
I write a loader for napajs to init zone by node module.
Repo: https://github.com/bramblex/napa-loader
Example: https://github.com/bramblex/napa-loader/blob/master/test/test.js
If there is a test module.
// test module
function fib(n) {
if (n === 0) return 0;
else if (n === 1) return 1;
else return fib(n - 1) + fib(n - 2)
}
module.exports = { fib }
It can load this module with zone
const { zrequire } = require('napa-loader')
const { fib } = await zrequire('./test-module') // it will auto export all functions and wrapped by zone exeucte.
console.log(await fib(10)) // return a promise object.
It can also work with third-party module.
const lodash = await zrequire('lodash')
console.log(await lodash.chunk([1,2,3,4,5,6]))