How to import Underscore into my Ember CLI addon as a module?

I am trying to import Underscore as a named module into my Ember CLI admin. Looking at the AMD Asset Standard section, it looks like this should work:

app.import(app.bowerDirectory + '/underscore/underscore.js', { exports: { 'underscore': ['default'] } }); 

Here is a line from Underline Source :

 define('underscore', [], function() { return _; }); 

I tried to import it into one of my files, /addon/utils/class.js :

 import _ from 'underscore'; 

and received an error message:

Could not find underscore module imported from ember-cli-mirage/utils/class

What I did wrong?

+6
source share
1 answer

This is the problem: if (typeof define === 'function' && define.amd)

define.amd not specified in ember-cli loader.js.

Solutions:

  • Wrap it yourself.
  • Use a browser to make a wrapper for you.
  • Instead, use LoDash (this is what I propose - easy, ruthless, the problem is solved, and you get time for an additional round of mojito on the beach);).
+3
source

Source: https://habr.com/ru/post/984708/


All Articles