I am using jspm for the first time and already ran into a snag.
I need to figure out how to "shim" a proprietary script which lives on our company's private npm registry.
Package: widget
- Resides on private npm registry
- Is not a CommonJS, UMD/AMD module
- Depends on
lodash
andjquery
, but assumes they exist on global scope - Exposes
Widget
on the global scope
Here's the (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 in a local web server, I get an error:
Uncaught Reference: _ is not defined
How can I provide a "shim" for widget
?
Your best bet is that if you can update the package.json for the Widget package you can tell JSPM it needs a shim there:
(Where "widget" is the module name inside the package.)
If for some reason you can't directly touch that npm package, then you can override the shim information when you jspm install it:
(Again, where 'widget' is the module name, as local to inside the package itself.)