path-alias-resolver
Resolve aliases in ts files. Useful for when you want to publish a package with the typings
file in package.json
, as a project consuming your package will not respect your package's baseurl and path mappings. This will convert all path mappings to relative paths.
Installation
npm i -D myc-path-alias-resolver
Caveats
Due to the nature of the regex used to resolve multi-line imports, it currently has the limitation of only working with prettier
and the follow configuration file:
How to use
Let's say you have a project that has its source files in <rootDir>/src
, and you want to ignore any *.spec.ts
or *.test.ts
files.
Example tsconfig.json
Example File Tree
├── coverage
├── dist
├── docs
├── gulpfile.js
├── node_modules
├── package.json
├── package-lock.json
├── readme.md
├── rollup.config.ts
├── src
├── __test__
├── tsconfig-build.json
├── tsconfig.json
└── tslint.json
Corresponding script gulpfile.js
to use with above setup
const gulp = ;const alias = ; gulp;
Breaking gulpfile.js down
['./src/**/*.ts', '!./src/**/*.spec.ts', '!./src/**/*.test.ts']
Ignore any *.spec.ts
or *.test.ts
files while including all other .ts
files in src
alias('.', { '@src': './src' })
The first parameter corresponds to your baseUrl
setting in tsconfig.json
.
The second parameter is an object of mappings from the paths
key in tsconfig.json
to its value.
gulp.dest('./dist/lib')
Pass the resulting transformed files to ./dist/list