FranckFreiburger / http-vue-loader

load .vue files from your html/js
MIT License
1.49k stars 275 forks source link

Use 'self' if 'root' is undefined #117

Open flancer64 opened 4 years ago

flancer64 commented 4 years ago

I try to load libs with import():

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script>
        function bootstrap() {
            // load all libraries then create & start application
            Promise.all([
                import("./lib/http_vue_loader.js"),
                import("./lib/vue-router.js"),
                import("./lib/vue_esm_browser.js"),
            ]).then(([modLoader, modRouter, modVue, ...other]) => {
                debugger;
            });
        }

        window.addEventListener("load", () => bootstrap());
    </script>
</head>
<body>
</body>
</html>

but root is undefined in this case:

(function umd(root,factory){
    if(typeof module==='object' && typeof exports === 'object' )
        module.exports=factory()
    else if(typeof define==='function' && define.amd)
        define([],factory)
    else
        root.httpVueLoader=factory()
})(this,function factory() {...});

and I have an error "Cannot set property 'httpVueLoader' of undefined" at

root.httpVueLoader=factory()

vue-router.js uses self in the same situation.