2026-07-02 05:38:01 +08:00
|
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
|
|
|
|
import path from 'path'
|
|
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
2026-07-02 17:53:58 +08:00
|
|
|
|
base: '/pms/',
|
2026-09-19 23:40:46 +08:00
|
|
|
|
plugins: [
|
|
|
|
|
|
react(),
|
|
|
|
|
|
tailwindcss(),
|
|
|
|
|
|
// React 19 兼容:patch react-dom CJS 文件,补充 render/createRoot/unmountComponentAtNode
|
|
|
|
|
|
// 不用 require() 因为 Rolldown 异步加载导致顺序问题,改用懒加载 getCreateRoot()
|
|
|
|
|
|
{
|
|
|
|
|
|
name: 'react-dom-compat',
|
|
|
|
|
|
enforce: 'pre',
|
|
|
|
|
|
transform(code, id) {
|
|
|
|
|
|
if (id.includes('react-dom') && (id.endsWith('.production.js') || id.endsWith('.development.js')) && !id.includes('client')) {
|
|
|
|
|
|
const isDev = id.endsWith('.development.js')
|
|
|
|
|
|
const clientFile = isDev ? './react-dom-client.development.js' : './react-dom-client.production.js'
|
|
|
|
|
|
// 用懒加载方式获取 createRoot,避免模块加载顺序问题
|
|
|
|
|
|
const patch = `
|
|
|
|
|
|
var _rdc_cache;
|
|
|
|
|
|
function _getRDC() {
|
|
|
|
|
|
if (!_rdc_cache) _rdc_cache = require('${clientFile}');
|
|
|
|
|
|
return _rdc_cache;
|
|
|
|
|
|
}
|
|
|
|
|
|
Object.defineProperty(exports, 'createRoot', {
|
|
|
|
|
|
get: function() { return _getRDC().createRoot; }
|
|
|
|
|
|
});
|
|
|
|
|
|
exports.render = function(element, container) {
|
|
|
|
|
|
var root = _getRDC().createRoot(container);
|
|
|
|
|
|
root.render(element);
|
|
|
|
|
|
return root;
|
|
|
|
|
|
};
|
|
|
|
|
|
exports.unmountComponentAtNode = function() { return true; };
|
|
|
|
|
|
`
|
|
|
|
|
|
return code + patch
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
],
|
2026-07-02 05:38:01 +08:00
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: {
|
|
|
|
|
|
'@': path.resolve(__dirname, 'src'),
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
server: {
|
|
|
|
|
|
port: 5173,
|
|
|
|
|
|
proxy: {
|
|
|
|
|
|
'/api': {
|
|
|
|
|
|
target: 'http://localhost:3000',
|
|
|
|
|
|
changeOrigin: true,
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
},
|
|
|
|
|
|
})
|