mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-05 11:18:54 +08:00
* feat: 添加 login 插件 * docs: 优化 access docs 文档 * refactor: beforeRender迁移到router创建后 * fix: 修复清除webpack-cache问题 * refactor: 优化 plugin 插件 Co-authored-by: wanchun <445436867@qq.com>
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
import { join } from 'path';
|
|
import { readFileSync } from 'fs';
|
|
import { name } from '../package.json';
|
|
|
|
export default (api) => {
|
|
api.addRuntimePluginKey(() => 'login');
|
|
const pkgs = Object.keys({
|
|
...api.pkg.dependencies,
|
|
...api.pkg.devDependencies,
|
|
});
|
|
const namespace = 'plugin-login';
|
|
|
|
const absRuntimeFilePath = `${namespace}/runtime.js`;
|
|
let generatedOnce = false;
|
|
api.onGenerateFiles(() => {
|
|
if (generatedOnce) return;
|
|
generatedOnce = true;
|
|
let content = readFileSync(join(__dirname, 'runtime', 'runtime.js'), 'utf-8');
|
|
if (pkgs.find((item) => item.includes('@fesjs/plugin-access'))) {
|
|
content = content.replace(
|
|
'// ACCESS',
|
|
`export function access(memo) {
|
|
const { loginPath } = getLoginConfig();
|
|
memo.ignoreAccess = (memo.ignoreAccess || []).concat(loginPath);
|
|
return memo;
|
|
}`,
|
|
);
|
|
}
|
|
api.writeTmpFile({
|
|
path: absRuntimeFilePath,
|
|
content,
|
|
});
|
|
});
|
|
|
|
api.addRuntimePlugin(() => `@@/${absRuntimeFilePath}`);
|
|
|
|
api.addConfigType(() => ({
|
|
source: name,
|
|
}));
|
|
};
|