TypeScript 详解之构建发布一个 TypeScript

2022-03-09  本文已影响0人  you的日常

介绍

在这篇文章中,我们会使用 TypeScript, TSLint, Prettier, Jest 等构建并发布一个 NPM TypeScript 包。

前提

node -v
npm -v

基本构建

mkdir irene-awesome-greeter && cd irene-awesome-greeter

echo "node_modules" >> .gitignore
echo "# Irene Awesome Greeter" >> README.md

git init
git add . && git commit -m "Initial commit"
git remote add origin <Git Repository Url>
git push -u origin master

npm init -y

添加 TypeScript as devDependencies

npm i -D typescript

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "declaration": true,
    "outDir": "./lib",
    "strict": true,
    "lib": ["es6"]
  },
  "include": ["src"],
  "exclude": ["node_modules", "**/__tests__/*"]
}

更多的编译选项可参考: www.typescriptlang.org/docs/handbo…

export const Greeter = (name: string) => `Hello ${name}`;

"build": "tsc"

node_modules
/lib

Formatting & Linting

移除不必要文件

上一篇 下一篇

猜你喜欢

热点阅读