codewithmichael / babel-browser-harness

In-browser CDN-based ES6+ transpiling via Babel
MIT License
1 stars 0 forks source link

Add "depends" field to modules config #1

Open codewithmichael opened 8 years ago

codewithmichael commented 8 years ago

Currently the modules config accepts either Object or Array syntax—the latter being required when load order is important.

A simpler system is to use a "depends" field to note when one lib requires another.

The obvious advantages are a unified syntax (Object-only) and explicit requirement designation ("B depends on A").

Example:

bbh.modules = {
  react: {
    exports: "React",
    src: "https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"
  },
  "react-dom": {
    exports: "ReactDOM",
    src: "https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js",
    depends: "react"
  },
};

There's no specific necessity to deprecate the array syntax, as a "depends" system necessitates conversion to an Array (or similar construct) for ordered processing.

Circular Dependencies:

In case of circular dependency, it's natural to assume no guaranteed load order.

codewithmichael commented 8 years ago

I recently published dependency-sorter, which handles pretty much everything this issue needs. I'm fine with importing a minified copy (or portion) of it here with attribution.

The weight system might be overkill, though. It would probably suffice to pull the method that performs the initial topological sort.

Aside: To address concerns in issue #2 without a weight system, we could just cherry-pick the libs from DEFAULT_MODULES after the topological sort and append them to the end of the list—specifically RequireJS.

codewithmichael commented 8 years ago

I copied in a minified version of dependency-sorter and have this working on branch issue1-and-issue2 (it will resolve both this issue and issue #2).

Still requires README documentation.

codewithmichael commented 8 years ago

Due to the documentation rewrite (issue #25), there will be no documentation pass.

In review - PR #26.