问题描述
我正在 ember-cli
的强大帮助下构建一个EmberJS应用程序,这很好,但是我有一个错误,我找不到我做错的事情。
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 what I do in my broccoli file:
app.import('vendor/underscore/underscore.js', {
exports: {
"underscore": [
"underscore"
]
}
});
然后在我的一个控制器中:
and then in one of my controllers:
import _ from "underscore";
ember-cli
构建我的应用程序。
但是当我使用下划线转到控制器时,出现错误:
But when I go to the controller using underscore, I get the error:
我在做什么错了?
推荐答案
尝试:
app.import({
development: 'vendor/underscore/underscore.js',
production: 'vendor/underscore/underscore.min.js'
}, {
'underscore': [
'default'
]
});
这至少会使从_下划线导入_;工作的机会。如果您选择下划线/破折号的AMD或ES6版本,请使用默认列出要导入的模块。
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'.
编辑:
使用下划线是否至关重要?为什么要问,我在lodash中使用了一个Ember-cli项目,所以它运行良好。
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
然后在Brocfile中:
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.
这篇关于如何在ember-cli中导入amd模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!