Skip to content

Instantly share code, notes, and snippets.

@alexdiliberto
Forked from caseywatts/0 README.md
Created November 23, 2017 04:50
Show Gist options
  • Save alexdiliberto/32236bd1a47d3002735eb1679f80c15c to your computer and use it in GitHub Desktop.
Save alexdiliberto/32236bd1a47d3002735eb1679f80c15c to your computer and use it in GitHub Desktop.
d3 & c3 npm shim to es6 module for Ember

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