var loaderUtils = require("loader-utils");

module.exports = function(source, map) {
    var query = loaderUtils.parseQuery(this.query);

    if (!query.uniquePrefix) {
        this.emitError("Missing loader parameter uniquePrefix");
        return;
    }

    this.cacheable();

    var r = query.uniquePrefix;
    if (r) r += '-';

    source = source.replace(/kwfUp-/g, r);

    if (source.match(/kwfLocal/)) {
        var p = this.resourcePath;
        p = p.replace(process.cwd()+'/', '');

        p = p.replace(/^commonjs\/views\//, '');
        p = p.replace(/^reactjs\/(components|layouts)\//, '');
        p = p.replace(/^components\/(.*?)\/backbone\/views\//, '');
        p = p.replace(/^components\/(.*?)\/reactjs\/(components|layouts)\//, '');
        p = p.replace(/\.underscore\.tpl$/, '');
        p = p.replace(/\.[a-z]+$/, '');
        p = p.replace(/\/(.)/g, m => {
            return m.toUpperCase();
        });
        p = p.replace(/\//g, '');

        p = r + p;
        source = source.replace(/kwfLocal/g, p);

    }

    return source;
};

var loaderUtils = require("loader-utils");

module.exports = function(source, map) {
    var query = loaderUtils.parseQuery(this.query);

    if (!query.uniquePrefix) {
        this.emitError("Missing loader parameter uniquePrefix");
        return;
    }

    this.cacheable();

    var r = query.uniquePrefix;
    if (r) r += '-';

    source = source.replace(/kwfUp-/g, r);

    if (source.match(/kwfLocal/)) {
        var p = this.resourcePath;
        p = p.replace(process.cwd()+'/', '');

        p = p.replace(/^commonjs\/views\//, '');
        p = p.replace(/^reactjs\/(components|layouts)\//, '');
        p = p.replace(/^components\/(.*?)\/backbone\/views\//, '');
        p = p.replace(/^components\/(.*?)\/reactjs\/(components|layouts)\//, '');
        p = p.replace(/\.underscore\.tpl$/, '');
        p = p.replace(/\.[a-z]+$/, '');
        p = p.replace(/\/(.)/g, m => {
            return m.toUpperCase();
        });
        p = p.replace(/\//g, '');
        p = p.charAt(0).toLowerCase() + p.substr(1);

        p = r + p;
        source = source.replace(/kwfLocal/g, p);

    }

    return source;
};

Replace kwfLocal, begin with lower-case letter
Replace kwfLocal, begin with lower-case letter

In order to target classes generated by a react application from component.scss,
the class name needs to start with a lower-case letter. kwcClass and kwcBem
start with lower-case letter as well.
