[英]How to import npm packages in vs code webview extension development?
I want to use npm packages(latextoMathML) but when i use it on my webview it gives me error on running the extension that is: undefined refrence caught: package name(latextoXML) not defined.我想使用 npm 包(latextoMathML)但是当我在我的 webview 上使用它时,它在运行扩展程序时给了我错误:未定义的引用被捕获:ZEFE90A8E604A7C840E88D03AxtoXML7 未定义。 i have tried through let / var / const with require method.
我已经尝试通过 let / var / const 使用 require 方法。 i wants to use in my js code under webview function.
我想在 webview function 下的 js 代码中使用。
You cannot import the npm package into webview in the usual way, for example like this:您不能以通常的方式将 npm package 导入 webview,例如:
var somelibrary = require('somelibrary')
Instead, you can load the package as local resource.相反,您可以将 package 作为本地资源加载。
See the Webview API documentation and example code for a detailed explanation有关详细说明,请参阅 Webview API 文档和示例代码
To do this, follow these minimum steps:为此,请按照以下最少步骤操作:
const panel = vscode.window.createWebviewPanel(
'viewType',
'view name',
vscode.ViewColumn.One,
{
// Enable javascript in the webview
enableScripts: true
}
);
const libraryPath = vscode.Uri.file(
path.join(extensionPath, 'node_modules', 'somelibrary', 'somelibrary.js')
);
const scriptUri = webview.asWebviewUri(libraryPath);
return '
...
<script src='$(scriptUri)'></script>
...
';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.