alias-reuse

2.0.1 • Public • Published

⚙️ Alias reuse

Npm package version Small size Testing

Parse custom or exists config with aliases and export for webpack, vite, jest and others

  • Read from TSConfig, Webpack, Vite, CustomFile or Object
  • Convert to TSConfig, Webpack, Vite, Jest or Object

.

  • Install

npm i alias-reuse --save-dev
  • Usage

const alias = require('alias-reuse');

// Read from config file
const ac = alias.fromFile(pathToRoot: string, pathToConfig: string);
// Or read from object
const ac = alias.fromObject(pathToRoot: string, config: Object);

// Convert to TS config
ac.toTSConfig();
// Or convert to Webpack config
ac.toWebpack();
// Or convert to Vite config
ac.toVite();
// Or convert to Jest config
ac.toJest();
// Or convert to object
ac.toObject();
  • Example for webpack.config.js

const alias = require('alias-reuse');
const tsConfigPath = path.join(__dirname, 'tsconfig.json');

module.exports = {
  resolve: {
    alias: alias.fromFile(__dirname, tsConfigPath)
        .toWebpack(),
  },
  // ...
};
  • Example for tsconfig.js

const alias = require('alias-reuse');

module.exports = {
  compilerOptions: {
    paths: alias.fromFile(__dirname, 'path/to/config.js')
        .toTSConfig(),
  },
  // ...
};
  • Example of custom config file

module.exports = {
  "~root/*": "./src/*",
  "~components/*": "./src/components/*",
};

Package Sidebar

Install

npm i alias-reuse

Weekly Downloads

36

Version

2.0.1

License

MIT

Unpacked Size

11.1 kB

Total Files

11

Last publish

Collaborators

  • neki-development