Skip to content

Instantly share code, notes, and snippets.

@caseywatts
Last active May 2, 2024 06:06
Show Gist options
  • Save caseywatts/347e18e4905c447859fa777ec97c34f8 to your computer and use it in GitHub Desktop.
Save caseywatts/347e18e4905c447859fa777ec97c34f8 to your computer and use it in GitHub Desktop.
d3 & c3 npm shim to es6 module for Ember

UPDATE: You don't need shims anymore! We can just use this now, and eventually it'll even be in Ember core.

app.import() works with node_modules now! As of Ember 2.15. Previously it only worked with bower_components and vendor.

Docs for app.import are here: https://ember-cli.com/managing-dependencies#standard-non-amd-asset

This method (vendor-shim) wraps the global export into an es6 module (but the global one is still present). It doesn't use an es6 interface even if the library offers one, but that's okay for my use case.

Things could still be easier, see this thread for the current state of that.

// vendor/shims/c3.js
// generated by `ember generate vendor-shim c3`
(function() {
function vendorModule() {
'use strict';
return {
'default': self['c3'],
__esModule: true,
};
}
define('c3', [], vendorModule);
})();
// vendor/shims/d3.js
// generated by `ember generate vendor-shim d3`
(function() {
function vendorModule() {
'use strict';
return {
'default': self['d3'],
__esModule: true,
};
}
define('d3', [], vendorModule);
})();
/* eslint-env node */
'use strict';
const EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
let app = new EmberApp(defaults, {
// Add options here
});
app.import('node_modules/d3/d3.js');
app.import('node_modules/d3/d3.css');
app.import('vendor/shims/d3.js');
app.import('node_modules/c3/c3.js');
app.import('node_modules/c3/c3.css');
app.import('vendor/shims/c3.js');
return app.toTree();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment