mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-18 07:47:23 +01:00
Refactor: update getSessionsHTML to improve CSS module handling and file root definition
This commit is contained in:
@@ -96,40 +96,40 @@ async function main() {
|
|||||||
|
|
||||||
function getSessionsHTML(host, port, cssModules) {
|
function getSessionsHTML(host, port, cssModules) {
|
||||||
const baseUrl = `http://${host}:${port}`;
|
const baseUrl = `http://${host}:${port}`;
|
||||||
|
const fileRoot = `${baseUrl}/out`;
|
||||||
|
|
||||||
|
// Build the import map server-side. Each CSS file gets mapped to a
|
||||||
|
// data: URI containing a JS module that injects the stylesheet via
|
||||||
|
// a global helper function. This must be a static <script type="importmap">
|
||||||
|
// declared before any <script type="module"> tags.
|
||||||
|
const imports = {};
|
||||||
|
for (const cssModule of cssModules) {
|
||||||
|
const cssUrl = `${fileRoot}/${cssModule}`;
|
||||||
|
const jsSrc = `globalThis._VSCODE_CSS_LOAD('${cssUrl}');\n`;
|
||||||
|
const encoded = Buffer.from(jsSrc).toString('base64');
|
||||||
|
imports[cssUrl] = `data:application/javascript;base64,${encoded}`;
|
||||||
|
}
|
||||||
|
const importMapJson = JSON.stringify({ imports }, null, 2);
|
||||||
|
|
||||||
return `<!DOCTYPE html>
|
return `<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>Sessions</title>
|
<title>Sessions</title>
|
||||||
<link rel="stylesheet" href="${baseUrl}/out/vs/sessions/sessions.desktop.main.css">
|
|
||||||
<style id="vscode-css-modules"></style>
|
<style id="vscode-css-modules"></style>
|
||||||
<script>
|
<script>
|
||||||
globalThis._VSCODE_FILE_ROOT = '${baseUrl}/out';
|
globalThis._VSCODE_FILE_ROOT = '${fileRoot}';
|
||||||
globalThis._VSCODE_CSS_MODULES = ${JSON.stringify(cssModules)};
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
// CSS import map for dev mode
|
|
||||||
const sheet = document.getElementById('vscode-css-modules').sheet;
|
const sheet = document.getElementById('vscode-css-modules').sheet;
|
||||||
globalThis._VSCODE_CSS_LOAD = function (url) { sheet.insertRule(\`@import url(\${url});\`); };
|
globalThis._VSCODE_CSS_LOAD = function (url) { sheet.insertRule(\`@import url(\${url});\`); };
|
||||||
const importMap = { imports: {} };
|
</script>
|
||||||
for (const cssModule of (globalThis._VSCODE_CSS_MODULES || [])) {
|
<script type="importmap">
|
||||||
const cssUrl = new URL(cssModule, globalThis._VSCODE_FILE_ROOT).href;
|
${importMapJson}
|
||||||
const jsSrc = \`globalThis._VSCODE_CSS_LOAD('\${cssUrl}');\\n\`;
|
|
||||||
const blob = new Blob([jsSrc], { type: 'application/javascript' });
|
|
||||||
importMap.imports[cssUrl] = URL.createObjectURL(blob);
|
|
||||||
}
|
|
||||||
if (Object.keys(importMap.imports).length > 0) {
|
|
||||||
const importMapElement = document.createElement('script');
|
|
||||||
importMapElement.type = 'importmap';
|
|
||||||
importMapElement.textContent = JSON.stringify(importMap, undefined, 2);
|
|
||||||
document.head.appendChild(importMapElement);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body aria-label="">
|
<body aria-label="">
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import { create } from '${baseUrl}/out/vs/sessions/sessions.web.main.internal.js';
|
import { create } from '${fileRoot}/vs/sessions/sessions.web.main.internal.js';
|
||||||
create(document.body, {
|
create(document.body, {
|
||||||
productConfiguration: {
|
productConfiguration: {
|
||||||
nameShort: 'Sessions (Web)',
|
nameShort: 'Sessions (Web)',
|
||||||
|
|||||||
Reference in New Issue
Block a user