mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 19:42:56 +01:00
Reduce reliance on RESOLVED_CORE_PATH
This commit is contained in:
parent
346cb83091
commit
745893d211
7 changed files with 56 additions and 49 deletions
|
|
@ -14,7 +14,6 @@
|
||||||
|
|
||||||
<script src="../metadata.js"></script>
|
<script src="../metadata.js"></script>
|
||||||
<script src="dev-setup.js"></script>
|
<script src="dev-setup.js"></script>
|
||||||
<script>document.write('<script src="http://localhost:8088' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
|
|
||||||
<script>
|
<script>
|
||||||
loadEditor(function() {
|
loadEditor(function() {
|
||||||
monaco.editor.create(document.getElementById('container'), {
|
monaco.editor.create(document.getElementById('container'), {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
<script>document.write('<script src="http://localhost:8088' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
|
|
||||||
<script>
|
<script>
|
||||||
loadEditor(function() {
|
loadEditor(function() {
|
||||||
monaco.editor.create(document.getElementById('container'), {
|
monaco.editor.create(document.getElementById('container'), {
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
function parseLoaderOptions() {
|
var LOADER_OPTS = (function() {
|
||||||
function parseQueryString() {
|
function parseQueryString() {
|
||||||
var str = window.location.search;
|
var str = window.location.search;
|
||||||
str = str.replace(/^\?/, '');
|
str = str.replace(/^\?/, '');
|
||||||
|
|
@ -19,63 +19,76 @@
|
||||||
result[plugin.name] = overwrites[plugin.name] || 'npm';
|
result[plugin.name] = overwrites[plugin.name] || 'npm';
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
}
|
})();
|
||||||
var LOADER_OPTS = parseLoaderOptions();
|
|
||||||
|
|
||||||
|
function Component(name, modulePrefix, paths, contrib) {
|
||||||
|
this.name = name;
|
||||||
|
this.modulePrefix = modulePrefix;
|
||||||
|
this.paths = paths;
|
||||||
|
this.contrib = contrib;
|
||||||
|
this.selectedPath = LOADER_OPTS[name];
|
||||||
|
}
|
||||||
|
Component.prototype.getResolvedPath = function() {
|
||||||
|
var resolvedPath = this.paths[this.selectedPath];
|
||||||
|
if (this.selectedPath === 'npm') {
|
||||||
|
resolvedPath = '/monaco-editor/' + resolvedPath;
|
||||||
|
}
|
||||||
|
return resolvedPath;
|
||||||
|
};
|
||||||
|
Component.prototype.generateLoaderConfig = function(dest) {
|
||||||
|
dest[this.modulePrefix] = this.getResolvedPath();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var RESOLVED_CORE = new Component('editor', 'vs', METADATA.CORE.paths);
|
||||||
|
var RESOLVED_PLUGINS = METADATA.PLUGINS.map(function(plugin) {
|
||||||
|
return new Component(plugin.name, plugin.modulePrefix, plugin.paths, plugin.contrib);
|
||||||
|
});
|
||||||
|
self.METADATA = null;
|
||||||
|
|
||||||
|
|
||||||
|
function loadScript(path, callback) {
|
||||||
|
var script = document.createElement('script');
|
||||||
|
script.onload = callback;
|
||||||
|
script.async = true;
|
||||||
|
script.type = 'text/javascript';
|
||||||
|
script.src = path;
|
||||||
|
document.head.appendChild(script);
|
||||||
|
}
|
||||||
|
|
||||||
// console.log(JSON.stringify(LOADER_OPTS, null, '\t'));
|
|
||||||
|
|
||||||
self.loadDevEditor = function() {
|
self.loadDevEditor = function() {
|
||||||
return (getQueryStringValue('editor') === 'dev');
|
return (getQueryStringValue('editor') === 'dev');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getQueryStringValue (key) {
|
function getQueryStringValue (key) {
|
||||||
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
|
return unescape(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + escape(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function resolvePath(paths, selectedPath) {
|
|
||||||
if (selectedPath === 'npm') {
|
|
||||||
return '/monaco-editor/' + paths[selectedPath];
|
|
||||||
} else {
|
|
||||||
return paths[selectedPath];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.RESOLVED_CORE_PATH = resolvePath(METADATA.CORE.paths, LOADER_OPTS['editor']);
|
|
||||||
var RESOLVED_PLUGINS = METADATA.PLUGINS.map(function(plugin) {
|
|
||||||
return {
|
|
||||||
name: plugin.name,
|
|
||||||
contrib: plugin.contrib,
|
|
||||||
modulePrefix: plugin.modulePrefix,
|
|
||||||
path: resolvePath(plugin.paths, LOADER_OPTS[plugin.name])
|
|
||||||
};
|
|
||||||
});
|
|
||||||
self.METADATA = null;
|
|
||||||
|
|
||||||
self.loadEditor = function(callback, PATH_PREFIX) {
|
self.loadEditor = function(callback, PATH_PREFIX) {
|
||||||
PATH_PREFIX = PATH_PREFIX || '';
|
PATH_PREFIX = PATH_PREFIX || '';
|
||||||
var pathsConfig = {};
|
|
||||||
RESOLVED_PLUGINS.forEach(function(plugin) {
|
|
||||||
pathsConfig[plugin.modulePrefix] = PATH_PREFIX + plugin.path;
|
|
||||||
});
|
|
||||||
pathsConfig['vs'] = PATH_PREFIX + RESOLVED_CORE_PATH;
|
|
||||||
|
|
||||||
var loaderInfo = document.createElement('div');
|
loadScript(PATH_PREFIX + RESOLVED_CORE.getResolvedPath() + '/loader.js', function() {
|
||||||
loaderInfo.style.position = 'fixed';
|
var loaderPathsConfig = {};
|
||||||
loaderInfo.style.top = 0;
|
RESOLVED_PLUGINS.forEach(function(plugin) {
|
||||||
loaderInfo.style.right = 0;
|
plugin.generateLoaderConfig(loaderPathsConfig);
|
||||||
loaderInfo.innerHTML = 'LOADER PATH CONFIGURATION: ' + '<br/><pre>' + JSON.stringify(pathsConfig, null, '\t') + '</pre>';
|
});
|
||||||
document.body.appendChild(loaderInfo);
|
RESOLVED_CORE.generateLoaderConfig(loaderPathsConfig);
|
||||||
|
|
||||||
require.config({
|
console.log('LOADER CONFIG: ');
|
||||||
paths: pathsConfig
|
console.log(JSON.stringify(loaderPathsConfig, null, '\t'));
|
||||||
});
|
|
||||||
|
|
||||||
require(['vs/editor/editor.main'], function() {
|
require.config({
|
||||||
// At this point we've loaded the monaco-editor-core
|
paths: loaderPathsConfig
|
||||||
require(RESOLVED_PLUGINS.map(function(plugin) { return plugin.contrib; }), function() {
|
});
|
||||||
// At this point we've loaded all the plugins
|
|
||||||
callback();
|
require(['vs/editor/editor.main'], function() {
|
||||||
// require(['./index'], function() {});
|
// At this point we've loaded the monaco-editor-core
|
||||||
|
require(RESOLVED_PLUGINS.map(function(plugin) { return plugin.contrib; }), function() {
|
||||||
|
// At this point we've loaded all the plugins
|
||||||
|
callback();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,6 @@
|
||||||
|
|
||||||
<script src="../metadata.js"></script>
|
<script src="../metadata.js"></script>
|
||||||
<script src="dev-setup.js"></script>
|
<script src="dev-setup.js"></script>
|
||||||
<script>document.write('<script src="' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
|
|
||||||
<script>
|
<script>
|
||||||
loadEditor(function() {
|
loadEditor(function() {
|
||||||
require(['./index'], function() {});
|
require(['./index'], function() {});
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@
|
||||||
|
|
||||||
<script src="../metadata.js"></script>
|
<script src="../metadata.js"></script>
|
||||||
<script src="dev-setup.js"></script>
|
<script src="dev-setup.js"></script>
|
||||||
<script>document.write('<script src="' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
|
|
||||||
<script>
|
<script>
|
||||||
loadEditor(function() {
|
loadEditor(function() {
|
||||||
monaco.editor.create(document.getElementById('Editor'), {
|
monaco.editor.create(document.getElementById('Editor'), {
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,6 @@
|
||||||
|
|
||||||
<script src="../metadata.js"></script>
|
<script src="../metadata.js"></script>
|
||||||
<script src="dev-setup.js"></script>
|
<script src="dev-setup.js"></script>
|
||||||
<script>document.write('<script src="' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
|
|
||||||
<script>
|
<script>
|
||||||
loadEditor(function() {
|
loadEditor(function() {
|
||||||
monaco.editor.create(document.getElementById('editor'), {
|
monaco.editor.create(document.getElementById('editor'), {
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,6 @@
|
||||||
|
|
||||||
<script src="../metadata.js"></script>
|
<script src="../metadata.js"></script>
|
||||||
<script src="dev-setup.js"></script>
|
<script src="dev-setup.js"></script>
|
||||||
<script>document.write('<script src="' + RESOLVED_CORE_PATH + '/loader.js"><'+'/script>');</script>
|
|
||||||
<script>
|
<script>
|
||||||
loadEditor(function() {
|
loadEditor(function() {
|
||||||
monaco.editor.create(document.getElementById('editor'), {
|
monaco.editor.create(document.getElementById('editor'), {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue