# wd-tracker

> 1. 常见工程目录 wd-tarcker

Latest version **1.0.0** (published 2023-01-31) · ISC license · 0 weekly downloads

## Install

```sh
npm install wd-tracker
pnpm add wd-tracker
yarn add wd-tracker
bun add wd-tracker
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-01-31 |
| First published | 2023-01-31 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | wangminghui |
| Keywords | 前端, 埋点, WDTracker |

## Links

- npm: https://www.npmjs.com/package/wd-tracker
- npm.io page: https://npm.io/package/wd-tracker

## Recent versions

- 1.0.0 (latest) — 2023-01-31

## README

# 一、工程初始化步骤

1. 常见工程目录 wd-tarcker

2. 创建 src、src/core/index.ts、src/types/index.ts、src/utils/pv.ts

3. 创建 index.html、README.md、rollup.config.js

4. 终端执行 npm init -y 生成 package.json

5. 终端执行 tsc --init 生成 tsconfig.json

   ```
   ps:若 tsc 无法执行，全局安装 yarn add typescript -g
   ```

# 二、安装开发依赖

```
yarn add rollup -D
yarn add rollup-plugin-dts -D
yarn add rollup-plugin-typescript2 -D
yarn add typescript -D
```

package.json

```
{
  "name": "wd-tracker",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "module": "dist/index.esm.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "rollup -c",
    "sourcemap": "rollup -c --sourcemap"
  },
  "keywords": [
    "前端",
    "埋点",
    "tracker"
  ],
  "author": "",
  "files": [
    "dist"
  ],
  "license": "ISC",
  "devDependencies": {
    "rollup": "^2.76.0",
    "rollup-plugin-dts": "^4.2.2",
    "rollup-plugin-typescript2": "^0.32.1",
    "typescript": "^4.7.4",
    "@babel/core": "^7.19.1",
    "@babel/preset-env": "^7.19.1",
    "@rollup/plugin-babel": "^5.3.1",
    "@rollup/plugin-node-resolve": "^14.1.0",
    "rollup-plugin-terser": "^7.0.2"
  }
}
```

# 三、配置 rollup.config.js

```
import ts from 'rollup-plugin-typescript2'
import path from 'path'
import dts from 'rollup-plugin-dts';
export default [{
    //入口文件
    input: "./src/core/index.ts",
    output: [
        //打包esModule
        {
            file: path.resolve(__dirname, './dist/index.esm.js'),
            format: "es"
        },
         //打包common js
        {
            file: path.resolve(__dirname, './dist/index.cjs.js'),
            format: "cjs"
        },
       //打包 AMD CMD UMD
        {
            input: "./src/core/index.ts",
            file: path.resolve(__dirname, './dist/index.js'),
            format: "umd",
            name: "tracker"
        }

    ],
    //配置ts
    plugins: [
        ts(),
    ]

}, {
    //打包声明文件
    input: "./src/core/index.ts",
    output:{
        file: path.resolve(__dirname, './dist/index.d.ts'),
        format: "es",
    },
    plugins: [dts()]
}]
```

https://blog.csdn.net/qq_48896417/article/details/128487180

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