Domanda

I`o usando R.JS per ottimizzare la mia app, Come ho visto in diversi campioni, ho usato Build.json Configuration File per configurare le mie opzioni di ottimizzazione.

Il problema è che quando ho impostato il riferimento al file JavaScript di output dopo l'ottimizzazione, sto ottenendo il seguente errore nel browser:

.

Uncaught ReferenceError: Definisci non è definito Main-Built-Built.js: 14735

Sembra che tutti i miei moduli delle app siano mancanti ma mancano RequireJS.

Questo è il mio file di configurazione Build build.json:

{
  "baseUrl": "../", 
  "name": "src/modules/main",
  "include": ["src/modules/main", "src/modules/navbar/navbar", "src/modules/contact/contact", "src/modules/about/about"], 
  "exclude": [], "optimize": "none", "out": "main-built.js", 
  "insertRequire": ["src/modules/main"]
}
.

Come aggiungo RequireJS al file JS di output?Forse ho bisogno di aggiungere qualcos'altro da config?O forse il problema non è la configurazione?

Grazie, Ori

È stato utile?

Soluzione

Prova:

<script src="scripts/require.js" data-main="scripts/main-built"></script>
.

Altri suggerimenti

Se ho capito correttamente, questo è il modo in cui dovrebbe funzionare.

Che cosa fa R.JS è che compila tutti i moduli Resapjs in un singolo file.Tuttavia è comunque necessario caricare quel file con lo script Richiesta, ad esempio:

<script data-main="scripts/main" src="scripts/require.js"></script>
.

Quindi aggiungi una versione minificata di RICORD.JS al tuo sito Web e caricare il modulo ottimizzato usando quello.

Devi includere require.js se è stato modularizzato il tuo progetto utilizzando RequireJS:

<script data-main="scripts/main" src="scripts/require.js"></script>
.

Questo perché RejanyJs gestisce il caricamento dei moduli e la risoluzione delle dipendenze.Senza di esso, il tuo browser non sa cosa significa define.Un modo per aggirare questo è usare UMD (definizione del modulo universale).Questo lo rende in modo che il tuo modulo possa essere utilizzato con o senza requirejs.Puoi vedere molti esempi qui .Uno che si adatta al tuo caso è:

// Uses AMD or browser globals to create a module.

// If you want something that will also work in Node, see returnExports.js
// If you want to support other stricter CommonJS environments,
// or if you need to create a circular dependency, see commonJsStrict.js

// Defines a module "amdWeb" that depends another module called "b".
// Note that the name of the module is implied by the file name. It is best
// if the file name and the exported global have matching names.

// If the 'b' module also uses this type of boilerplate, then
// in the browser, it will create a global .b that is used below.

// If you do not want to support the browser global path, then you
// can remove the `root` use and the passing `this` as the first arg to
// the top function.

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // AMD. Register as an anonymous module.
        define(['b'], factory);
    } else {
        // Browser globals
        root.amdWeb = factory(root.b);
    }
}(this, function (b) {
    //use b in some fashion.

    // Just return a value to define the module export.
    // This example returns an object, but the module
    // can return a function as the exported value.
    return {};
}));
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top