在 Playframework 2.1 - Asycronous Module Definition (AMD) 被引入并支持 Require.js
然而,除了概述之外,还缺少官方 Play 文档: http ://www.playframework.com/documentation/2.1.0/RequireJS-support
我正在寻找一个关于使用 Require.js 支持 Bootstrap 主题的最佳实践的教程
bootstrap、jquery 的代码库跨越多个文件:
jquery.js
jquery.dataTable.js
jquery-ui.custom.js
...
bootstrap.js
bootstrap.colorpicker.js
bootstrap.tooltip.js
...
Over 30 of these Bootstrap themed files needs to be managed.
在app/assets/js
中,我有:
requirejs.config({
baseUrl: "assets/javascripts/lib",
paths: {
"jquery": ["http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min",
//If the CDN location fails, load from this location
'jquery-1.10.1.min'
],
"bootstrap" : ['bootstrap.min'],
},
shim : {
"bootstrap" : ['jquery'],
"jquery.dataTables" : ['jquery'],
"jquery-ui.custom" : ['jquery'],
'jquery.uniform' : ['jquery'],
'excanvas' : ['jquery'],
'jquery.flot.min' : ['jquery'],
'jquery.flot.resize.min' : ['jquery'],
'jquery.peity.min' : ['jquery'],
'select2' : ['jquery'],
'unicorn' : ['jquery', 'bootstrap'],
'unicorn.dashboard' : ['jquery', 'bootstrap'],
'unicorn.tables' : ['jquery', 'bootstrap']
}
});
在project/Build.scala
中,requireJs 被附加到 main:
val main = play.Project(appName, appVersion, appDependencies).settings(
requireJs += "main.js",
requireJsShim += "main.js",
requireJsFolder := "js"
)
在我的模板中,app/views/main.scala.html
调用了助手:
@helper.requireJs(core = routes.Assets.at("javascripts/require.js").url, module = routes.Assets.at("js/main").url)
我有许多从 main.scala.html 路由的模板页面,现在每个页面都会调用一次帮助程序。因此我遇到了baseUrl错误:
GET http://localhost:9000/admin/assets/javascripts/lib/bootstrap.min.js 404 (Not Found) require.js:33
GET http://localhost:9000/admin/assets/javascripts/lib/jquery.dataTables.js 404 (Not Found) require.js:33
GET http://localhost:9000/admin/assets/javascripts/lib/jquery.uniform.js 404 (Not Found) require.js:33
GET http://localhost:9000/admin/assets/javascripts/lib/jquery-ui.custom.js 404 (Not Found) require.js:33
GET http://localhost:9000/admin/assets/javascripts/lib/select2.js 404 (Not Found) require.js:33
GET http://localhost:9000/admin/assets/javascripts/lib/excanvas.js 404 (Not Found)
是否有将 PlayFramework 中的 Boostrap 与 Require.js 安全集成的最佳实践?