0

I have written a typescript library (mathquill-typescript) that requires Jquery. I use jquery as a node_module. So my mathquill-typescript library starts like this:

import * as $ from 'jquery'

export namespace MathQuillLoader {
  ...

Now when I (or someone else) want to use this library, for example with SystemJS, I still need to specify details about jquery:

System.config({
baseURL: './'
,
map: {
  'jquery': 'node_modules/jquery/dist/jquery.js',
  'mathquill-typescript': 'node_modules/mathquill-typescript/dist/index.js'        
}
});

Is there a way, that jquery is just an implementation detail and the user of mathquill-typescript doesn't need to know about it? At the same time I wouldn't want to inline jquery, since I want jquery to be only loaded once by the browser.

bersling
  • 11,990
  • 5
  • 41
  • 51
  • 3
    You don't... you define npm packages and declare dependencies --pretty much all the package managers can deal with npm packages-- and as for System.js configs, they can be auto generated via JSPM. Consumers of your package don't need to deal with the dependencies directly because npm/JSPM/webpack will deal with it for you. – Meirion Hughes Jun 25 '17 at 18:37
  • the problem is, it didn't work for me. I tried to include `mathquill-typescript` into an Angular2 project (which uses webpack). It was weird, as somehow jquery was loaded (the `.getScript` was working) but somehow it wasn't loaded (mathquill threw an error, which it didn't throw when I included jquery in the `` of the html) – bersling Jun 25 '17 at 19:00
  • sound like you're potentially using the global in your package; see #2 here https://stackoverflow.com/a/28989476/1657476 – Meirion Hughes Jun 25 '17 at 19:14
  • If you wanna share your lib with npm|yarn, you can add jquery as peerDependency – ArtemSky Jun 25 '17 at 19:22
  • @MeirionHughes That actually sounds a lot like the issue! Now the problem is that AngularCli hides the webpack conifg. So should I just add to the `readme` of my library "please include jquery in a way such that it's globally available, for example in the `head` or in the `.angular-cli.json`'s scripts (see https://stackoverflow.com/a/39661714/3022127)"? And then I also should make it a peerDependency, so it's not loaded twice, right? – bersling Jun 25 '17 at 20:09

0 Answers0