Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neki-dev/alias-reuse
⚙️ Reuse custom or existing aliases from one configuration in others
https://github.com/neki-dev/alias-reuse
alias config jest path reuse tsconfig vite webpack
Last synced: 19 days ago
JSON representation
⚙️ Reuse custom or existing aliases from one configuration in others
- Host: GitHub
- URL: https://github.com/neki-dev/alias-reuse
- Owner: neki-dev
- License: mit
- Created: 2022-04-02T16:20:32.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-19T13:11:35.000Z (4 months ago)
- Last Synced: 2024-10-11T15:15:20.295Z (about 1 month ago)
- Topics: alias, config, jest, path, reuse, tsconfig, vite, webpack
- Language: TypeScript
- Homepage:
- Size: 334 KB
- Stars: 3
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## ⚙️ Alias reuse
[![Version](https://badgen.net/npm/v/alias-reuse)](https://npmjs.com/package/alias-reuse)
[![Small size](https://img.badgesize.io/neki-dev/alias-reuse/master/dist/index.js)](https://github.com/neki-dev/alias-reuse/blob/master/dist/index.js)
[![Build](https://github.com/neki-dev/alias-reuse/actions/workflows/build.yml/badge.svg)](https://github.com/neki-dev/alias-reuse/actions/workflows/build.yml)
[![Test](https://github.com/neki-dev/alias-reuse/actions/workflows/test.yml/badge.svg)](https://github.com/neki-dev/alias-reuse/actions/workflows/test.yml)Reuse custom or existing aliases from one configuration in others.
.
## Install
```sh
npm i alias-reuse --save-dev
```.
## Usage
### Import
Import aliases from existing configuration.
The library will automatically detect the configuration source type.Supported configuration sources:
* `tsconfig`
* `webpack` / `vite`
* `object`
```ts
reuse().from(pathToConfig: string);
```
... and also from custom object.
```ts
reuse().from(config: Record);
```### Configure
Set custom root directory.
```ts
reuse().from(...).at(pathToRoot: string);
```### Export
Export of aliases in a required configuration target.Supported configuration targets:
* `tsconfig`
* `webpack` / `vite`
* `jest`
* `object`
```ts
reuse().from(...).for(target: string);
```.
## Examples
* #### Example for Webpack
```js
const { reuse } = require('alias-reuse');
const tsconfigPath = path.join(__dirname, 'tsconfig.json');module.exports = {
resolve: {
alias: reuse()
.from(tsconfigPath) // Import aliases from tsconfig.json
.for("webpack"), // And convert to webpack format
},
// ...
};
```* #### Example for TSConfig
```js
const { reuse } = require('alias-reuse');
const configPath = path.join(__dirname, 'configs/aliases.json');module.exports = {
compilerOptions: {
paths: reuse()
.from(configPath) // Import aliases from custom config
.for("tsconfig"), // And convert to tsconfig format
},
// ...
};
```* #### Example with custom root directory
```js
const { reuse } = require('alias-reuse');
const rootPath = path.join(__dirname, 'root');
const configPath = path.join(__dirname, 'configs/aliases.json');module.exports = {
resolve: {
alias: reuse()
.from(configPath) // Import aliases from custom config
.at(rootPath) // Set root directory
.for("vite"), // And convert to vite format
},
// ...
};
```