sourceTextModule.createCachedData()


在评估模块之前,可以多次调用此方法。

// 创建初始模块
const module = new vm.SourceTextModule('const a = 1;');

// 从这个模块创建缓存数据
const cachedData = module.createCachedData();

// 使用缓存数据创建新的模块。代码必须相同。
const module2 = new vm.SourceTextModule('const a = 1;', { cachedData });

Creates a code cache that can be used with the SourceTextModule constructor's cachedData option. Returns a Buffer. This method may be called any number of times before the module has been evaluated.

// Create an initial module
const module = new vm.SourceTextModule('const a = 1;');

// Create cached data from this module
const cachedData = module.createCachedData();

// Create a new module using the cached data. The code must be the same.
const module2 = new vm.SourceTextModule('const a = 1;', { cachedData });