Ember CLI导入ES6文件到Ember - CLI -builds.js

Ember CLI import ES6 file to ember-cli-builds.js

本文关键字:Ember CLI -builds js 文件 导入 ES6      更新时间:2023-09-26

所以ember-cli-builds.js文件清楚地说明了

// 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.

我用这种方式导入常规javascript文件

app.import('vendor/global.js');

但什么是正确的方式来"指定一个对象与模块的列表作为键以及每个模块的导出作为它的值"?

在指南的"AMD Javascript模块"标题中,它是这样描述的:

提供资源路径作为第一个参数,以及模块列表并导出为第二个。

app.import('bower_components/ic-ajax/dist/named-amd/main.js', {
  exports: {
    'ic-ajax': [
      'default',
      'defineFixture',
      'lookupFixture',
      'raw',
      'request'
    ]
  }
});

你现在可以在你的应用程序中import它们(例如import { raw as icAjaxRaw } from 'ic-ajax';)

参考资料

选择器的答案是旧ember, pre - ember-auto-import (webpack)和pre ember Octane。

在现代ember中,在npm install包之后,您可以直接从该包中导入。

的例子:

npm install qs

然后在应用程序的任何地方

import qs from 'qs';
如果与

相关,建议避免将要与模块系统集成的文件放在供应商文件夹中。供应商存在于包之外,所以如果你有一个独立的模块,你可以把它放在你的app文件夹,也许在一些描述性的文件夹下:app/external-modules/global.js,允许您从它导入,如:

import * as globalStuff from '<my-app>/external-modules/global';