Commit d84a7adb authored by 邓晓峰's avatar 邓晓峰

feat: 代理添加热更新

parent c8acba2c
......@@ -12,7 +12,7 @@ const mockMiddewares = require('./mock');
const emitter = require('./event');
const Server = require('./server');
const debug = createDebug('preset-build-in:proxy:createMiddleware');
const proxyConfig = require('../config/proxy');
// const proxyConfig = require('../config/proxy');
const loadDotEnv = require('./utils/loadDotEnv');
const { getSchema } = require('./openapi');
const cleanRequireCache = require('./utils/cleanRequireCache');
......@@ -113,12 +113,12 @@ const cleanRequireCache = require('./utils/cleanRequireCache');
const errors = [];
watcher.on('ready', () => debug('Initial scan complete. Ready for changes')).on('all', async (event, file) => {
debug(`[${event}] ${file}, reload proxy config`);
debug(`[${event}] ${file}, reload proxy config`);``
errors.splice(0, errors.length);
cleanRequireCache(proxyWatcherPaths);
// eslint-disable-next-line no-const-assign
cleanRequireCache(Array.from(new Set(proxyWatcherPaths)));
if (!errors.length) {
server.setupProxy && server.setupProxy(proxyConfig[process.env.NODE_ENV], true);
const hotProxy = require('../config/proxy');
server.setupProxy && server.setupProxy(hotProxy[process.env.NODE_ENV], true);
signale.success(`Proxy config parse success`);
}
});
......
......@@ -134,7 +134,7 @@ class Server {
);
}
setupProxy(proxyOpts, isWatch = true) {
setupProxy(proxyOpts, isWatch = false) {
let proxy = proxyOpts || this.opts.proxy;
if (!Array.isArray(proxy)) {
if (proxy && 'target' in proxy) {
......
const { winPath } = require('@umijs/utils')
function cleanRequireCache(paths) {
Object.keys(require.cache).forEach(file => {
if (paths.some(p => winPath(file).indexOf(p) > -1)) {
console.log(file);
delete require.cache[file];
}
});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment