ts-js-path-resolve
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

TS-JS-PATH-RESOLVE

NPM version NPM downloads

Use the "NODE_PATH hack" to add new path from tsconfig.json where nodejs should search for modules. *Works with typescript@>=2.0 and only with -unix OS.

Installation

npm install ts-js-path-resolve --save-dev

Usage

rootDir
|
/src
   |
   /lib
       |
       main.ts
   |
   /lib2
       |
       /lib3
           |
           index.ts
// ts-config.json
{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "baseUrl": "./src",
    "paths": {
      "*": [
        "./li/*"
      ],
      "lib/*": ["./lib/*"]
    }
  },
}
 
// now can require some modules as:
// src/main.ts
import * as http from 'http';
import * as path from 'path';
import resolve from 'ts-js-path-resolve';
const configPath = path.join(__dirname, '..', 'tsconfig.json'); //add absolute path to tsconfig.json
resolve(configPath);
 
import module1 from 'lib/main';
import module2 from 'lib2/lib3/'; // now import currectly work after compiling

flags

  • --logs, -LG Get a logs display how change NODE_PATH

License

MIT

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i ts-js-path-resolve

    Weekly Downloads

    1

    Version

    0.0.9

    License

    MIT

    Last publish

    Collaborators

    • killroy192