I decided to use module and target ES2020, because it's time to catch up. I also like the idea of not using webpacking to compile the code to a single JS file. Anyway, I have the following code
//// main.ts:
import { Included } from "./Included";
export class Main {
constructor() {
console.log(`hi from main`);
new Included().say();
}
}
new Main();
/// included.ts:
export class Included {
constructor() {
console.log(`I was included!`);
}
say(){
alert(`Wayasalikilikiyawangagat!`);
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Using latest ts => js2018</title>
</head>
<body>
hi
<script type="module" src="./bin/main.js"></script>
</body>
</html>
It works fine in TypeScript, but when it compiles to ES2020 - it won't recognize
import { Included } from "./Included";
It wants only
import { Included } from "./Included.js";
But my Typescript does not add ".js" automatically. Here is my tsconfig:
{
"compilerOptions": {
"module": "ES2020",
"target": "ES2020",
"outDir": "./bin"
},
"include": [
"src/**/*"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
Is it possible to make TS add ".js" on every import when it compiles files to JS? Thank you.