Open progrium opened 3 months ago
It seems like it's become even easier to consume the workbench file with the recent ESM changes that vscode has been releasing over the last few week. Here's what I'm doing, which does not use the vscode-web prepackaged assets at all.
@vscode/test-web
as a dependency of your reponpx vscode-test-web --esm
localhost:3000
, and copy this as workbench.html
<meta id="vscode-workbench-web-configuration"
And replace:
(function () {
const configElement = window.document.getElementById('vscode-workbench-web-configuration');
const configElementAttribute = configElement ? configElement.getAttribute('data-settings') : undefined;
if (!configElement || !configElementAttribute) {
throw new Error('Missing web configuration element');
}
const config = JSON.parse(configElementAttribute);
create(window.document.body, {
...config,
workspaceProvider: WorkspaceProvider.create(config),
urlCallbackProvider: new LocalStorageURLCallbackProvider(config.callbackRoute)
});
})();
with your config object:
(function () {
const config = {
productConfiguration: {
nameShort: "VSCode Web Sample",
nameLong: "VSCode Web sample",
applicationName: "code-web-sample",
dataFolderName: ".vscode-web-sample",
version: "1.95.0",
extensionsGallery: {
serviceUrl: "https://open-vsx.org/vscode/gallery",
itemUrl: "https://open-vsx.org/vscode/item",
resourceUrlTemplate: "https://openvsxorg.blob.core.windows.net/resources/{publisher}/{name}/{version}/{path}"
},
extensionEnabledApiProposals: {
"yourcompay.yourextension": ["fileSearchProvider", "textSearchProvider", "ipc"]
}
},
folderUri: { scheme: "memfs", path: "/" },
additionalBuiltinExtensions: [{
scheme: window.location.protocol === "http:" ? "http" : "https",
authority: window.location.host,
}]
};
create(window.document.body, {
...config,
workspaceProvider: WorkspaceProvider.create(config),
urlCallbackProvider: new LocalStorageURLCallbackProvider(config.callbackRoute)
});
})();
then, you can use the official built assets from the .vscode-test-web/vscode-web-insider-<sha>
folder along with your custom workbench.html file
It looks like you can also get the latest build url by going to:
In my case, I also add to set the following global var:
globalThis._VSCODE_WEB_PACKAGE_TTP = window.trustedTypes?.createPolicy('amdLoader', {
createScriptURL(value) {
return value;
}
})
Otherwise I was not able to load assets from a CDN.
I don't know when this was introduced, but the stock
workbench.ts
will pull config from a data attribute of an element with idvscode-workbench-web-configuration
. So I do a synchronous fetch ofproduct.json
(though maybe better to nameworkbench.json
) in theindex.html
before the VSCode sources are loaded. If I understand correctly, this achieves the same result of the patchedworkbench.ts
you have without patching/replacing it.https://github.com/progrium/vscode-web/blob/main/patched/index.html#L27-L40