npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

@zerollup/ts-transform-paths

1.7.3 • Public • Published

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",
                "exclude": ["*"]
            }
        ]
    }
}

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.

Plugin options

interface Config {
    /**
        Add a browser mode -- meaning that path resolution includes
        determining exact FILE being imported (with extension) as this
        is required by browsers when not using browserfy or rollup or any of the other packaging tools
     */
    for?: string | void
 
    /**
        Disable plugin path resolving for given paths keys
     */
    exclude?: string[] | void
}

Limitations

Only first element in paths substitutions array used.

my-lib/tsconfig.json:

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

install

npm i @zerollup/ts-transform-paths

Downloadsweekly downloads

2,767

version

1.7.3

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability