fix: 修复vite热更新问题

This commit is contained in:
winixt 2022-05-13 16:54:26 +08:00
parent b12f86bbbf
commit 7da7a348e2

View File

@ -36,16 +36,21 @@ export default function (api) {
}, },
}); });
const cacheCopyPath = {};
api.registerMethod({ api.registerMethod({
name: 'copyTmpFiles', name: 'copyTmpFiles',
fn({ namespace, path, ignore }) { fn({ namespace, path, ignore }) {
const base = join(api.paths.absTmpPath, namespace);
// copy 行为只需要执行一次
if (cacheCopyPath[base]) return;
cacheCopyPath[base] = true;
assert(api.stage >= api.ServiceStage.pluginReady, 'api.copyTmpFiles() should not execute in register stage.'); assert(api.stage >= api.ServiceStage.pluginReady, 'api.copyTmpFiles() should not execute in register stage.');
assert(path, 'api.copyTmpFiles() should has param path'); assert(path, 'api.copyTmpFiles() should has param path');
assert(namespace, 'api.copyTmpFiles() should has param namespace'); assert(namespace, 'api.copyTmpFiles() should has param namespace');
const files = api.utils.glob.sync('**/*', { const files = api.utils.glob.sync('**/*', {
cwd: path, cwd: path,
}); });
const base = join(api.paths.absTmpPath, namespace);
files.forEach((file) => { files.forEach((file) => {
const source = join(path, file); const source = join(path, file);
const target = join(base, file); const target = join(base, file);