A custom transformer that can be used with ttypescript to transform ts imports to browser style imports
Home > config > PluginConfigs > importMap
Use import map as the transform rules. (This has the highest priority.)
Signature:
importMap?: ImportMapResolution | ImportMapCustomResolution
**Experimental** may have many bugs on transforming with importMap. See ImportMapResolution (static) or ImportMapCustomResolution (dynamic)
If you’re using snowpack, let’s assume the folder is like
Folder:
/web_modules/ # generated by snowpack
/src/ # your source code
/dist/ # your output
tsconfig.json # tsconfig at here
You must set rootDir
when using importMap.
Filename: snowpack/tsconfig.json
{
"compilerOptions": {
"plugins": [
{
// @magic-works/ttypescript-browser-like-import-transformer
"transform": "@magic-works/ttypescript-browser-like-import-transformer",
"after": true,
"importMap": {
"type": "path",
"mapPath": "./web_modules/import-map.json",
"simulateRuntimeImportMapPosition": "/web_modules/",
"simulateRuntimeSourceRoot": "/dist/"
}
}
],
"target": "ESNext",
"module": "ESNext",
"outDir": "./dist",
"rootDir": "./src",
"moduleResolution": "node"
}
}
Source:
Filename: snowpack/src/index.ts
import * as _ from 'lodash-es'
console.log(_)
import './another'
Output:
Filename: snowpack/index.js
import * as _ from "/web_modules/lodash-es.js?rev=806d1b9f78";
console.log(_);
import "./another.js";