It is possible to use RequireJS to inject some modules into a custom script, for example:
define([
'jquery',
'tinymce',
'Magento_Ui/js/modal/modal'
], function($, modal, tinymce) {
"use strict";
...
});
However, it looks like in Magento 2.3 the module tinymce is no longer supported, but it is possible to use tinymce4. However, that is not backwards-compatible.
The question is, is it possible to check whether a module exists before defining it? It have tried with require.defined and require.specified but they appear to check against what's defined with define(), not what exists.
Ideally I'd want something like this:
var tinymce_module = requirejs.moduleExists('tinymce4') ? 'tinymce4' : 'tinymce';
define([
'jquery',
tinymce_module,
'Magento_Ui/js/modal/modal'
], function($, modal, tinymce) {
"use strict";
...
});
P.S. Any help regarding loading TinyMCE across Magento 2 versions specifically would be appreciated in the comments as well.