If I want to create an add-on for Ember.js, let's call it ember-awesome for the purpose of this question, that is a wrapper around a library awesome-lib.js and its extensions. How do I create a shim around that library and any extensions I want to bundle with it?
Assume for a moment that awesome-lib.js
can have plugins or extensions to its funcitonality, e.g. awesome-ext-foo.js
, awesome-ext-bar.js
, etc. What is the best way to write a shim for and add-on that provides awesome-lib, awesome-ext-foo, and awesome-ext-bar to the component?
I thought I might be able to define a single shim, e.g. vendor/shims/awesome-lib-shim.js
as such:
// ember-awesome/vendor/shims/awesome-lib-shim.js
define("awesome-lib", [
"awesome-lib",
"awesome-ext-foo",
"awesome-ext-bar"], function(awesomeLib, extFoo, extBar) {
return {
"default": awesomeLib,
"foo": extFoo,
"bar": extBar
};
})
And use it in my ember-awesome/index.js
as such:
// ember-awesome/index.js
module.exports = {
name: "ember-awesome",
included: function(app) {
...
this.app.import("vendor/shims/awesome-lib-shim.js", {
type: "vendor",
exports: {
"awesome-lib": ["default"],
"awesome-ext-foo": ["foo"],
"awesome-ext-bar": ["bar"],
}
});
...
}
...
};
This doesn't seem to work though. I can always create different shims, sure, but thought it would make the most sense to bundle like-components together in the same shim.
A good, real world, example of the type library and extension complexity I'm looking to write an add-on around is the markdown-it and its extensions