[英]UMD With Ember-CLI
I am trying to load the gridstack in my Ember application via ember-cli.我正在尝试通过 ember-cli 在我的 Ember 应用程序中加载gridstack 。 I installed the application via
bower
and imported in my ember-cli-build.js
file.我通过
bower
安装了该应用程序并导入到我的ember-cli-build.js
文件中。 It includes _
as a library via:它包括
_
作为一个库,通过:
if (typeof define === 'function' && define.amd) {
define(['jquery', 'lodash'], factory);
}
define.amd
evaulates to false
define.amd
evaulates到false
I looked into why this is the case , and found that ember-cli's loader doesn't support UMD
.我调查了为什么会这样,发现 ember-cli 的加载程序不支持
UMD
。 On an open cli issue , Stefan Penner, one of the main cli developers, suggested:在开放 cli问题上,主要 cli 开发人员之一 Stefan Penner 建议:
This is by design.
这是设计使然。 As this library requires a pre build step to de-anonymize the modules.
因为这个库需要一个预构建步骤来对模块进行去匿名化。 That step can do the appropriate munging to work correctly
该步骤可以进行适当的修改以正常工作
I have no clue what that means.我不知道这意味着什么。 I got around the issue by manually importing the dependencies of this library in my own
ember-cli-build
before this library but that's defeating the purpose of dependency management.我通过在这个库之前在我自己的
ember-cli-build
手动导入这个库的依赖项来解决这个问题,但这ember-cli-build
了依赖项管理的目的。 How can I make this library resolve its own modules?我怎样才能让这个库解析它自己的模块?
Latest Ember CLI blueprints for new Ember projects contain ember-auto-import .新 Ember 项目的最新 Ember CLI 蓝图包含ember-auto-import 。
ember-auto-import
is a library that allows to import any NPM library in Ember. ember-auto-import
是一个允许在 Ember 中导入任何 NPM 库的库。 No configuration is needed.无需配置。 It could also be installed in projects using an older Ember CLI version and is the recommended way.
它也可以使用较旧的 Ember CLI 版本安装在项目中,这是推荐的方式。
If you don't want to install an additional dependency - even if it's part of official blueprints - Ember CLI not only supports Standard Named AMD Asset via app.import('path/to/entry-point.js')
but also Standard Anonymous AMD Asset :如果您不想安装额外的依赖项 - 即使它是官方蓝图的一部分 - Ember CLI 不仅通过
app.import('path/to/entry-point.js')
支持标准命名的 AMD 资产,还支持 标准匿名AMD 资产:
app.import('path/to/entry-point.js', {
using: [
{ transformation: 'amd', as: 'your-named-import' }
]
});
As normal this goes into your ember-cli-build.js
.正常情况下,这会进入您的
ember-cli-build.js
。
Sidenode: For some time ember-browserify was the recommended solution for CommonJS modules. Sidenode:有一段时间ember- browserify 是 CommonJS 模块的推荐解决方案。 But it has been deprecated in favor of
ember-auto-import
.但它已被弃用,取而代之的是
ember-auto-import
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.