From 083face1221e92458184173f47a64d0b859ebdae Mon Sep 17 00:00:00 2001 From: Dmitriy Lyner Date: Wed, 30 May 2018 10:15:11 -0600 Subject: [PATCH] Take into account --- index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3d4fc99e..307bcf24 100644 --- a/index.js +++ b/index.js @@ -94,10 +94,24 @@ 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) - })`, + })`, }; return [ {