monavari-lebrecht
monavari-lebrecht

Reputation: 920

How can I manage non-AMD dependencies with Require JS?

I try to manage a library with no AMD-Support that depends on 3 other JS-files (https://github.com/augustl/js-epub).

I have to include the files in the following order:

<script type="text/javascript" src="zip/jszip.js"></script>
<script type="text/javascript" src="zip/jszip-load.js"></script>
<script type="text/javascript" src="zip/jszip-deflate.js"></script>
<script type="text/javascript" src="zip/jszip-inflate.js"></script>

at the moment I try to handle the dependencies via shim like that:

shim {

      "zip/jszip": {
        "deps": ["zip/jszip-deflate", "zip/jszip-inflate", "zip/jszip-load"],
        "exports": "JSZip"
      }
}

But the scripts are included in the wrong order. How can I manage that?

Best regards, hijolan

Upvotes: 2

Views: 827

Answers (1)

jevakallio
jevakallio

Reputation: 35970

The deps dependencies array defines scripts which need to load before the shimmed script. Your shim declaration it's the wrong way around: you need to shim the modules which depend on jszip and list jszip as their dependency.

shim: {
  "zip/jszip": {
    "deps": [],
    "exports": "JSZip"
  },
  "zip/jszip-load": {
    "deps": ["zip/jszip"],
    "exports": "JSZip"
  },
  "zip/deflate": {
    "deps": ["zip/jszip"],
    "exports": "JSZip"
  },
  "zip/inflate": {
    "deps": ["zip/jszip"],
    "exports": "JSZip"
  }

Upvotes: 3

Related Questions