How can I get around the non-CommonJS package, not AMD, which depends on global jQuery & lodash?

I am using jspm for the first time and have already encountered a problem.

I need to figure out how to β€œpin” a proprietary script that lives in our company's npm private registry.

Package: widget

  • Stored in npm private registry
  • not CommonJS module, UMD / AMD
  • Depends on lodashand jquery, but assumes that they exist in a global area
  • Opens widgetin a global area

Here is a (hypothetical) code

var Widget = {
  render: function(el, symbol) {
    symbol = _.trim(symbol);
    $(el).text(symbol);
  }
};

app.js

var widget = require("Widget");
widget.render(document.getElementById("name"), " Fred ");

index.html

<body>
  <div id="name"></div>

  <script src="jspm_packages/system.js"></script>
  <script src="config.js"></script>
  <script>
    System.import("app");
  </script>
</body>

When I run this page on a local web server, I get an error message:

Not prepared Link: _ not defined

How can I provide a "gasket" for widget?

+4
1

, package.json Widget, JSPM, :

{
  "shim": {
    "widget": { "deps": ["jquery", "lodash"] }
  }
}

( "" - .)

- npm, jspm:

jspm install widget -o "{ shim: { 'widget': { deps: ['jquery', 'lodash'] } } }"

( , "" - , .)

0

All Articles