Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading min.js files Generated by TypeScript with Require

I have a full aplication working with Typescript and RequireJs, it is working perfectly. I have now download WebEssentials and it is generating the minified script files. WebEssentials generates separated *.min.js files with the same name as the original script file.

How can I tell RequireJs to load my minified files instead of my original script files ?

Thanks in advance

like image 788
mvbaffa Avatar asked Jan 14 '13 17:01

mvbaffa


2 Answers

You can use path config to override module paths. You can even fall back to non minified files:

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

There may be a more general way to use min files that I don't know about!

like image 163
Fenton Avatar answered Oct 12 '22 15:10

Fenton


You can create a simple customized version of require which will conditionally append '.min.js' to all module file requests that would normally just receive the '.js' appendage. Consider the following:

    //Establish a new 'useMinified' boolean in your initial config.
    require.config({ useMinified: true });

Then, edit the require.js library file and modify the 'nameToUrl' function as below:

    //Join the path parts together, then figure out if baseUrl is needed.
url = syms.join('/');

    //new statement
var extension = config.useMinified ? '.min.js' : '.js';

    //customized statement
url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : extension));

url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
like image 20
neuroplexus Avatar answered Oct 12 '22 16:10

neuroplexus