如何在Ember.JS应用程序中加载Require.JS开发的模块?

如何在Ember.JS应用程序中加载Require.JS开发的模块?,ember.js,requirejs,Ember.js,Requirejs,我正在尝试将使用Require.JS开发的第三方库集成到新的Ember.JS应用程序中。我看过像ember cli amd和ember auto import这样的插件,但我不知道如何让它们在这样加载的库中工作 <script data-main="jslib/app/LibConfig" type="text/javascript" src="jslib/modules/require.js"></script> 欢迎来到堆栈溢出 因此,您不能在Ember中直接使用r

我正在尝试将使用Require.JS开发的第三方库集成到新的Ember.JS应用程序中。我看过像ember cli amd和ember auto import这样的插件,但我不知道如何让它们在这样加载的库中工作

<script data-main="jslib/app/LibConfig" type="text/javascript" src="jslib/modules/require.js"></script>

欢迎来到堆栈溢出

因此,您不能在Ember中直接使用require.js,但Ember loader会为您构建require.js版本。您只需确保要使用的库是命名的AMD或UMD格式,并且可以使用app.import从您的ember cli构建文件中导入它们,如下所示:

// ember-cli-build.js

'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    // Add options here
  });

  // Use `app.import` to add additional libraries to the generated
  // output files.
  //
  // If you need to use different assets in different
  // environments, specify an object as the first parameter. That
  // object's keys should be the environment name and the values
  // should be the asset to use in that environment.
  //
  // If the library that you are including contains AMD or ES6
  // modules that you would like to import into your application
  // please specify an object with the list of modules as keys
  // along with the exports of each module as its value.

  app.import('vendor/my-awesome-named-amd-library.js');

  return app.toTree();
};
有关详细信息,请参阅:


或者,查看您要使用的库的版本是否在npm中,
ember auto import
可以确定格式并为您完成工作。

欢迎使用Stack Overflow

因此,您不能在Ember中直接使用require.js,但Ember loader会为您构建require.js版本。您只需确保要使用的库是命名的AMD或UMD格式,并且可以使用app.import从您的ember cli构建文件中导入它们,如下所示:

// ember-cli-build.js

'use strict';

const EmberApp = require('ember-cli/lib/broccoli/ember-app');

module.exports = function(defaults) {
  let app = new EmberApp(defaults, {
    // Add options here
  });

  // Use `app.import` to add additional libraries to the generated
  // output files.
  //
  // If you need to use different assets in different
  // environments, specify an object as the first parameter. That
  // object's keys should be the environment name and the values
  // should be the asset to use in that environment.
  //
  // If the library that you are including contains AMD or ES6
  // modules that you would like to import into your application
  // please specify an object with the list of modules as keys
  // along with the exports of each module as its value.

  app.import('vendor/my-awesome-named-amd-library.js');

  return app.toTree();
};
有关详细信息,请参阅:

或者,查看您要使用的库的版本是否在npm中,
ember auto import
可以确定格式并为您完成工作