[英]vscode extension. 'JS Import' from webview
我正在使用 webview 作為單個 Web 應用程序為 vscode 編寫擴展。 我的項目具有以下結構:
在索引 html 中,我想導入一個腳本。
<script type="module">
import * as CommandHandler from '/core/CommandHadnler.js'
//some code
</script>
WebView 設置localResourceRoots
const UI_PATH = path.join(context.extensionPath, 'UI');
this._panel = vscode.window.createWebviewPanel(
'JSONRPCTester',
'JSONRPC Tester',
vscode.ViewColumn.Two,
{
enableScripts: true,
localResourceRoots: [
vscode.Uri.file(UI_PATH)
]
}
);
我看到有人嘗試加載模塊,但我收到錯誤 (Ignore RPC*)。
加載網址:
vscode-webview://a8f78cdc-7d22-4793-810f-67c2d10dfb67/core/ClientProxy.js
可能它不正確的內容安全策略。 我的政策設置:
<meta http-equiv="Content-Security-Policy" content="default-src self; img-src vscode-webview-resource:; script-src vscode-webview-resource: 'self' 'unsafe-inline'; style-src vscode-webview-resource: 'self' 'unsafe-inline'; ">
路徑'/core/CommandHadnler.js'
無效。 您必須在本地機器上指定 JavaScript 文件的完整路徑,並將其轉換為Webview.asWebviewUri
。
見https://code.visualstudio.com/api/extension-guides/webview#loading-local-content
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.