在 SEA 中从 VFS 加载模块


🌐 Loading modules from the VFS in a SEA

当启用 useVfs 时,主脚本会从虚拟文件系统内部执行,而 require() 使用 VFS 的 模块加载器 集成 从打包的资源中加载模块。这支持相对引用(例如 require('./helper.js'))以及 node_modules 包查找,这些查找都局限于挂载点:

🌐 When useVfs is enabled, the main script is executed from inside the virtual file system, and require() uses the module loader integration of the VFS to load modules from the bundled assets. This supports relative requires (e.g. require('./helper.js')) as well as node_modules package lookups, which are confined to the mount:

// Require bundled modules using relative paths.
const myModule = require('./lib/mymodule.js');

// Packages bundled under the node_modules asset prefix also resolve.
const dep = require('some-package');