jax
jax

Reputation: 38653

Importing an es6 module that may not exist

Just say I create an addon that is shared with other users and I need to import ember-data.

import DS from 'ember-data';

How can I import this given it might not exist in the client code. Basically I need a condition to check if ember-data is available, if so import it and do something, else don't do it.

if(ember data exists) {
  //do something
}

Upvotes: 8

Views: 503

Answers (1)

JackCA
JackCA

Reputation: 4885

I have the same question for general es6 usage, but assuming you're using ember-cli you can look at the require._eak_seen object so your code could potentially look something like:

if(require._eak_seen['ember-data']){
  //your code
}

Upvotes: 1

Related Questions