Ember CLI 导入 ES6 文件到 ember-cli-builds.js
Ember CLI import ES6 file to ember-cli-builds.js
所以 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');
但是 "specify an object with the list of modules as keys along with the exports of each module as it's value" 的正确方法是什么?
在指南的"AMD Javascript modules"标题处,是这样描述的:
Provide the asset path as the first argument, and the list of modules
and exports as the second.
app.import('bower_components/ic-ajax/dist/named-amd/main.js', {
exports: {
'ic-ajax': [
'default',
'defineFixture',
'lookupFixture',
'raw',
'request'
]
}
});
You can now import
them in your app. (e.g. 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';
相关,建议避免将文件放在你要与模块系统集成的vendor文件夹中。供应商存在于包之外,所以如果你有一个独立的模块,你可以将它放在你的 app
文件夹中,也许在一些描述性文件夹下:
app/external-modules/global.js
,允许您从中导入:
import * as globalStuff from '<my-app>/external-modules/global';
所以 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');
但是 "specify an object with the list of modules as keys along with the exports of each module as it's value" 的正确方法是什么?
在指南的"AMD Javascript modules"标题处,是这样描述的:
Provide the asset path as the first argument, and the list of modules and exports as the second.
app.import('bower_components/ic-ajax/dist/named-amd/main.js', { exports: { 'ic-ajax': [ 'default', 'defineFixture', 'lookupFixture', 'raw', 'request' ] } });
You can now
import
them in your app. (e.g.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';
相关,建议避免将文件放在你要与模块系统集成的vendor文件夹中。供应商存在于包之外,所以如果你有一个独立的模块,你可以将它放在你的 app
文件夹中,也许在一些描述性文件夹下:
app/external-modules/global.js
,允许您从中导入:
import * as globalStuff from '<my-app>/external-modules/global';