Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://requirejs.org/docs/optimization.html" rel="nofollow">That approach could cause problems for the build tool.</a></p> <h3>Update:</h3> <p>After further research, I find that <a href="http://requirejs.org/docs/optimization.html#mainConfigFile" rel="nofollow">config settings in your main JS file are not read by default by the optimizer.</a> So, a cleaner solution would be to use a different <a href="http://requirejs.org/docs/api.html#config-map" rel="nofollow">map config</a> for client and server.</p> <h3>Original:</h3> <p>A safer approach may be to define a module that adapts itself to the environment, thus keeping all the conditional code within your module definitions, and leaving all dependency lists in the most reliable format.</p> <pre><code>// dependent module define(["libraryAB"], function (library) { //do some stuff }); // libraryAB.js dependency module define([], function () { return window ? defineLibraryA() : defineLibraryB(); }); </code></pre> <p>You could alternatively keep the <code>libraryA</code> and <code>libraryB</code> code separate by defining <code>libraryAB</code> this way.</p> <pre><code>// libraryAB.js dependency module define(["libraryA", "libraryB"], function (libraryA, libraryB) { return window ? libraryA : libraryB; }); //define libraryA.js and libraryB.js as usual </code></pre> <p>If you want to avoid executing <code>libraryA</code> on the server or <code>libraryB</code> on the client, you could have these modules return functions and memoize the result if necessary.</p> <p>The moral is that it's safest to keep all your non-standard code inside module definitions, keeping dependency lists nice and predictable.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload