While writing a Typescripts application where I am using RequireJS for loading the modules (I use Visual Studio 2015).
I can easily load almost all of the modules either from .ts classes I wrote myself for from external libraries using their typing .d.ts files.
But my problem begins where I want to load a plugin for jquery.
I am using the typing file for the library but logically there is no module definitions in the .d.ts file because it's just a plugin for jquery.
I have followed the recommendations for shim library loading from RequireJS website like this:
requirejs.config({
baseUrl: "Scripts",
paths: {
"jquery": "jquery-2.2.3",
"jquery.pjax": "jquery.pjax"
},
shim:
{
"jquery.pjax":
{
deps: ["jquery"],
exports: "jQuery.fn.pjax"
}
}
});
require(["app"]);
And according to the RequireJS website:
The shim config only sets up code relationships. To load modules that are part of or use shim config, a normal require/define call is needed. Setting shim by itself does not trigger code to load.
Now, neither of the following work for loading the plugin (even after moving the jquery.pjax.d.t next to the jquery.pjax.js):
import * as pjax from "jquery.pjax";
import pjax = require("jquery.pjax");
import pjax = require("./jquery.pjax");
import pjax = require("jquery.pjax.js");
import pjax = require("./jquery.pjax.js");
Compiler complains with the error Cannot find module "jquery.pjax"
or File C:/foo/bar/jquery.pjax.d.ts is not a module
.
The app.ts does not get compiled as long as any of the codes above exists and when I remove them, the plugin does not get loaded.
Regarding that I am using several imports in my app.ts file and there will be more, I prefer to use import Foo = require("foo")
or import * as Foo from "foo"
module loading style in opposition to writing the AMD define function manually.
Also I am using Nuget package management and I prefer not to edit/move external .d.ts or .js files manually.
Can anyone help me figure this out please?