3
votes

Ember-cli uses ES6 syntax to import modules.

This is how you import Ember-Data:

import DS from 'ember-data'

How does Ember-cli know where to import Ember-Data from? This case doesn't seem to fit the naming conventions explained in Using Modules and the Resolver docs. (Or maybe I'm missing something.)

2

2 Answers

2
votes

The ‘ember-cli-ember-data’ node module adds ember-data to the generated Ember CLI output (via vendor.js). If you look at this module’s index.js, in the EmberCLIED.prototype.included function, you will see the following references to ember-data in the vendor directory:

    EmberCLIED.prototype.included = function included(app) {
      this.app = app;
      var options = {
        exports: {
          'ember-data': [
            'default'
          ]
        }
      };

      if (this.app.env === 'production') {
        this.app.import('vendor/ember-data/ember-data.prod.js', options); // <--
      } else {
        this.app.import('vendor/ember-data/ember-data.js', options);      // <--
      }
    };

That’s how Ember CLI knows where to find ember-data.

0
votes

The bit 'ember-data' refers to, in the case of a base install of Ember-CLI vendor/ember-data/ember-data.js.

This is exactly the same as: import Ember from 'ember'; which refers to vendor/ember/ember.js.

What you call it in the import doesn't matter. That is just a reference to what you are importing.