npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@anjianshi/presets-typescript

v3.2.3

Published

通用 tsconfig.json 配置

Downloads

41

Readme

通用 TypeScript 配置

| 文件 | 场景 | | ------------------------------------------------- | --------------------------------------------------------------- | | @anjianshi/presets-typescript/tsconfig-base.json | 仅用 TypeScript 包进行类型检查,用其他工具编译代码 | | @anjianshi/presets-typescript/tsconfig-build.json | 用 tsc 执行编译(支持编译类库和 Node.js 脚本,输出 ES6 Module) | | @anjianshi/presets-typescript/tsconfig-vite.json | 用 Vite 打包 | | tsc-with-alias | 组合运行 tsc 和 tsc-alias。 |

使用方式

安装依赖:

pnpm add --save-dev @anjianshi/presets-typescript typescript

在项目根目录建立 tsconfig.json,然后引用所需的文件:

{
  "extends": "./node_modules/@anjianshi/presets-typescript/tsconfig-build"
}

注意:在使用 pnpm 的情况下,必须使用相对路径来引用 `tsconfig 文件,不能直接通过包名来引用,不然路径计算会出错。

配置 path alias

tsconfig.json 中添加:

{
  "compilerOptions": {
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}

使用 tsc 构建

  • 先添加 ts-alias 依赖:pnpm add --save-dev ts-alias
    不用 ts-alias 的话,构建结果会保留原始带 alias 的引用,甚至在类型定义里会把原本没用引用的路径改为使用引用。
  • 单次构建运行此包提供的脚本:tsc-with-alias
  • 持续监听构建运行:tsc-with-alias --watch

如果在构建的同时还要运行其他内容,例如 nodemon

  • 先添加依赖:pnpm add --save-dev concurrently
  • 构建时运行:concurrently \"tsc-with-alias --watch\" && \"sleep xxx && nodemon xxx\"
    其中,sleep 是可选的,它是为了等待第一次构建完成。

使用 Vite 构建

vite.config.jsresolve.alias 里添加和 tsconfig.json 中一致的配置,
详见:https://vitejs.dev/config/shared-options#resolve-alias