Take <base href=..> into account

This commit is contained in:
Dmitriy Lyner 2018-05-30 10:15:11 -06:00
parent 6b7dfecca4
commit 083face122

View file

@ -94,8 +94,22 @@ function createLoaderRules(languages, features, workers, publicPath) {
const workerPaths = workers.reduce((acc, { label, output }) => Object.assign(acc, { const workerPaths = workers.reduce((acc, { label, output }) => Object.assign(acc, {
[label]: `${publicPath ? `${stripTrailingSlash(publicPath)}/` : ''}${output}`, [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 = { const globals = {
'MonacoEnvironment': `((paths) => ({ getWorkerUrl: (moduleId, label) => paths[label] }))(${ 'MonacoEnvironment': `((paths) => ({ getWorkerUrl: (moduleId, label) => ${getWorkerPath(paths[label])}}))(${
JSON.stringify(workerPaths, null, 2) JSON.stringify(workerPaths, null, 2)
})`, })`,
}; };