我正在将我的应用程序从 Webpack 迁移到 Vite。在大多数情况下,一切都很顺利,但我遇到了react-dnd 的问题。有趣的是,这个问题仅在我本地运行应用程序时出现。
下面是我在 vite.config.ts 中使用的配置:
export default defineConfig({
plugins: [react(), tsconfigPaths(), splitVendorChunkPlugin(), mkcert({
hosts: ['localhost','127.0.0.1'],
savePath: './.cache/certs',
})],
server: {
proxy: {
'/www': {
target: 'https://localhost:5000',
changeOrigin: true,
secure: false,
},
},
open: false,
https: true,
watch: {
ignored: ['**/.env', '**/.env.*', '**/coverage', '**/tsconfig.*', 'src/server/**/*'],
},
},
define: {
'window.global': {},
'process.env': {},
},
build: {
sourcemap: false,
commonjsOptions: {
transformMixedEsModules: true,
},
outDir: 'build',
},
});
任何使用react-dnd解决问题的见解或建议将不胜感激!
对于那些遇到类似问题的人,我在这个 Stack Overflow 答案中找到了解决方案,并删除了
'process.env': {}
。
您可以像这样修改您的配置:
define: {
global: 'window',
}
这次调整解决了我的问题。
非常感谢您为我提供的解决方案。