0.0.1 • Published 5 years ago

@cardstack/requirejs-monaco-ember-polyfill v0.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

requirejs-monaco-ember-polyfill

This polyfill was created for Ember apps that use the ESM/Webpack configuration of monaco-editor via Embroider. It is not needed when using ember-monaco.

The polyfill attaches a fake .s.contexts._config with a value of '' to window.requirejs that runs as soon as the package is imported.

Usage

yarn add @cardstack/requirejs-monaco-ember-polyfill
import requirejsContext from 'requirejs-monaco-ember-polyfill';
import * as monaco from 'monaco-editor';
// the order of imports matters!

requirejsContext()

Why is this needed?

This is needed because the SimpleWorker.js in monaco-editor has the following code:

loaderConfiguration = self.requirejs.s.contexts._.config;

However, Ember apps have their own requirejs that do not have these properties/methods. So, we need to stub or polyfill it to prevent type errors when monaco tries to look up the config.

This has to be a node module because it must resolve before monaco's workers initialize. Required dependencies are evaluated before any other code in a JavaScript file.

Without this polyfill, the Workers will fail to initialize.