How to import an amd module in ember-cli?

前端 未结 3 1480
攒了一身酷
攒了一身酷 2021-02-13 02:13

I am building an EmberJS application with the great help of ember-cli, which is great, but I have an error and I cannot find what I am doing wrong.

Here is

3条回答
  •  灰色年华
    2021-02-13 02:16

    Try:

    app.import({
      development: 'vendor/underscore/underscore.js',
      production:  'vendor/underscore/underscore.min.js'
    }, {
      'underscore': [
        'default'
      ]
    });
    

    This will at least give "import _ from 'underscore';" a chance to work. If you choose an AMD or ES6 version of underscore/lodash, list which modules you wish to import with 'default'.

    EDIT:

    Is it crucial that you use underscore? Why I ask, I'm using lodash with one Ember-cli project, and it is working fine.

    Console> bower install lodash --save
    

    then in Brocfile:

    app.import({
      development: 'vendor/lodash/dist/lodash.js',
      production:  'vendor/lodash/dist/lodash.min.js'
    }, {
      'lodash': [
        'default'
      ]
    });
    
    
    //or:
    app.import('vendor/lodash/dist/lodash.min.js');
    

    As for underscore - there was an issue with devDependencies not being bundled, of which underscore is one.

提交回复
热议问题