How to set path for files in monaco editor?

2k views Asked by At

This is a snippet of html code in a test.html file.

<script src="monaco-editor/min/vs/loader.js"></script>
<script>
 require.config({ paths: { 'vs': 'monaco-editor/min/vs' }});
 require(['vs/editor/editor.main'], function() {
  var editor = monaco.editor.create(document.getElementById('container'), {
   value: [
    'function x() {',
    '\tconsole.log("Hello world!");',
    '}'
   ].join('\n'),
   language: 'javascript'
  });
 });
</script>

this is a file tree on my system.

ide ├── cpp14 │   ├── test.html ├── monaco └── node_modules ├── monaco-editor    └── test.html

I copied test.html file from monaco/node_moules/ to cpp14

And changed all the paths in cpp14/test.html to

<script src="ide/monaco/node_modules/monaco-editor/min/vs/loader.js"></script>
<script>
 require.config({ paths: { 'vs': 'ide/monaco/node_modules/monaco-editor/min/vs' }});
 require(['ide/monaco/node_modules/monaco-editor/min/vs/editor/editor.main'], function() {
  var editor = monaco.editor.create(document.getElementById('container'), {
   value: [
    'function x() {',
    '\tconsole.log("Hello world!");',
    '}'
   ].join('\n'),
   language: 'javascript'
  });
    });

This is not working and I think there is error in setting path of those files in the snippet. How to make this work ?

1

There are 1 answers

0
David I. Samudio On

Try aliasing it:

require.config({
    paths:{
         'ide/monaco/node_modules/test.html': 'ide/cpp14/test.html'
          'vs': '...'
    }
});