ant-design-vue/components/_util/cssinjs/hooks/useHMR.ts

42 lines
933 B
TypeScript
Raw Normal View History

2023-01-24 14:51:59 +00:00
function useProdHMR() {
return false;
}
let webpackHMR = false;
let viteHMR = false;
function useDevHMR() {
return webpackHMR || viteHMR;
}
export default process.env.NODE_ENV === 'production' ? useProdHMR : useDevHMR;
// Webpack `module.hot.accept` do not support any deps update trigger
// We have to hack handler to force mark as HRM
if (
process.env.NODE_ENV !== 'production' &&
2023-01-25 03:28:53 +00:00
((typeof module !== 'undefined' &&
module &&
// @ts-ignore
module.hot) ||
// @ts-ignore
import.meta.hot)
2023-01-24 14:51:59 +00:00
) {
const win = window as any;
if (typeof win.webpackHotUpdate === 'function') {
const originWebpackHotUpdate = win.webpackHotUpdate;
win.webpackHotUpdate = (...args: any[]) => {
webpackHMR = true;
setTimeout(() => {
webpackHMR = false;
}, 0);
return originWebpackHotUpdate(...args);
};
// @ts-ignore
} else if (import.meta.hot) {
2023-01-25 03:28:53 +00:00
viteHMR = true;
2023-01-24 14:51:59 +00:00
}
}