Loading min.js files Generated by TypeScript with Require

前端 未结 3 1443
余生分开走
余生分开走 2020-12-19 10:40

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. We

3条回答
  •  盖世英雄少女心
    2020-12-19 11:42

    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;
    

提交回复
热议问题