qlin 97bfb30f30
refactor: 优化 request 插件 (#130)
* refactor: 优化 request 插件

* fix: errorHandler 的顺序控制问题'
2022-06-16 11:04:26 +08:00

32 lines
724 B
JavaScript

import { join } from 'path';
import { name } from '../package.json';
export default (api) => {
api.addRuntimePluginKey(() => 'request');
const namespace = 'plugin-request';
const absoluteFilePath = `${namespace}/request.js`;
let generatedOnce = false;
api.onGenerateFiles(() => {
if (generatedOnce) return;
generatedOnce = true;
api.copyTmpFiles({
namespace,
path: join(__dirname, 'template'),
});
});
api.addPluginExports(() => [
{
exportAll: true,
source: absoluteFilePath,
},
]);
api.addConfigType(() => ({
source: name,
runtime: ['RequestRuntimeConfig'],
}));
};