const path = require('path'); const { replaceFileContent, rootDir, logSuccess, exit, logError, checkFileExist } = require('../helper'); const viteConfigPath = path.join(rootDir, 'vite.config.ts'); checkFileExist(viteConfigPath); replaceFileContent(viteConfigPath, (data) => { const pattern = /hmr\s*:\s*(true|false)\s*/; const isHmrStr = data.match(pattern)?.[1]; if (!isHmrStr) { logError(''); exit(); } const newData = data.replace(pattern, `hmr: ${isHmrStr === 'true' ? 'false' : 'true'}`); if (isHmrStr === 'true') { logSuccess('已关闭 hmr'); } else { logSuccess('已开启 hmr'); } return newData; });