mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 15:05:39 +01:00
Merge pull request #14 from dmitriylyner/enhancement/context-path
Enhancement/dynamicPublicPath - Take into account publicPath being set dynamically
This commit is contained in:
commit
198d321805
1 changed files with 14 additions and 10 deletions
24
index.js
24
index.js
|
|
@ -83,22 +83,26 @@ function getPublicPath(compiler) {
|
||||||
return compiler.options.output && compiler.options.output.publicPath || '';
|
return compiler.options.output && compiler.options.output.publicPath || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function stripTrailingSlash(string) {
|
|
||||||
return string.replace(/\/$/, '');
|
|
||||||
}
|
|
||||||
|
|
||||||
function createLoaderRules(languages, features, workers, publicPath) {
|
function createLoaderRules(languages, features, workers, publicPath) {
|
||||||
if (!languages.length && !features.length) { return []; }
|
if (!languages.length && !features.length) { return []; }
|
||||||
const languagePaths = languages.map(({ entry }) => entry).filter(Boolean);
|
const languagePaths = languages.map(({ entry }) => entry).filter(Boolean);
|
||||||
const featurePaths = features.map(({ entry }) => entry).filter(Boolean);
|
const featurePaths = features.map(({ entry }) => entry).filter(Boolean);
|
||||||
const workerPaths = workers.reduce((acc, { label, output }) => Object.assign(acc, {
|
const workerPaths = fromPairs(workers.map(({ label, output }) => [label, output]));
|
||||||
[label]: `${publicPath ? `${stripTrailingSlash(publicPath)}/` : ''}${output}`,
|
|
||||||
}), {});
|
|
||||||
const globals = {
|
const globals = {
|
||||||
'MonacoEnvironment': `(function (paths) { return { getWorkerUrl: function (moduleId, label) { return paths[label]; } }; } )(${
|
'MonacoEnvironment': `(function (paths) {
|
||||||
JSON.stringify(workerPaths, null, 2)
|
function stripTrailingSlash(str) {
|
||||||
})`,
|
return str.replace(/\\/$/, '');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
getWorkerUrl: function (moduleId, label) {
|
||||||
|
const pathPrefix = (typeof window.__webpack_public_path__ === 'string' ? window.__webpack_public_path__ : ${JSON.stringify(publicPath)});
|
||||||
|
return (pathPrefix ? stripTrailingSlash(pathPrefix) + '/' : '') + paths[label];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(${JSON.stringify(workerPaths, null, 2)})`,
|
||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
test: MONACO_EDITOR_API_PATHS,
|
test: MONACO_EDITOR_API_PATHS,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue