Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

perf(web): lazy-load Vite plugins (#38663)

Stephen Zhou6f47950fe205
diff --git a/web/vite.config.ts b/web/vite.config.ts
index a4d3df3c18f..ff6acfdf503 100644
--- a/web/vite.config.ts
+++ b/web/vite.config.ts
@@ -1,9 +1,5 @@
import { fileURLToPath } from 'node:url'
-import tailwindcss from '@tailwindcss/vite'
-import react from '@vitejs/plugin-react'
-import vinext from 'vinext'
-import Inspect from 'vite-plugin-inspect'
-import { defineConfig } from 'vite-plus'
+import { defineConfig, lazyPlugins } from 'vite-plus'
import { createCodeInspectorPlugin, createForceInspectorClientInjectionPlugin } from './plugins/vite/code-inspector.ts'
import { customI18nHmrPlugin } from './plugins/vite/custom-i18n-hmr.ts'
import { getRootClientInjectTarget } from './plugins/vite/inject-target.ts'
@@ -19,42 +15,57 @@ export default defineConfig(({ mode }) => {
|| process.argv.some(arg => arg.toLowerCase().includes('storybook'))
return {
- plugins: isTest
- ? [
+ plugins: lazyPlugins(async () => {
+ const { default: react } = await import('@vitejs/plugin-react')
+
+ if (isTest) {
+ return [
nextStaticImageTestPlugin({ projectRoot }),
react(),
{
// Stub .mdx files so components importing them can be unit-tested
name: 'mdx-stub',
enforce: 'pre',
- transform(_, id) {
+ transform(_: string, id: string) {
if (id.endsWith('.mdx'))
return { code: 'export default () => null', map: null }
},
},
]
- : isStorybook
- ? [
- react(),
- ]
- : [
- Inspect(),
- createCodeInspectorPlugin({
- injectTarget: rootClientInjectTarget,
- }),
- createForceInspectorClientInjectionPlugin({
- injectTarget: rootClientInjectTarget,
- projectRoot,
- }),
- tailwindcss(),
- react(),
- vinext({ react: false }),
- customI18nHmrPlugin({ injectTarget: rootClientInjectTarget }),
- // reactGrabOpenFilePlugin({
- // injectTarget: rootClientInjectTarget,
- // projectRoot,
- // }),
- ],
+ }
+
+ if (isStorybook)
+ return [react()]
+
+ const [
+ { default: tailwindcss },
+ { default: vinext },
+ { default: Inspect },
+ ] = await Promise.all([
+ import('@tailwindcss/vite'),
+ import('vinext'),
+ import('vite-plugin-inspect'),
+ ])
+
+ return [
+ Inspect(),
+ createCodeInspectorPlugin({
+ injectTarget: rootClientInjectTarget,
+ }),
+ createForceInspectorClientInjectionPlugin({
+ injectTarget: rootClientInjectTarget,
+ projectRoot,
+ }),
+ tailwindcss(),
+ react(),
+ vinext({ react: false }),
+ customI18nHmrPlugin({ injectTarget: rootClientInjectTarget }),
+ // reactGrabOpenFilePlugin({
+ // injectTarget: rootClientInjectTarget,
+ // projectRoot,
+ // }),
+ ]
+ }),
resolve: {
tsconfigPaths: true,
alias: [