mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 10:38:32 +08:00
perf(web): lazy-load Vite plugins (#38663)
This commit is contained in:
parent
4043adacd7
commit
6f47950fe2
@ -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: [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user