import.meta.resolve(specifier[, parent])
Stability: 1 - 實驗性
此函數僅在啟用--experimental-import-meta-resolve
命令標誌時可用。
specifier
<string> 相對於parent
解析的模塊說明符。parent
<string> | <URL> 要解析的絕對父模塊 URL。如果未指定,則使用import.meta.url
的值作為默認值。- 返回: <Promise>
提供範圍為每個模塊的module-relative 解析函數,返回 URL 字符串。
const dependencyAsset = await import.meta.resolve('component-lib/asset.css');
import.meta.resolve
還接受第二個參數,它是要從中解析的父模塊:
await import.meta.resolve('./dep', import.meta.url);
這個函數是異步的,因為 Node.js 中的 ES 模塊解析器是允許異步的。
相關用法
- Node.js import.meta.url用法及代碼示例
- Node.js init(asyncId, type, triggerAsyncId, resource)用法及代碼示例
- Node.js indexOf()用法及代碼示例
- Node.js inspector.Session.post(method[, params][, callback])用法及代碼示例
- Node.js inspector.console用法及代碼示例
- Node.js ServerHttp2Stream http2stream.pushStream(headers[, options], callback)用法及代碼示例
- Node.js http2.Http2ServerRequest request.url用法及代碼示例
- Node.js request.socket用法及代碼示例
- Node.js assert.notEqual(actual, expected[, message])用法及代碼示例
- Node.js tlsSocket.authorized用法及代碼示例
- Node.js zlib.deflateRaw()用法及代碼示例
- Node.js http.IncomingMessage message.rawHeaders用法及代碼示例
- Node.js Console用法及代碼示例
- Node.js GM transparent()用法及代碼示例
- Node.js URL.protocol用法及代碼示例
- Node.js http.Agent.reuseSocket(socket, request)用法及代碼示例
- Node.js fs.filehandle.datasync()用法及代碼示例
- Node.js socket.bind()用法及代碼示例
- Node.js v8.getHeapSpaceStatistics()用法及代碼示例
- Node.js http2session.destroyed用法及代碼示例
- Node.js http.ServerResponse response.statusCode用法及代碼示例
- Node.js Buffer buf.writeBigUInt64BE(value[, offset])用法及代碼示例
- Node.js Http2ServerResponse.finished用法及代碼示例
- Node.js Http2Stream close用法及代碼示例
- Node.js readStream.isRaw用法及代碼示例
注:本文由純淨天空篩選整理自nodejs.org大神的英文原創作品 import.meta.resolve(specifier[, parent])。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。