Giter Site home page Giter Site logo

discover-monore's Introduction

配置 typescript 下的 monorepo

注:

根据教程:《How to Set Up a TypeScript Monorepo》配置[https://earthly.dev/blog/setup-typescript-monorepo/]

添加了 commitizen 功能

feature

  • git commit with commitizen/cz-cli
  • declare every folder inside /packages with a package.json file is considered a local package.(by add "workspaces" property in /package.json )
  • typescript
  • ts-node
  • eslint
  • prettier

git commit

使用npm run cz命令替代git commit提交代码

add a Local Package

mkdir in /packages:

  • cd packages
  • mkdir utils

initialize a package.json file inside utils:

  • npm init --scope @monorepo --workspace ./packages/utils

  • confirm package.json own this content

    {
      "name": "@monorepo/utils",
      "version": "1.0.0",
      "description": "The package containing some utility functions",
      "main": "build/index.js",
      "scripts": {
        "build": "tsc --build"
      }
    }
  • add tsconfig.json inside utils:

    {
      "compilerOptions": {
        "target": "es2022",
        "module": "commonjs",
        "moduleResolution": "node",
        "declaration": true,
        "strict": true,
        "incremental": true,
        "esModuleInterop": true,
        "skipLibCheck": true,
        "forceConsistentCasingInFileNames": true,
        "rootDir": "./src",
        "outDir": "./build",
        "composite": true
      }
    }

build Local Package Works

通过 --workspace指明命令的工作路径,从而执行对应 package.json中定义的script

npm run build --workspace ./packages/utils

tsconfig.json全局管理

{
  "compilerOptions": {
    "incremental": true,
    "target": "es2022",
    "module": "commonjs",
    "declaration": true,
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "rootDir": "./src",
    "outDir": "./build"
  },
  "files": [],
  "references": [
    {
      "path": "./packages/utils"
    }
  ]
}

在根目录执行 tsc --build 命令时,编译器会通过全局 tsconfig.json文件中的 references字段中定义的路径找到所有可编译的独立项目,并编译

在pacakges下的库中引入其他库

在packages/ui下使用packages/utils的库

npm install @monorepo/utils --workspace ./packages/ui

npm安装依赖命令

npm install moment --workspace ./packages/ui

全局声明packages下的项目作为依赖

npm install @monorepo/utils @monorepo/ui

discover-monore's People

Contributors

lhaosss avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.