How do you setup a require.js config with typescript?

后端 未结 3 517
别那么骄傲
别那么骄傲 2020-12-16 11:16

Ok, I\'ve been reading a lot of questions and answers about this, and a lot of it is rubbish.

I have a very simple question. How do I do the equivalent of this:

3条回答
  •  Happy的楠姐
    2020-12-16 11:43

    Yesterday I wrote up a solution to this exact issue on my blog - http://edcourtenay.co.uk/musings-of-an-idiot/2014/11/26/typescript-requirejs-and-jquery:

    TL;DR - create a config file config.ts that looks something like:

    requirejs.config({
        paths: {
            "jquery": "Scripts/jquery-2.1.1"
        }
    });
    
    require(["app"]);
    

    and ensure your RequireJS entry point points to the new config file:

    
    

    You can now use the $ namespace from within your TypeScript files by simply using

    import $ = require("jquery")
    

    Hope this helps

提交回复
热议问题