PlayFramework:如何安全地将Bootstrap主题与Require.js集成

时间:2013-06-17 23:56:14

标签: twitter-bootstrap requirejs playframework-2.1

在Playframework 2.1中 - 引入了Asycronous模块定义(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安全地集成?

1 个答案:

答案 0 :(得分:0)

截至2013年5月1日 - 在Play Framework团队工作的Christopher Hunt正在更好地整合Javascript: http://christopherhunt-software.blogspot.com/

另请查看WebJARS - http://www.webjars.org/