2013-07-03 18 views
9

Ecco (parte della) mia struttura di cartelle:Evitare la duplicazione della configurazione "percorsi" nel file principale RequireJS e nel file di costruzione r.js?

  • nodo-test
    • bower_components
    • accumulo
    • pubblici
      • main.js
    • build.js

Esecuzione del ottimizzatore con r.js -o build.js e la seguente configurazione funziona bene:

// 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 
}) 

Tuttavia, se tolgo configurazione paths in build.js non funziona più:

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 'Mi piacerebbe essere ASCIUTTO, evitando di aggiungere una dipendenza due volte. È possibile?

risposta

15

Se si desidera utilizzare la stessa configurazione dal codice runtime per trovare la posizione delle librerie, è possibile utilizzare l'opzione 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.

Qualcosa di simile a questo:

({ 
    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

Perfect !! ! Grazie mille! – gremo

Problemi correlati