资源
¥Assets
用户可以通过将键路径字典添加到配置中作为 assets
字段来包含资源。在构建时,Node.js 将从指定路径读取资源并将它们打包到准备 blob 中。在生成的可执行文件中,用户可以使用 sea.getAsset()
和 sea.getAssetAsBlob()
API 检索资源。
¥Users can include assets by adding a key-path dictionary to the configuration
as the assets
field. At build time, Node.js would read the assets from the
specified paths and bundle them into the preparation blob. In the generated
executable, users can retrieve the assets using the sea.getAsset()
and
sea.getAssetAsBlob()
APIs.
{
"main": "/path/to/bundled/script.js",
"output": "/path/to/write/the/generated/blob.blob",
"assets": {
"a.jpg": "/path/to/a.jpg",
"b.txt": "/path/to/b.txt"
}
}
单一可执行应用可以按如下方式访问资源:
¥The single-executable application can access the assets as follows:
const { getAsset, getAssetAsBlob, getRawAsset } = require('node:sea');
// Returns a copy of the data in an ArrayBuffer.
const image = getAsset('a.jpg');
// Returns a string decoded from the asset as UTF8.
const text = getAsset('b.txt', 'utf8');
// Returns a Blob containing the asset.
const blob = getAssetAsBlob('a.jpg');
// Returns an ArrayBuffer containing the raw asset without copying.
const raw = getRawAsset('a.jpg');
有关更多信息,请参阅 sea.getAsset()
、sea.getAssetAsBlob()
和 sea.getRawAsset()
API 的文档。
¥See documentation of the sea.getAsset()
, sea.getAssetAsBlob()
and sea.getRawAsset()
APIs for more information.