我们有一个大规模的JavaScript应用程序,我们试图使用grunt-contrib-requirejs进行连接和缩小。我们使用Aura框架。我们使用bower将其他存储库中的依赖关系引入我们的主应用程序。requirejs优化器 - 需要帮助优化我们的应用程序
这里是我们应用结构
- app/
|
|_ main.js
|_ index.html
|_ css
|_ bower_components/
|_ core/
|_ widget1/
|_ main.js
|_ views/
|_ models/
|_ widget2/
|_ extension1/
|_ extension2/
|_ other third party libraries, etc
- Gruntfile.js
- bower.json
main.js:
requirejs.config({
shim: {
...
},
paths: {
'core': 'bower_components/core/app/main',
'aura': 'bower_components/aura/dist/',
'jquery': 'bower_components/jquery/jquery',
'backbone': ...,
... lots of other paths
}
});
define(['core', 'jquery', 'jqueryui'], function(core, $) {
// Here we start Aura, which finds our extensions and widgets in
// bower_components
});
我们目前requirejs任务配置:
requirejs: {
compile: {
options: {
mainConfigFile: 'app/main.js',
name: 'main',
include: ['bower_components/widget1/main', 'bower_components/widget2/main',
'bower_components/extension1/main', 'bower_components/extension2/main'],
exclude: ['jquery'],
insertRequire: ['main'],
out: 'dist/app.js'
}
}
}
这个连接我们的app/main及其依赖关系,但是当我们尝试运行它时,我们得到的错误如下:
GET404(Not Found) 尽管下划线是我们包含的许多小部件的依赖关系。
我们已经在the r.js examples中广泛尝试了不同的选项,并通读了许多试图找到答案的叠层流问题。
我们希望有关如何使用这种结构建设成为一个缩小的文件,这样的建议:
更新#2:正确的文件结构
- dist/
|_ index.html // copied using grunt copy
|_ css // copied using grunt copy
|_ app.js // Built with grunt requirejs
UPDATE
我们已经在我们的垫片包括underscore
其中修正了上述错误,但我们仍然收到另一个错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
http://my-machine.com:8080/bower_components/core/app/main.js
这包括在最小化的文件,所以我不明白为什么它无法找到该文件:
define("bower_components/core/app/main.js", ["aura/aura", "bootstrap"], function(){
...
});
更新#3
的定义从上面通过优化工具生成的文件来!最初定义该模块,core/app/main.js
,看起来像:
define(['aura', 'bootstrap'], function(Aura) {
...
});
你有没有在垫片中加下划线? – Evgeniy
可以请你更新你的代码结构的描述和共享构建的文件 – Evgeniy
顺便说一句,我已经使用了一个技巧来澄清与路径 - 构建后,我已经在页面require.config({baseUrl:'/路径/到/ scripts'})。无论如何,为了帮助你,我需要你分享建立的文件+完整的文件结构。 – Evgeniy