electron-index.html 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta
  6. http-equiv="Content-Security-Policy"
  7. content="default-src 'none'; script-src file: 'sha256-RtE3AqQ1tBhtcwykhJsEKY7jjCqiGy5yH1mRDwu6gEE='; style-src 'unsafe-inline' file:; font-src file:"
  8. />
  9. <title>Monaco Editor!</title>
  10. </head>
  11. <body>
  12. <h1>Monaco Editor in Electron!</h1>
  13. <div id="container" style="width: 500px; height: 300px; border: 1px solid #ccc"></div>
  14. </body>
  15. <script>
  16. (function () {
  17. const path = require('path');
  18. const amdLoader = require('../node_modules/monaco-editor/min/vs/loader.js');
  19. const amdRequire = amdLoader.require;
  20. const amdDefine = amdLoader.require.define;
  21. function uriFromPath(_path) {
  22. var pathName = path.resolve(_path).replace(/\\/g, '/');
  23. if (pathName.length > 0 && pathName.charAt(0) !== '/') {
  24. pathName = '/' + pathName;
  25. }
  26. return encodeURI('file://' + pathName);
  27. }
  28. amdRequire.config({
  29. baseUrl: uriFromPath(path.join(__dirname, '../node_modules/monaco-editor/min'))
  30. });
  31. // workaround monaco-css not understanding the environment
  32. self.module = undefined;
  33. amdRequire(['vs/editor/editor.main'], function () {
  34. var editor = monaco.editor.create(document.getElementById('container'), {
  35. value: ['function x() {', '\tconsole.log("Hello world!");', '}'].join('\n'),
  36. language: 'javascript'
  37. });
  38. });
  39. })();
  40. </script>
  41. </html>