GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - x-dirve/alias: nodeJs 包引用别名支持

BranchesTags
Open more actions menu

Latest commit

 

History

6 Commits
6 Commits

Folders and files

NameName
Last commit message
Last commit date
example
example
 
 
src
src
 
 
.gitignore
.gitignore
 
 
.npmrc
.npmrc
 
 
.swcrc
.swcrc
 
 
CHANGELOG.md
CHANGELOG.md
 
 
README.md
README.md
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
yarn.lock
yarn.lock
 
 

Repository files navigation

NodeJS 模块别名支持模块

NodeJs 应用中的模块引用,很容易会出现多层相对路径引用的情况,如:

import { local } from "../../../../../components/cache";

本模块使用了目前很多页端应用其实已广泛的别名机制来解决这个问题。

使用

  1. 将 @x-drive/alias 加入到项目生产依赖
  2. 定义项目路径别名
    1. 默认是在根目录的 package.json 中的 aliases 字段
    2. 用户可通过配置指定符合标准的配置文件
  3. 在尽可能开始的地方启用模块

配置项

  • cwd 查找根目录,默认是 process.cwd()
  • modulesDir 额外的模块目录,默认是 node_modules
  • file 别名配置文件,默认是根目录下的 package.json

TypeScript 中使用

由于不同的项目 TypeScript 的应用方式有可能会不同,比如可能直接使用 node 启动 ts 项目或 ts 项目是需要编译后才启动的。因此 alias 不会尝试去使用 tsconfig 中的相关设置,也不会尝试去干预 ts 的相关设置。因此在 ts 中使用,需要用户自己根据项目的情况设置 tsconfig 稳健中 compilerOptions 中的 paths 字段

About

nodeJs 包引用别名支持

Resources

Readme
Activity
Custom properties

Stars

0 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.