Felx-B / vscode-web

Visual Studio Code for browser
MIT License
405 stars 105 forks source link

workbench.ts patch now unnecessary #39

Open progrium opened 3 months ago

progrium commented 3 months ago

I don't know when this was introduced, but the stock workbench.ts will pull config from a data attribute of an element with id vscode-workbench-web-configuration. So I do a synchronous fetch of product.json (though maybe better to name workbench.json) in the index.html before the VSCode sources are loaded. If I understand correctly, this achieves the same result of the patched workbench.ts you have without patching/replacing it.

https://github.com/progrium/vscode-web/blob/main/patched/index.html#L27-L40

wylieconlon commented 1 month 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.

  1. Install the official @vscode/test-web as a dependency of your repo
  2. npx vscode-test-web --esm
  3. View source on localhost:3000, and copy this as workbench.html
  4. Edit workbench.html by deleting
<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

pomdtr commented 2 weeks ago

It looks like you can also get the latest build url by going to:

pomdtr commented 2 weeks ago

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.