@build-script/typescript-transformer-common

transformer helpers

Usage no npm install needed!

<script type="module">
  import buildScriptTypescriptTransformerCommon from 'https://cdn.skypack.dev/@build-script/typescript-transformer-common';
</script>

README

typescript-transformer-import-commonjs

It will convert things like

import { emptyDir } from 'fs-extra';

Into

import fs_extra_1 from 'fs-extra';
const { emptyDir } = fs_extra_1;

Only if:

  1. path is not relative
  2. package name directly defined in dependencies in package.json
  3. imported package's package.json does not have "type": "module"
  4. not imported with special extensions: .cjs or .mjs or .json

Usage

tsconfig.json: all extra options is optional

{
    "compilerOptions": {
        "plugins": [
            {
                "transform": "@build-script/typescript-transformer-dual-package",
                "specialExtensions": ["cjs", "mjs", "json", "wasm", "cjs.js"], // defaults to cjs,mjs,json
                "ignore": ["some-module"], // do not change import of this package
                "force": ["some-module"], // force change import even it's type is module
                "package.json": "../package.json" // Current package's json file, defaults to find the nearest one
            }
        ]
    }
}