@build-script/typescript-transformer-common
TypeScript icon, indicating that this package has built-in type declarations

0.2.3 • Public • Published

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
			}
		]
	}
}

Readme

Keywords

none

Package Sidebar

Install

npm i @build-script/typescript-transformer-common

Weekly Downloads

0

Version

0.2.3

License

MIT

Unpacked Size

122 kB

Total Files

69

Last publish

Collaborators

  • gongt