Open mbrodala opened 9 years ago
+1, using it from GitHub Electron shell, but have to include the js file in my index.html
Current workaround is to use shim
and define exports
to make it loadable via RequireJS but this provides no encapsulation at all:
requirejs.config({
shim: {
"path/to/json-editor": {
exports: "JSONEditor"
}
}
});
Then use it as usual:
define(["path/to/json-editor"], function(JSONEditor) {});
This doesn't seem to work with Handlebars. The latest version of Handlebars (as of this time, 3.0.3) supports AMD loading and so does not bind window.Handlebars (as is expected in https://github.com/jdorn/json-editor/blob/master/src/templates/handlebars.js#L2 )
The only workaround I've managed to get working at the moment is this:
jsonEditor: {
deps: ["handlebars"],
init: function (Handlebars) {
window.Handlebars = Handlebars;
return this.JSONEditor;
},
exports: "JSONEditor"
},
Which is pretty terrible since it breaks the whole module encapsulation pattern.
The actual issue here is that there are optional dependencies which doesn't work with the AMD pattern. Normally one should split all the different templating engines to separate AMD modules with proper dependencies.
+1, Just a chime in to say that this would be an amazing thing to add in!
It would be great if the JSON editor supports AMD/RequireJS.
Since Grunt is apparently already used to build dist scripts, grunt-umd should do the trick. See twitter/typeahead.js for an example.