在学习ArcGIS JS API的过程中,我尝试自己来实现一个esri/core/Accessor类。所以我这么做了,并且把它做成了一个基类发布到了npm上。
这里主要记录如何发布一个包到npm上。
创建项目
首先创建一个项目,正常的npm init -y初始化就好。然后传到仓库。比如我传到了GitHub。
准备工作
先安装你的依赖(如果你有依赖的话),和填写README.md、LICENSE等。
然后我需要配置package.json和tsconfig.json。
package.json:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| { "name": "@geodaoyu/accessor", "version": "1.0.1", "description": "Implement esri/core/Accessor by myself.", "main": "index.js", "module": "dist/index.js", "scripts": { "build": "npx tsc", "test": "mocha" }, "keywords": [ "Accessor", "Esri", "ArcGIS" ], "author": "GeoDaoyu", "license": "MIT", "type": "module", "repository": { "type": "git", "url": "https://github.com/GeoDaoyu/Accessor.git" }, "devDependencies": { "mocha": "^8.3.2", "typescript": "^4.2.4" } }
|
tsconfig.json:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| { "compilerOptions": { "experimentalDecorators": true, "module": "ESNext", "target": "ESNext", "sourceMap": false, "rootDir": "./src", "outDir": "./dist", "esModuleInterop": true, "declaration": true, "skipLibCheck": true, "moduleResolution": "node", }, "include": [ "src/**/*.ts", ], "exclude": [] }
|
编写代码
然后就是正常的编写你的代码。调试通过node来调试。
测试代码
编写xxx.test.js等测试代码,然后npm run test来测试。
发布
需要一个npm的账号,然后npm publish即可发布。