Monaco-editor: How to use it on browserify

Created on 4 Aug 2016  路  7Comments  路  Source: microsoft/monaco-editor

When I try to use it on browserify(gulp-browserify), other modules is not imported.
I think require is overwritten by loader.js.

I ask you to how to use it on browserify correctly.

integration

Most helpful comment

For example, you can rename loader.js require?
e.g.) require -> _require
It is possible to prevent a conflict of require function.

All 7 comments

Agreed, I'd like to be able to bundle this so that everything can be loaded synchronously and so the bundle can be limited to the specific dependencies that I want.

For example, you can rename loader.js require?
e.g.) require -> _require
It is possible to prevent a conflict of require function.

Maybe you can draw ideas from #40, it's a webpack discussion but it might help.

rename loader.js require is a good idea
webpack bundle require into one file, but loader.js require should be running dynamicly at runtime

In my case, I just replaced require with window['require'], and it worked.

<script src="https://cdn.bootcss.com/monaco-editor/0.17.1/min/vs/loader.js"></script>
window['require'].config({ paths: { 'vs': 'https://cdn.bootcss.com/monaco-editor/0.17.1/min/vs' } })
window['require'](['vs/editor/editor.main'], function () {
    const monaco = window.monaco || require('monaco-editor'); // for IntelliSense
    var editor = monaco.editor.create(document.querySelector('.editor-container'), {
        language: "javascript",
        roundedSelection: false,
        scrollBeyondLastLine: false,
        readOnly: false,
        theme: "vs",
        fontSize: 20,
    });
});

Thanks @yuanliwei your solution worked for me only I changed the cdn url to unpkg:
https://unpkg.com/[email protected]/min/vs/loader.js

Was this page helpful?
0 / 5 - 0 ratings