/*@flow*/
/*:: const define = () => {}; */
define([
    '/api/config',
    '/bower_components/less/dist/less.min.js'
], function (Config, Less) { /*::});module.exports = (function() {
    const Config = (undefined:any);
    const Less = (undefined:any);
    */

    var module = { exports: {} };
    var key = Config.requireConf.urlArgs;
    var localStorage;
    try {
        localStorage = window.localStorage || {};
    } catch (e) {
        console.error(e);
        localStorage = {};
    }

    var fixURL = function (url) {
        var mark = (url.indexOf('?') !== -1) ? '&' : '?';
        return url + mark + key;
    };

    var doXHR = Less.FileManager.prototype.doXHR;
    Less.FileManager.prototype.doXHR = function (url, type, callback, errback) {
        url = fixURL(url);
        //console.log("xhr: " + url);
        return doXHR(url, type, callback, errback);
    };

    var inject = function (cssText, url) {
        var curStyle = document.createElement('style');
        curStyle.setAttribute('data-original-src', url);
        curStyle.type = 'text/css';
        curStyle.appendChild(document.createTextNode(cssText));
        if (!document.head) { throw new Error(); }
        document.head.appendChild(curStyle);
    };

    var checkCache = function () {
        if (localStorage['LESS_CACHE'] === key) { return; }
        Object.keys(localStorage).forEach(function (k) {
            if (k.indexOf('LESS_CACHE|') !== 0) { return; }
            delete localStorage[k];
        });
        localStorage['LESS_CACHE'] = key;
    };

    module.exports.load = function (url /*:string*/, cb /*:()=>void*/) {
        checkCache();
        if (localStorage['LESS_CACHE|' + key + '|' + url]) {
            inject(localStorage['LESS_CACHE|' + key + '|' + url], url);
            cb();
            return;
        }
        Less.render('@import (multiple) "' + url + '";', {}, function(err, css) {
            if (err) {
                console.log(err);
                return;
            }
            localStorage['LESS_CACHE|' + key + '|' + url] = css.css;
            inject(css.css, url);
            cb();
        }, window.less);
    };

    return module.exports;
})/*::()*/;

@@ -521,24 +521,137 @@
 ion (url) %7B%0A
+        // data: blob: etc%0A        if (!/%5E(%5C/%7Chttp)/.test(url)) %7B return url; %7D%0A        var ua = url.split('#');%0A
         var 
@@ -659,18 +659,20 @@
 ark = (u
-rl
+a%5B0%5D
 .indexOf
@@ -706,26 +706,29 @@
         
-return url
+ua%5B0%5D = ua%5B0%5D
  + mark 
@@ -730,24 +730,120 @@
 mark + key;%0A
+        var out = ua.join('#');%0A        console.log(url + %22  --%3E  %22 + out);%0A        return out;%0A
     %7D;%0A%0A    
@@ -1760,24 +1760,721 @@
 ey;%0A    %7D;%0A%0A
+    var fixAllURLs = function (source) %7B%0A        var urlRegEx = /@import%5Cs*(%22(%5B%5E%22%5D*)%22%7C'(%5B%5E'%5D*)')%7Curl%5Cs*%5C(%5Cs*(%5Cs*%22(%5B%5E%22%5D*)%22%7C'(%5B%5E'%5D*)'%7C%5B%5E%5C)%5D*%5Cs*)%5Cs*%5C)/ig;%0A        var result, url;%0A%0A        while (!!(result = urlRegEx.exec(source))) %7B%0A            url = result%5B3%5D %7C%7C result%5B2%5D %7C%7C result%5B5%5D %7C%7C result%5B6%5D %7C%7C result%5B4%5D;%0A            var newUrl = fixURL(url);%0A            var quoteLen = result%5B5%5D %7C%7C result%5B6%5D ? 1 : 0;%0A            source = source.substr(0, urlRegEx.lastIndex - url.length - quoteLen - 1)%0A               + newUrl + source.substr(urlRegEx.lastIndex - quoteLen - 1);%0A            urlRegEx.lastIndex = urlRegEx.lastIndex + (newUrl.length - url.length);%0A        %7D%0A%0A        return source;%0A    %7D;%0A%0A
     module.e
@@ -2906,32 +2906,184 @@
 ;%0A            %7D%0A
+            var output = fixAllURLs(css.css);%0A            window.lc = window.lc %7C%7C %7B%7D;%0A            window.lc%5B'LESS_CACHE%7C' + key + '%7C' + url%5D = output;%0A
             loca
@@ -3126,23 +3126,22 @@
  url%5D = 
-css.css
+output
 ;%0A      
@@ -3153,23 +3153,22 @@
  inject(
-css.css
+output
 , url);%0A

Make less loader rewrite urls to use version parameter