Andy
Andy

Reputation: 5414

Typescript import module to import minify version of js

When using Typescript (v0.8.3), with Visual Studio + Web Essentials, I have configure Web Essentials to use the AMD module compiler flag, and also have it to minify the generated JS.

enter image description here

In my AppMain.ts I imported a module using the import keyword

/// <reference path="./../modules/jquery.d.ts" />
import main = module('classes/facebook');

export class AppMain {
    public run() {
        $(()=>{
            var app = new facebook.App();
            app.start();
        });
    }
}

And the generated JS looks like the following

define(["require", "exports", 'classes/facebook'], function(require, exports, __main__) {
    var main = __main__;

    var AppMain = (function () {
        function AppMain() { }
        AppMain.prototype.run = function () {
            $(function () {
                var app = new facebook.App();
                app.start();
            });
        };
        return AppMain;
    })();
    exports.AppMain = AppMain;    
})

My question is, how do I get the generated requirejs code to load the *.min instead? Since Web Essentials already generated the minify version of the JS file.

E.g. What of what I want from the generated JS file:

define(["require", "exports", 'classes/facebook.min'], function(require, exports, __main__)

Edit: I've lots of modules, so I'd prefer a way that gives me less headache.

Upvotes: 1

Views: 2958

Answers (2)

Fenton
Fenton

Reputation: 250922

You need to add some RequireJS config to ask it to substitute the minified version of the library:

requirejs.config({
    enforceDefine: true,
    paths: {
        facebook: [
            'lib/facebook.min',
            'lib/facebook'
        ]
    }
});

Upvotes: 1

basarat
basarat

Reputation: 275857

I'd recommend that you do not use these min files and use r.js for merging followed by a separate minification pipeline when you are using RequireJS to begin with.

It will save you headaches with debugging your app as well since you can easily debug the non minified js.

Upvotes: 2

Related Questions