JSPM

  • Created
  • Published
  • Downloads 39470
  • Score
    100M100P100Q160526F
  • License MIT

Ts transform paths

Package Exports

  • @zerollup/ts-transform-paths

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@zerollup/ts-transform-paths) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Typescript transform paths plugin

tsconfig baseUrl + paths alias rewriting in bundles and declaration files. You can use absolute paths in libraries. All them will be rewritted to relative in transpiled js and in d.ts files.

Works everywhere, no more tspath, rollup-plugin-alias and other workarounds.

Why? Problem described here: d.ts files not working, if absolute paths used in npm-packaged library.

Setup

For setup transform plugin use ttypescript. This is a wrapper around typescript with transformer plugin support in tsconfig.json.

my-lib/tsconfig.json:

{
    "compilerOptions": {
        "baseUrl": ".",
        "paths": {
            "my-lib/*": ["src/*"]
        },
        "plugins": [
            { "transform": "@zerollup/ts-transform-paths" }
        ]
    }
}

my-lib/src/index.ts

export * from 'my-lib/some'

my-lib/src/some.ts

export const some = '123'

Transpiled my-lib/dist/index.js

export * from './some'

Typings my-lib/dist/index.d.ts

export * from './some';

For more examples see zerollup demo lib.

Limitations

Only first element in paths substitutions array used.

my-lib/tsconfig.json:

{
    "compilerOptions": {
        "paths": {
            "my-lib/*": ["src/*", "not_used_substitution/*"]
        }
    }
}