I am using imports and exports because references are said to be outdated. However, I want to compile to one file, and I'm using the "system" module, but it is turning everything into a module even if nothing is being exported. If anything is imported, the code is not executed, but if nothing is imported or exported, the code is executed. I need to import files to be able to use them, but I cannot because the code becomes a module function.
This is my tsconfig.json:
{
"compilerOptions": {
"module": "system",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": false,
"outFile": "{PATH}"
}
}
My TypeScript code:
import { Button } from "UI/Button";
new Button("Hello World!");
console.log("HELLO!");
The compiled code turns it into this:
System.register("Main/main", ["UI/Button"], function (exports_4, context_4) {
"use strict";
var Button_1;
var __moduleName = context_4 && context_4.id;
return {
setters: [
function (Button_1_1) {
Button_1 = Button_1_1;
}
],
execute: function () {
new Button_1.Button("Hello World!");
console.log("HELLO!");
}
};
});
If I remove the import and only keep the console.log:
console.log("HELLO!");
It removes everything without the import, even the previous modules because I guess it does not detect them being used.
I am assuming I am misunderstanding how the import/export system works? I want to be able to run functions and import/export files, but as of now it looks like I can only import/export files, not run them. I want all of it to be compiled into one file, too. Any help would be appreciated!