Use jspm to load script that depends on global jQuery

Yes I've read How do I shim a non CommonJS, non AMD package which depends on global jQuery & lodash?.

I'm trying to load X.js, through jspm, which is not a 'package' but an old js file I have no control over that needs a global jQuery object and needs to run like it is in a script tag.

I'm using System.import('app/X'); to load it.

I tried various shim / globals tricks to make it load but I can't quite figure it out.

How would one write the config.js to be able to import that X file so that it sees a global jQuery object? Do I have to make X a 'package' and install it to be able to shim it better?

Thanks.

Answers


If you installed jquery through jspm, all you need is to set the meta 'deps' property like this:

System.config({
  meta: {
    'app/X': {
       deps: ['jquery']
    }
  }
});

System.import('app/X');

Be sure to get the X path correctly and check how jspm sets up System.config 'paths' and 'map', by default trailing .js is added automatically (with paths *.js wildcard) so you must not add it.

Maybe try to look at these links from the documentation as well https://github.com/systemjs/systemjs/blob/master/docs/module-formats.md#globals https://github.com/systemjs/systemjs/blob/master/docs/config-api.md#meta


If providing the meta 'deps' property like the following (as suggested by Mathias Rasmussen) doesn't do the trick,

System.config({
  meta: {
    'app/X': {
       deps: ['jquery']
    }
  }
});

then you may have to provide a 'globals' meta property like the following:

System.config({
  meta: {
    'app/X': {
       globals: {
           'jquery': 'jquery' 
       }
    }
  }
});

In order for the above to work you will have needed to install jquery via jspm. Doing the above should also allow you to import the plugin by doing System.import('app/X'); or import 'app/X'; without having to import jquery as well. Importing the plugin alone should also bring in jquery as a dependency.


Need Your Help

What is the equivalent T-SQL select query for the attached linq query?

c# sql sql-server linq

I am facing some trouble writing where condition in the SQL select statement match the above criteria. Any advice?

winforms - datagridview row height doesn't resize when defaultcellstyle is set to wrapmode

winforms datagridview

i have a datagrid that displays long text on couple columns. I have set the cells defaultcellstyle to wrap. This works but now the row height doesn't change to compensate for the wrapped text &...