此 webpack 插件是服务于axios-api的 d.ts 生成工具
npm install --save @no-996/axios-api-webpack-plugin
// webpack.config.js
// ...
const AxiosApiWebpackPlugin = require('@no-996/axios-api-webpack-plugin')
// ...
module.exports = {
// ...
plugins: [
// ...
new AxiosApiWebpackPlugin({
// 接口定义文件
configFile: './src/api/options/index.js',
// 输出d.ts声明文件(与实例输出文件所在目录一致、文件名一致)
declareOutputFile: './src/api/index.d.ts',
}),
// ...
],
// ...
}
接口定义文件示例:
// src/api/options/index.js
export default [
{
name: 'posts',
des: '帖子',
url: '/posts',
params: {
userId: undefined,
},
children: [
{
name: 'comments',
des: '评论',
url: '/posts/{postId}/comments',
urlParams: {
postId: undefined,
},
metadata: {
urlParams: {
postId: {
name: '帖子id',
required: true,
},
},
},
},
],
metadata: {
params: {
userId: {
name: '用户id',
des: '用户唯一标识',
type: 'string',
},
},
},
},
{
name: 'albums',
url: '/albums',
des: '专辑',
params: {
id: undefined,
},
children: [],
},
{
name: 'photos',
url: '/photos',
des: '相片',
params: {},
children: [],
cache: 3000,
},
{
name: 'todos',
url: '/todos',
des: '待办事项',
params: {},
children: [],
cancel: 'current',
},
{
name: 'users',
url: '/users',
des: '用户',
params: {},
children: [],
cancel: 'previous',
},
]
实例输出文件示例:
// src/api/index.js
import ApiModule from '@no-996/axios-api'
import options from './options'
export default new ApiModule(
// 接口定义
options,
// axios配置
{
baseURL: 'https://jsonplaceholder.typicode.com',
onUploadProgress: (progressEvent, percentCompleted) => {
console.log(percentCompleted)
},
},
// axios-api配置
{
cacheStorage: localStorage,
debug: true,
}
)
"dependencies": {
"colors": "^1.4.0",
"lodash": "^4.17.21",
"prettier": "^2.4.1"
}
Mix parent declare name
bug fix
bug fix
Add axios instance declear
Add console words
Use webpack instead async import
Fix param declare missing when without metadata
Fix ApiModuleOptions import
Fix request comment
Support urlParams ts info
Change input file from object to array
Add method comment
Add comment after default data
Change url comment lines
Change url comment placement
Add url comment
Fix file path resolve
First release version.