Search code examples
javascripttypescriptwebpackbabeljs

Simple Typescript es5 library


I am really confused about 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

var f = new Foo();

I am using webpack to bundle the assets.

Do I need babel to polyfill to an iife or am I missing something else?


Solution

  • 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 did.