ts-webpack-demo-for-andy
v3.0.0
Published
这是个 用 webpack 打包 ts 的 库,你可以在上面 测试,打包你的 ts 库
Downloads
5
Readme
这是个 用 webpack 打包 ts 的 库,你可以在上面 测试,打包你的 ts 库
实现
- [x] ts 项目,tsconfig.json 就可以实现打包 tsc 一条命令即可
- [x] 建议用 webpack 打包,更强大,配合 tsconfig.json 生成 typings 文件
- [x] 两个文件的输出路径要一致
疑问
用 ts 编写一个库,也生成了.d.ts 文件,然后发布到 npm,然后 在第三方项目中引入这个库,报错, 解决方法:在 node_modules 中建 @types/xxxx(库名)/index.d.ts 就不报错了, 但是问题来了,自己写的库,如何把库的.d.ts 文件提交到 @types/xxx 呢
解决疑问
: 只需要在 tsconfig.json 中 添加 include: ["typeings"], 然后在 项目根目录下新建typings
目录即可,如果里面还报错,那么在typings
里 新建和你 引入的库 同名的 xxxx.d.ts 文件即可参考: https://www.jianshu.com/p/35742227738e https://juejin.im/post/5e43d7a3e51d45270d530300
收获
参考 https://juejin.im/post/5d1f01fce51d454d5653585c
发布库到 npm 如何忽略 不必要的文件
- 黑名单 新建一个 .npmignore 文件,在其中添加不要的文件(夹)
- 白名单 (推荐) 在 package.json 中设置一个要发布的文件(夹)白名单 "files": ["lib/**/*"] ,你要添加发布的库的文件
参考:https://godbasin.github.io/2019/01/05/ts-npm-package/
https://nodelover.gitbook.io/typescript/tsconfig.json
https://segmentfault.com/a/1190000021421461 【xxxx】