I have a tsconfig.json like this:
{
"compilerOptions": {
"lib": ["es2017", "dom"],
"module": "umd",
"outDir": "dist",
"target": "es5",
"declaration": true
},
"compileOnSave": true,
"files": [
"myClass.ts"
"demo.ts"
]
}
My typescript, demo.ts
:
import { MyClass } from './myClass';
(() => {
console.log('fired IIFE');
document.onreadystatechange = function () {
if (document.readyState === 'interactive') {
console.log('hello world', MyClass);
}
};
})();
Which gets compiled to:
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "./myClass"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var myClass_1 = require("./myClass");
(function () {
console.log('fired IIFE');
document.onreadystatechange = function () {
if (document.readyState === 'interactive') {
console.log('hello world', myClass_1.MyClass);
}
};
})();
});
My html:
<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
<script src="./dist/myClass.js"></script>
<script src="./dist/demo.js"></script>
</head>
<body>
<p>test</p>
</body>
</html>
I have also tried:
<!DOCTYPE HTML>
<html>
<head>
<title>Test</title>
</head>
<body>
<p>test</p>
<script src="./dist/myClass.js"></script>
<script src="./dist/demo.js"></script>
</body>
</html>
Neither way executes the script, and neither log statement is printed. What am I doing wrong?