diff --git a/packages/fes-builder-webpack/src/plugins/commands/dev/index.js b/packages/fes-builder-webpack/src/plugins/commands/dev/index.js index ae628df0..66a01005 100644 --- a/packages/fes-builder-webpack/src/plugins/commands/dev/index.js +++ b/packages/fes-builder-webpack/src/plugins/commands/dev/index.js @@ -4,19 +4,20 @@ const fs = require('fs'); async function handleCacheClean(cwd) { return new Promise((resolve, reject) => { const cachePath = path.join(cwd, '.cache/webpack'); - if (fs.existsSync(cachePath)) { - 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); - }); + if (!fs.existsSync(cachePath)) { + return resolve(); } + 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); + }); }); } diff --git a/packages/fes-plugin-login/build.config.js b/packages/fes-plugin-login/build.config.js deleted file mode 100644 index 87b511e5..00000000 --- a/packages/fes-plugin-login/build.config.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = { - copy: ['runtime'], -}; diff --git a/packages/fes-plugin-login/src/index.js b/packages/fes-plugin-login/src/index.js index 90e04faf..2ee1ee00 100644 --- a/packages/fes-plugin-login/src/index.js +++ b/packages/fes-plugin-login/src/index.js @@ -1,9 +1,13 @@ 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`; @@ -11,9 +15,20 @@ export default (api) => { api.onGenerateFiles(() => { if (generatedOnce) return; generatedOnce = true; - api.copyTmpFiles({ - namespace, - path: join(__dirname, 'runtime'), + 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, }); }); diff --git a/packages/fes-plugin-login/src/runtime/runtime.js b/packages/fes-plugin-login/src/runtime/runtime.js index 243282fe..dc98263e 100644 --- a/packages/fes-plugin-login/src/runtime/runtime.js +++ b/packages/fes-plugin-login/src/runtime/runtime.js @@ -14,11 +14,7 @@ function getLoginConfig() { return config; } -export function access(memo) { - const { loginPath } = getLoginConfig(); - memo.ignoreAccess = (memo.ignoreAccess || []).concat(loginPath); - return memo; -} +// ACCESS export function request(memo) { if (!memo.responseInterceptors) {