2013-07-03 3 views
9

は私のフォルダ構造(の一部)である:RequireJSメインファイルとr.jsビルドファイルに "paths"設定が重複しないようにしますか?ここ

  • ノード・テスト
    • bower_components
    • ビルド
    • 公共
      • main.js
    • build.js

r.js -o build.jsでオプティマイザを実行すると、以下の設定が正常に動作します:

// main.js file 
requirejs.config({ 
    baseUrl: '../bower_components', 
    paths: { 
     'domready': 'domready/ready', 
     'jquery': 'jquery/jquery', 
    } 
}); 

requirejs(['domready', 'jquery'], function (domReady, $) { 
    domReady(function() { 

    }); 
}); 

// build.js file 
({ 
    baseUrl: "bower_components", 
    name: "./almond/almond", 
    include: "./../public/main", 
    out: "build/main.js", 
    paths: { 
     'domready': 'domready/ready', 
     'jquery': 'jquery/jquery', 
    }, 
    preserveLicenseComments: false 
}) 

私はbuild.jspathsコンフィギュレーションを削除した場合しかし、それはもう動作しません:

Tracing dependencies for: ./almond/almond Error: ENOENT, no such file or directory 'C:\Users\Marco\Documents\Progetti\nodejs-opt\bower_components\domready.js' In module tree: ../public/main

Error: Error: ENOENT, no such file or directory 'C:\Users\Marco\Documents\Progetti\nodejs-opt\bower_components\domready.js' In module tree: ../public/main

at Object.fs.openSync (fs.js:427:18) 

I DRYのようになり、依存関係を2回追加するのを避けます。これは可能ですか?

答えて

15

、あなたのライブラリの場所を見つけるためにあなたのランタイムコードから同じ設定を使用する場合は、mainConfigFileオプションを使用することができます。このような

...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.

は何か:

({ 
    baseUrl: "bower_components", 
    mainConfigFile: '/some/path/main.js', // adjust path as needed 
    name: "./almond/almond", 
    include: "./../public/main", 
    out: "build/main.js", 
    preserveLicenseComments: false 
}) 
+0

パーフェクト! !どうもありがとうございます! – gremo

関連する問題