# ts-rc-cli

> React + Typescript Web 项目脚手架

Latest version **1.0.0-alpha.9** (published 2022-01-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-rc-cli
pnpm add ts-rc-cli
yarn add ts-rc-cli
bun add ts-rc-cli
```

Provides the command `ts-rc`.

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-alpha.9 |
| Published | 2022-01-07 |
| First published | 2021-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 43 |
| Unpacked size | 144.8 KB |
| Known vulnerabilities | 0 (+6 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 3 |
| Author | lanten |
| Maintainers | lanten233 |

## Links

- npm: https://www.npmjs.com/package/ts-rc-cli
- Repository: https://github.com/lanten/ts-rc-cli
- Homepage: https://github.com/lanten/ts-rc-cli#readme
- Issues: https://github.com/lanten/ts-rc-cli/issues
- npm.io page: https://npm.io/package/ts-rc-cli

## Dependencies (43)

- [url](https://npm.io/package/url.md) ^0.11.0
- [glob](https://npm.io/package/glob.md) ^7.2.0
- [tslib](https://npm.io/package/tslib.md) ^2.3.1
- [eslint](https://npm.io/package/eslint.md) ^8.6.0
- [address](https://npm.io/package/address.md) ^1.1.2
- [process](https://npm.io/package/process.md) ^0.11.10
- [webpack](https://npm.io/package/webpack.md) ^5.65.0
- [inquirer](https://npm.io/package/inquirer.md) ^8.2.0
- [prettier](https://npm.io/package/prettier.md) ^2.5.1
- [cross-env](https://npm.io/package/cross-env.md) ^7.0.3
- [ts-loader](https://npm.io/package/ts-loader.md) ^9.2.6
- [css-loader](https://npm.io/package/css-loader.md) ^6.5.1
- [ex-console](https://npm.io/package/ex-console.md) ^0.0.1
- [webpackbar](https://npm.io/package/webpackbar.md) ^5.0.2
- [@types/glob](https://npm.io/package/@types/glob.md) ^7.2.0
- [@types/node](https://npm.io/package/@types/node.md) ^17.0.8
- [webpack-cli](https://npm.io/package/webpack-cli.md) ^4.9.1
- [style-loader](https://npm.io/package/style-loader.md) ^3.3.1
- [webpack-merge](https://npm.io/package/webpack-merge.md) ^5.8.0
- [@types/webpack](https://npm.io/package/@types/webpack.md) ^5.28.0
- [css-hot-loader](https://npm.io/package/css-hot-loader.md) ^1.4.4
- [@types/inquirer](https://npm.io/package/@types/inquirer.md) ^8.1.3
- [default-gateway](https://npm.io/package/default-gateway.md) ^6.0.3
- [ts-import-plugin](https://npm.io/package/ts-import-plugin.md) ^2.0.0
- [@types/webpackbar](https://npm.io/package/@types/webpackbar.md) ^4.0.3
- [@types/webpack-env](https://npm.io/package/@types/webpack-env.md) ^1.16.3
- [webpack-dev-server](https://npm.io/package/webpack-dev-server.md) ^4.7.2
- [eslint-plugin-react](https://npm.io/package/eslint-plugin-react.md) ^7.28.0
- [html-webpack-plugin](https://npm.io/package/html-webpack-plugin.md) ^5.5.0
- [eslint-webpack-plugin](https://npm.io/package/eslint-webpack-plugin.md) ^3.1.1
- [terser-webpack-plugin](https://npm.io/package/terser-webpack-plugin.md) ^5.3.0
- [@types/default-gateway](https://npm.io/package/@types/default-gateway.md) ^3.0.1
- [eslint-config-prettier](https://npm.io/package/eslint-config-prettier.md) ^8.3.0
- [eslint-plugin-prettier](https://npm.io/package/eslint-plugin-prettier.md) ^4.0.0
- [mini-css-extract-plugin](https://npm.io/package/mini-css-extract-plugin.md) ^2.4.6
- [@types/webpack-dev-server](https://npm.io/package/@types/webpack-dev-server.md) ^4.7.2
- [@typescript-eslint/parser](https://npm.io/package/@typescript-eslint/parser.md) ^5.9.0
- [eslint-plugin-react-hooks](https://npm.io/package/eslint-plugin-react-hooks.md) ^4.3.0
- [@types/html-webpack-plugin](https://npm.io/package/@types/html-webpack-plugin.md) ^3.2.6
- [css-minimizer-webpack-plugin](https://npm.io/package/css-minimizer-webpack-plugin.md) ^3.3.1
- [@types/mini-css-extract-plugin](https://npm.io/package/@types/mini-css-extract-plugin.md) ^2.4.0
- [@typescript-eslint/eslint-plugin](https://npm.io/package/@typescript-eslint/eslint-plugin.md) ^5.9.0
- [eslint-plugin-jsx-control-statements](https://npm.io/package/eslint-plugin-jsx-control-statements.md) ^2.2.1

## Recent versions

- 1.0.0-alpha.9 (latest) — 2022-01-07
- 1.0.0-alpha.8 — 2022-01-07
- 1.0.0-alpha.7 — 2022-01-07
- 1.0.0-alpha.6 — 2021-12-10
- 1.0.0-alpha.5 — 2021-12-09
- 1.0.0-alpha.4 — 2021-12-09
- 1.0.0-alpha.3 — 2021-12-09
- 1.0.0-alpha.2 — 2021-12-09
- 1.0.0-alpha.1 — 2021-12-09
- 0.2.6 — 2021-06-23
- 0.2.5 — 2021-05-30
- 0.2.4 — 2021-05-30
- 0.2.3 — 2021-05-30
- 0.2.2 — 2021-05-30
- 0.2.1 — 2021-05-30
- … 34 more at https://npm.io/package/ts-rc-cli/versions

## README

# ts-rc-cli

![v](https://img.shields.io/npm/v/ts-rc-cli) ![dm](https://img.shields.io/npm/dm/ts-rc-cli) ![languages](https://img.shields.io/github/languages/top/lanten/ts-rc-cli) ![last-commit](https://img.shields.io/github/last-commit/lanten/ts-rc-cli)

## 命令行工具

`ts-rc` 命令, 例子: `ts-rc dev`

| 指令                 | 说明             | 参数                 |
| -------------------- | ---------------- | -------------------- |
| create               | 创建模板项目     | name(非必须)         |
| add-template, -at    | 添加模板         | gitUrl, name(非必须) |
| remove-template, -rt | 删除本地模板     | name(非必须)         |
| dev                  | 启动本地服务     | ...env               |
| build                | 执行编译脚本     | ...env               |
| get-config           | 编译 config 文件 | -                    |
| help, -h             | 显示帮助         | -                    |

## 快速开始

全局安装脚手架

```bash
npm i -g ts-rc-cli
# or
yarn global add ts-rc-cli
```

通过模板快速创建项目

```bash
ts-rc create
```

启动 dev 本地开发服务

```bash
yarn dev
# or
npm run dev
```

生产编译

```bash
yarn build
# or
npm run build
```

## 自定义配置

创建 `config/index.ts` 文件

chestnut:

```ts
import path from 'path'
import { ReactTsConfigPartial } from 'ts-rc-cli'

const rootPath = process.cwd()

const projectName = 'new-project'
const projectTitle = 'New Project'

const config: ReactTsConfigPartial = {
  projectName,
  projectTitle,
  port: 18081,
  htmlOptions: {
    template: path.resolve(rootPath, 'src/index.html'),
  },
  devServerOptions: {
    publicPath: '',
  },

  entry: {
    app: path.resolve(rootPath, 'src/index.tsx'),
  },
}

export default config
```

### ⚠ 注意: `config` 使用的 `tsconfig` 是独立的, 如下所示

```json
[
  "-m commonjs",
  "-t es6",
  "--moduleResolution node",
  "--resolveJsonModule true",
  "--esModuleInterop true",
  "--allowSyntheticDefaultImports true",
  "--suppressImplicitAnyIndexErrors true",
  "--skipLibCheck true",
  "--types node",
  "--lib esnext,scripthost,es5",
  "--outDir ${outPath}"
]
```

项目根目录需要添加 `tsconfig.json` 文件.

此外,请按需添加 `.eslintignore`, `.eslintrc.js`, `.browserslistrc` 文件.

脚本将自动读取 `config` 下的配置文件

## 集成 cross-env

集成了 [cross-env](https://www.npmjs.com/package/cross-env), 可以直接添加环境变量:

```bash
ts-rc-dev MY_ENV=xxx
ts-rc-build MY_ENV=xxx
```

## 默认配置

在 [config.d.ts](./typings/config.d.ts) 中查看全部默认配置

- 在生产环境中默认移除了 `console.log`, 可以在 `terserOptions` 中修改
- `@` 是 `src` 的别名
- 默认 `dev-server` 端口号: `18080`
- 默认入口文件: `src/main.ts`
- 默认构建环境: `mock` | `dev` | `prod`

## 环境变量

| 变量名      | 说明         | 类型                       | 默认值          |
| ----------- | ------------ | -------------------------- | --------------- |
| CONFIG_PATH | 配置文件路径 | string                     | config/index.ts |
| NODE_ENV    | Node 参数    | development/production     | auto            |
| BUILD_ENV   | 构建参数     | keyOf ReactTsConfig['env'] | dev             |

## 模板开发文档

TODO...

---

## 源代码相关

#### 子模块

- [react-ts-template](https://github.com/lanten/react-ts-template)

#### 初始化子模块

```bash
git submodule init
```

#### 拉取子模块

```bash
git submodule update
```

---
_Source: https://npm.io/package/ts-rc-cli · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
