mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Take <base href=..> into account
This commit is contained in:
parent
6b7dfecca4
commit
083face122
1 changed files with 16 additions and 2 deletions
16
index.js
16
index.js
|
|
@ -94,8 +94,22 @@ function createLoaderRules(languages, features, workers, publicPath) {
|
|||
const workerPaths = workers.reduce((acc, { label, output }) => Object.assign(acc, {
|
||||
[label]: `${publicPath ? `${stripTrailingSlash(publicPath)}/` : ''}${output}`,
|
||||
}), {});
|
||||
|
||||
const getBasePath = () => {
|
||||
const bases = document.getElementsByTagName('base');
|
||||
let contextPath = '/';
|
||||
if (bases.length) {
|
||||
contextPath = bases[0].getAttribute('context') || bases[0].href || '/';
|
||||
}
|
||||
return contextPath;
|
||||
}
|
||||
|
||||
const getWorkerPath = (workerPath) => {
|
||||
return `${getBasePath()}/${workerPath}`.replace('//', '/');
|
||||
}
|
||||
|
||||
const globals = {
|
||||
'MonacoEnvironment': `((paths) => ({ getWorkerUrl: (moduleId, label) => paths[label] }))(${
|
||||
'MonacoEnvironment': `((paths) => ({ getWorkerUrl: (moduleId, label) => ${getWorkerPath(paths[label])}}))(${
|
||||
JSON.stringify(workerPaths, null, 2)
|
||||
})`,
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue