I am really confused on how to create a simple es5 library that is not loaded as a module but rather like an old fashioned iife.
All I am trying to do is to create a single file that will be included in the html
<script src="foo.js" type="text/javascript" />
and then be able to instantiate the function
<script>
var f = new Foo();
</script>
I am using webpack to bundle the assets.
Do I need babel to polyfill to an iife or am I missing something else ?
CodePudding user response:
Usually the library injects the class into the browser's global variable. May be you shoud add this in your lib code.
class Foo {
}
window.Foo = Foo
For example: This is how jquery does it.