13

私はrequirejsオプティマイザーに苦労しています。このコードは、最適化せずにブラウザにロードするだけで機能します。オプティマイザーを実行すると、

: ENOENT, no such file or directory 'C:\Users\dev\checkout\src\main\webapp\resources\scripts\
json2.js'

In module tree: main

これはコードです

requirejs.config({
paths : {
    jquery : "lib/jquery",
    bootstrap : "lib/bootstrap",
    modals : "lib/modals",
    tablesort : "lib/tablesort",
    json2 : "lib/json2"
},

shim : {
    "bootstrap" : [ "jquery" ],
    "modals" : [ "jquery" ],
    "tablesort" : [ "jquery" ],
    "json2" : [ "jquery" ]
}
});

require([ "jquery", "json2","bootstrap", "modals", "tablesort", "registermodule",    "personsmodule" ], function($) {

オプティマイザーを機能させるには何をする必要がありますか?lib/json2をrequireに入れてみました。次に、AMD以外のモジュールであるため、jQueryの問題が発生します。

編集:まだこれに苦労しています。最も単純な例を試してみました。ブラウザでは正常に動作しますが、オプティマイザはファイルが見つからないと文句を言います。lib/jquery.jsおよびlib/modal.js。

requirejs.config({
paths : {
    jquery : "lib/jquery",
    modals : "lib/modals"
},

shim : {
    "bootstrap" : [ "jquery" ],
    "modals" : [ "jquery" ]
}
});

require([ "jquery", "modals" ], function($) {

console.log($("#leverandor_span").text());
$("#register_modal").modal("show");

});
4

2 に答える 2

24

を参照してくださいmainConfigFile。これが導入されたため、必要な構成をランタイム/最適化時間ファイルにコピーする必要がなく、ビルドをドライに保つことができます。

//By default all the configuration for optimization happens from the command
//line or by properties in the config file, and configuration that was
//passed to requirejs as part of the app's runtime "main" JS file is *not*
//considered. However, if you prefer the "main" JS file configuration
//to be read for the build so that you do not have to duplicate the values
//in a separate configuration, set this property to the location of that
//main JS file. The first requirejs({}), require({}), requirejs.config({}),
//or require.config({}) call found in that file will be used.
mainConfigFile: '../some/path/to/main.js',
于 2013-01-24T05:55:04.210 に答える
20

問題:require.config()がr.jsによって解析されません。その構成は実行時のみです。r.jsの場合、パスなどを構成するために別のファイルを作成する必要があります。

ファイル(app.build.jsなど)を作成し、パスを構成します

({
   appDir: "../",
   baseUrl: "./",
   dir: "dist",
   modules: [
        {
            name: "bootloader"
        }
    ],
    paths: {
       // libraries path
      "json": "lib/json2",
      "jquery": "lib/jquery",
      "underscore": "lib/underscore",
      "bootstrap": "lib/bootstrap",
      "backbone": "lib/backbone",
      "hogan": "lib/hogan",

       // require plugins
      "css": "lib/css",
      "hgn": "lib/hgn",
      "text": "lib/text"
   }
})

オプティマイザーを実行します。

$ r.js -o app.build.js

詳細はこちら: http: //japhr.blogspot.it/2011/12/optimizing-requirejs-part-2.html

ビルドファイルオプション: http: //requirejs.org/docs/optimization.html#wholeproject

于 2012-07-12T14:45:26.883 に答える