[英]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.