'use strict';

const fs = require('fs');
const stripBom = require('strip-bom');
const compiler = require('vue-template-compiler');

let browserEnv = false;
try {
    document;
    browserEnv = true;
} catch (e) {}

let store = {
    style : {
        defaults : '',
        langs : {},
    },
    script : {
        defaults : '',
        langs : {},
    },
    template : {
        defaults : '',
        langs : {},
    },
};

require.extensions['.vue'] = require.extensions['.vue'] || function ( module, filePath ) {

    let content = fs.readFileSync(filePath, 'utf8');

    let vueTemplate = '';
    let vueComponent = compiler.parseComponent(stripBom(content));

    let script = vueComponent.script;
    let styles = vueComponent.styles;
    let template = vueComponent.template;

    [].concat(script, template, styles).forEach(( tag ) => {
        if (tag) {
            let type = tag.type;
            let content = tag.content;
            let lang = tag.attrs.lang || store[type].defaults;
            let handler = store[type].langs[lang];
            if (handler) {
                content = handler(content, filePath);
            }
            switch (type) {
                case 'style':
                    if (browserEnv) {
                        let style = document.createElement('style');
                        style.innerHTML = content;
                        document.head.appendChild(style);
                    }
                    break;
                case 'script':
                    module._compile(content, filePath);
                    break;
                case 'template':
                    vueTemplate = content;
                    break;
            }
        }
    });
    module.exports.template = vueTemplate;
};

function set ( type, lang ) {
    store[type].defaults = lang;
}

function register ( type, lang, handler ) {
    store[type].langs[lang] = handler;
}

['style', 'script', 'template'].forEach(( type ) => {
    exports[type] = {
        set ( lang ) {
            set(type, lang);
            return this;
        },
        register ( lang, handler ) {
            register(type, lang, handler);
            return this;
        },
    };
});

@@ -125,16 +125,80 @@
 ler');%0A%0A
+/**%0A * In Browser Environment%0A * @type %7BBoolean%7D browserEnv%0A */%0A
 let brow
@@ -272,16 +272,86 @@
 (e) %7B%7D%0A%0A
+/**%0A * Save Loaders of different Language%0A * @type %7BObject%7D store%0A */%0A
 let stor
@@ -556,16 +556,937 @@
  %7D,%0A%7D;%0A%0A
+/**%0A * Set default Loader%0A * @param %7BString%7D type %7C style %7C script %7C template %7C%0A * @param %7BString%7D lang scss, ts, jade etc.%0A */%0Afunction set ( type, lang ) %7B%0A    store%5Btype%5D.defaults = lang;%0A%7D%0A%0A/**%0A * Register Loader%0A * @param %7BString%7D type %7C style %7C script %7C template %7C%0A * @param %7BString%7D lang scss, ts, jade etc.%0A * @param %7BFunction%7D handler handler%0A */%0Afunction register ( type, lang, handler ) %7B%0A    store%5Btype%5D.langs%5Blang%5D = handler;%0A%7D%0A%0A/**%0A * Exports API to expand%0A */%0A%5B'style', 'script', 'template'%5D.forEach(( type ) =%3E %7B%0A    exports%5Btype%5D = %7B%0A        set ( lang ) %7B%0A            set(type, lang);%0A            return this;%0A        %7D,%0A        register ( lang, handler ) %7B%0A            register(type, lang, handler);%0A            return this;%0A        %7D,%0A    %7D;%0A%7D);%0A%0A/**%0A * Require extension vue hook%0A * @param %7BModule%7D module module%0A * @param %7BString%7D filePath file path%0A * @export %7BVue%7D Vue Component after compile%0A */%0A
 require.
@@ -2289,24 +2289,157 @@
 owserEnv) %7B%0A
+                        /**%0A                         * Only in Browser Environment, append style to head%0A                         */%0A
             
@@ -2902,16 +2902,17 @@
     %7D);%0A
+%0A
     modu
@@ -2953,448 +2953,4 @@
 %0A%7D;%0A
-%0Afunction set ( type, lang ) %7B%0A    store%5Btype%5D.defaults = lang;%0A%7D%0A%0Afunction register ( type, lang, handler ) %7B%0A    store%5Btype%5D.langs%5Blang%5D = handler;%0A%7D%0A%0A%5B'style', 'script', 'template'%5D.forEach(( type ) =%3E %7B%0A    exports%5Btype%5D = %7B%0A        set ( lang ) %7B%0A            set(type, lang);%0A            return this;%0A        %7D,%0A        register ( lang, handler ) %7B%0A            register(type, lang, handler);%0A            return this;%0A        %7D,%0A    %7D;%0A%7D);%0A

update md