![Introducing License Enforcement in Socket](https://cdn.sanity.io/images/cgdhsj6q/production/739c20a7a75752fc62de4685a31b46625de9f00a-2108x1404.png?w=400&fit=max&auto=format)
Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
The tsc-alias npm package is a tool designed to resolve and replace path aliases in the compiled JavaScript files generated by the TypeScript compiler. It is particularly useful for projects that use path aliases in their TypeScript configuration (tsconfig.json) to simplify module imports.
Path Alias Resolution
This command resolves and replaces path aliases in the compiled JavaScript files based on the configuration specified in the tsconfig.json file. It ensures that the path aliases used in TypeScript are correctly translated to relative paths in the output JavaScript.
tsc-alias -p tsconfig.json
Custom Configuration
This command allows you to specify a custom configuration file for tsc-alias. This is useful if you have a separate configuration for alias resolution that differs from your main tsconfig.json.
tsc-alias -p tsconfig.json --config custom-config.json
Watch Mode
This command runs tsc-alias in watch mode, which means it will continuously monitor your TypeScript files for changes and automatically resolve path aliases in the compiled JavaScript files whenever a change is detected.
tsc-alias -p tsconfig.json --watch
The module-alias package allows you to register and use custom module paths in Node.js. It is similar to tsc-alias in that it helps manage module paths, but it is not specifically designed for TypeScript and does not integrate with the TypeScript compiler.
The babel-plugin-module-resolver package is a Babel plugin that allows you to alias module paths in your JavaScript code. It is similar to tsc-alias in that it helps manage module paths, but it is designed to work with Babel rather than the TypeScript compiler.
The tsconfig-paths package is a tool that helps resolve TypeScript path aliases at runtime. It is similar to tsc-alias in that it works with TypeScript path aliases, but it focuses on runtime resolution rather than compile-time resolution.
Replace alias paths with relative paths after typescript compilation. You can add aliases that reference other projects outside your tsconfig.json project by providing a relative path to the baseUrl.
+ Compile time (no runtime dependencies)
First, install tsc-alias as devDependency using npm.
npm install -g tsc-alias
npm install --save-dev tsc-alias
"scripts": {
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
}
================ OR ===================
"scripts": {
"build": "tsc && tsc-alias",
"build:watch": "tsc -w & tsc-alias -w"
}
npm install tsc-alias
import { replaceTscAliasPaths } from 'tsc-alias';
replaceTscAliasPaths(options?);
Here are all the available options:
Option | Description | Default Value |
---|---|---|
configFile | path to tsconfig.json | 'tsconfig.json' |
watch | Observe file changes | false |
outDir | Run in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig) | tsconfig.compilerOptions.outDir |
resolveFullPaths | Attempt to replace incomplete import paths (those not ending in .js ) with fully resolved paths (for ECMAScript Modules compatibility) | false |
silent | Reduced terminal output | false |
FAQs
Replace alias paths with relative paths after typescript compilation.
The npm package tsc-alias receives a total of 503,732 weekly downloads. As such, tsc-alias popularity was classified as popular.
We found that tsc-alias demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.