I'm not using WebPack or others, instead, trying to use the native browser ES-Module system(ESM).
In TypeScript, the coding the source refering the local NPM installed modules.
import * as React from "react";
import * as ReactDOM from "react-dom";
import { SubComponent } from './sub-component';
Then the transpiled JavaScript code is:
import * as React from "react";
import * as ReactDOM from "react-dom";
import { SubComponent } from './sub-component';
This is not good so far, because the actual path to refer on execution with the JavaScript code should be:
import * as React from "../esm/react.js";
import * as ReactDOM from "../esm/react-dom.js";
import { SubComponent } from "./sub-component.js";
(Note: I have a working react/react-dom ESM files in this code and path, so the transpiled output is required exactly to be this code.)
I've read https://www.typescriptlang.org/docs/handbook/module-resolution.html , but don't know exactly what to write to set the mapping.
tsconfig.json
that doesn't work:
{
"compilerOptions": {
//.........
"baseUrl": ".",
"paths": {
"react": [
"../esm/react.js"
],
"react-dom": [
"../esm/react-dom.js"
],
"./sub-component": [
"./sub-component.js"
],
}
}
}
What is the proper way? Thanks.