mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-23 00:22:56 +01:00
per timkenrick's feedback. Slight modification in that the outer function (MonacoEnvironment iife) is run at build time while the getWorkerUrl function is run at runtime so we must move the logic for accessing window.__webpack_public_path__ inside.
This commit is contained in:
parent
87f68ff7af
commit
f7a3a213f6
1 changed files with 14 additions and 15 deletions
29
index.js
29
index.js
|
|
@ -83,27 +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 getWorkerPath = (workerPath) => {
|
|
||||||
if(!publicPath && window.__webpack_public_path__) {
|
|
||||||
return `${window.__webpack_public_path__}/${workerPath}`
|
|
||||||
}
|
|
||||||
return workerPath;
|
|
||||||
};
|
|
||||||
|
|
||||||
const globals = {
|
const globals = {
|
||||||
'MonacoEnvironment': `((paths) => ({ getWorkerUrl: (moduleId, label) => (${getWorkerPath.toString()})(paths[label]) }))(${JSON.stringify(workerPaths, null, 2)})`
|
'MonacoEnvironment': `(function (paths) {
|
||||||
|
function stripTrailingSlash(string) {
|
||||||
|
return string.replace(/\\/$/, '');
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
getWorkerUrl: function (moduleId, label) {
|
||||||
|
const pathPrefix = (typeof window.__webpack_public_path__ === 'string' ? window.__webpack_public_path__ : ${JSON.stringify(publicPath)});
|
||||||
|
var path = (pathPrefix ? stripTrailingSlash(pathPrefix) + '/' : '') + paths[label];
|
||||||
|
console.log('editor path: ' + path);
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(${JSON.stringify(workerPaths, null, 2)})`,
|
||||||
};
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue