mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
refactor: 优化 plugin 插件
This commit is contained in:
parent
df78d1dcac
commit
3620ee15b4
@ -4,19 +4,20 @@ const fs = require('fs');
|
|||||||
async function handleCacheClean(cwd) {
|
async function handleCacheClean(cwd) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const cachePath = path.join(cwd, '.cache/webpack');
|
const cachePath = path.join(cwd, '.cache/webpack');
|
||||||
if (fs.existsSync(cachePath)) {
|
if (!fs.existsSync(cachePath)) {
|
||||||
require('get-folder-size')(cachePath, (err, size) => {
|
return resolve();
|
||||||
if (err) {
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
// 大于 5G 清除缓存,修复 webpack 缓存无限增长问题
|
|
||||||
// https://github.com/webpack/webpack/issues/13291
|
|
||||||
if (size > 5 * 1024 * 1024 * 1024) {
|
|
||||||
require('fs-extra').removeSync(cachePath);
|
|
||||||
}
|
|
||||||
resolve(size);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
require('get-folder-size')(cachePath, (err, size) => {
|
||||||
|
if (err) {
|
||||||
|
return reject(err);
|
||||||
|
}
|
||||||
|
// 大于 5G 清除缓存,修复 webpack 缓存无限增长问题
|
||||||
|
// https://github.com/webpack/webpack/issues/13291
|
||||||
|
if (size > 5 * 1024 * 1024 * 1024) {
|
||||||
|
require('fs-extra').removeSync(cachePath);
|
||||||
|
}
|
||||||
|
resolve(size);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
copy: ['runtime'],
|
|
||||||
};
|
|
@ -1,9 +1,13 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
import { readFileSync } from 'fs';
|
||||||
import { name } from '../package.json';
|
import { name } from '../package.json';
|
||||||
|
|
||||||
export default (api) => {
|
export default (api) => {
|
||||||
api.addRuntimePluginKey(() => 'login');
|
api.addRuntimePluginKey(() => 'login');
|
||||||
|
const pkgs = Object.keys({
|
||||||
|
...api.pkg.dependencies,
|
||||||
|
...api.pkg.devDependencies,
|
||||||
|
});
|
||||||
const namespace = 'plugin-login';
|
const namespace = 'plugin-login';
|
||||||
|
|
||||||
const absRuntimeFilePath = `${namespace}/runtime.js`;
|
const absRuntimeFilePath = `${namespace}/runtime.js`;
|
||||||
@ -11,9 +15,20 @@ export default (api) => {
|
|||||||
api.onGenerateFiles(() => {
|
api.onGenerateFiles(() => {
|
||||||
if (generatedOnce) return;
|
if (generatedOnce) return;
|
||||||
generatedOnce = true;
|
generatedOnce = true;
|
||||||
api.copyTmpFiles({
|
let content = readFileSync(join(__dirname, 'runtime', 'runtime.js'), 'utf-8');
|
||||||
namespace,
|
if (pkgs.find((item) => item.includes('@fesjs/plugin-access'))) {
|
||||||
path: join(__dirname, 'runtime'),
|
content = content.replace(
|
||||||
|
'// ACCESS',
|
||||||
|
`export function access(memo) {
|
||||||
|
const { loginPath } = getLoginConfig();
|
||||||
|
memo.ignoreAccess = (memo.ignoreAccess || []).concat(loginPath);
|
||||||
|
return memo;
|
||||||
|
}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
api.writeTmpFile({
|
||||||
|
path: absRuntimeFilePath,
|
||||||
|
content,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -14,11 +14,7 @@ function getLoginConfig() {
|
|||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function access(memo) {
|
// ACCESS
|
||||||
const { loginPath } = getLoginConfig();
|
|
||||||
memo.ignoreAccess = (memo.ignoreAccess || []).concat(loginPath);
|
|
||||||
return memo;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function request(memo) {
|
export function request(memo) {
|
||||||
if (!memo.responseInterceptors) {
|
if (!memo.responseInterceptors) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user