Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to declare dependencies inside an amd compatability check without creating 404/mismatched anonymous module during builds?
    text
    copied!<p>I'm struggling to add a plugin using the following AMD compatability setup to my application: </p> <p>The snippet from <strong>foo.js</strong> in question:</p> <pre><code>(function (dependencies, module) { "use strict"; if (typeof define === 'function' &amp;&amp; define.amd) { return define(dependencies, module); } if (typeof exports === 'object') { return module(exports); } window.foo = {}; module(window.foo, {hex_sha256: hex_sha256}); }(['exports', 'sha256'], function (exports, sha256) { // foo })); </code></pre> <p>I'm setting <strong>foo</strong> as a dependency in another module called <strong>bar</strong> like so:</p> <pre><code>define(["jquery", "foo", "sha256", "c", "d"], function() { // stuff }); </code></pre> <p>And inside the r.js optimizer I define <code>bar</code> to be:</p> <pre><code> { name: "bar" , include: ["foo", "sha256", "c", "d"] , exclude: ["jquery"] }, </code></pre> <p>This generates the <code>bar.js</code> file allright including the abovementioned files.</p> <p>However when I load my built application, there are still two requests being triggered to <code>foo.js</code> and <code>sha256.js</code>, which both <code>404</code> (optimizer cleans up built files) and who are inside my <code>bar.js</code> build layer.</p> <p><strong>Question:</strong><br> I'm a little lost with the module amd check and am suspecting it being responsible for the unwanted call. Can anyone shed some light on what I should modify in the AMD check to make <code>foo</code> callable form inside a build layer?</p> <p>Thanks!</p> <p><strong>EDIT:</strong><br> I tried <code>shimming</code> like so:</p> <pre><code>shim: { 'foo': { deps: ['sha256'] } }, </code></pre> <p>which takes care of the 404, but returns an: </p> <pre><code>Mismatched anonymous define() module: function (exports, sha256) {.... </code></pre> <p>error, so I'm still stuck assuming the hardcoded dependency to <code>sha256</code> in my AMD check to be the culprit. Maybe this helps.</p> <p><strong>EDIT</strong>:<br> I'm pretty sure my problems stem from the dependency declaration inside the AMD compatability check.</p>
 

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