mirror of
https://github.com/microsoft/monaco-editor.git
synced 2025-12-22 17:25:39 +01:00
Restore node's require after loading loader.js
This commit is contained in:
parent
4dad8338f9
commit
cc7b52cdcc
1 changed files with 14 additions and 5 deletions
|
|
@ -10,12 +10,21 @@
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
// require node modules before loader.js comes in
|
// Monaco uses a custom amd loader that over-rides node's require.
|
||||||
var path = require('path');
|
// Keep a reference to node's require so we can restore it after executing the amd loader file.
|
||||||
|
var nodeRequire = global.require;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
|
<script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
// Save Monaco's amd require and restore Node's require
|
||||||
|
var amdRequire = global.require;
|
||||||
|
global.require = nodeRequire;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
// require node modules before loader.js comes in
|
||||||
|
var path = require('path');
|
||||||
|
|
||||||
function uriFromPath(_path) {
|
function uriFromPath(_path) {
|
||||||
var pathName = path.resolve(_path).replace(/\\/g, '/');
|
var pathName = path.resolve(_path).replace(/\\/g, '/');
|
||||||
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
|
if (pathName.length > 0 && pathName.charAt(0) !== '/') {
|
||||||
|
|
@ -24,7 +33,7 @@
|
||||||
return encodeURI('file://' + pathName);
|
return encodeURI('file://' + pathName);
|
||||||
}
|
}
|
||||||
|
|
||||||
require.config({
|
amdRequire.config({
|
||||||
baseUrl: uriFromPath(path.join(__dirname, '../node_modules/monaco-editor/min'))
|
baseUrl: uriFromPath(path.join(__dirname, '../node_modules/monaco-editor/min'))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -34,7 +43,7 @@
|
||||||
// workaround monaco-typescript not understanding the environment
|
// workaround monaco-typescript not understanding the environment
|
||||||
self.process.browser = true;
|
self.process.browser = true;
|
||||||
|
|
||||||
require(['vs/editor/editor.main'], function() {
|
amdRequire(['vs/editor/editor.main'], function() {
|
||||||
var editor = monaco.editor.create(document.getElementById('container'), {
|
var editor = monaco.editor.create(document.getElementById('container'), {
|
||||||
value: [
|
value: [
|
||||||
'function x() {',
|
'function x() {',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue