需要预编
修改 require() 这样你就可以装入预编译模块源.
安装
$ npm install --save require-precompiled
使用量
const installPrecompiler = require('require-precompiled');
const cache = require('my-cache-implementation');
installPrecompiler(filename => {
if (cache.hasEntryFor(filename)) {
return cache.getPrecompiledCode(filename);
}
// fall through to underlying extension chain
return null;
});
// any module required from this point on will be checked against the cache
const foo = require('some-module');
API 密码
function installPrecompiler(
loadSource: (filename: string) => string | null,
ext = '.js',
): void
这个 loadSource() 函数应在预编译源可用时返回源字符串。 返回时 null 回到Node.js的默认行为.
默认安装了预编译器 .js 文档。 您可以通过提供第二个参数来指定替代扩展 :
installPrecompiler(filename => {
// ...
}, '.cjs')
许可证
麻省理工学院 詹姆斯·塔玛吉