index.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Hello World!</title>
  6. </head>
  7. <body>
  8. <h1>Hello World!</h1>
  9. <div id="container" style="width:500px;height:300px;border:1px solid #ccc"></div>
  10. </body>
  11. <script>
  12. // Monaco uses a custom amd loader that over-rides node's require.
  13. // Keep a reference to node's require so we can restore it after executing the amd loader file.
  14. var nodeRequire = global.require;
  15. </script>
  16. <script src="../node_modules/monaco-editor/min/vs/loader.js"></script>
  17. <script>
  18. // Save Monaco's amd require and restore Node's require
  19. var amdRequire = global.require;
  20. global.require = nodeRequire;
  21. </script>
  22. <script>
  23. // require node modules before loader.js comes in
  24. var path = require('path');
  25. function uriFromPath(_path) {
  26. var pathName = path.resolve(_path).replace(/\\/g, '/');
  27. if (pathName.length > 0 && pathName.charAt(0) !== '/') {
  28. pathName = '/' + pathName;
  29. }
  30. return encodeURI('file://' + pathName);
  31. }
  32. amdRequire.config({
  33. baseUrl: uriFromPath(path.join(__dirname, '../node_modules/monaco-editor/min'))
  34. });
  35. // workaround monaco-css not understanding the environment
  36. self.module = undefined;
  37. // workaround monaco-typescript not understanding the environment
  38. self.process.browser = true;
  39. amdRequire(['vs/editor/editor.main'], function() {
  40. var editor = monaco.editor.create(document.getElementById('container'), {
  41. value: [
  42. 'function x() {',
  43. '\tconsole.log("Hello world!");',
  44. '}'
  45. ].join('\n'),
  46. language: 'javascript'
  47. });
  48. });
  49. </script>
  50. </html>