mirror of
https://github.com/langgenius/dify.git
synced 2026-03-13 02:57:41 +08:00
90 lines
2.7 KiB
TypeScript
90 lines
2.7 KiB
TypeScript
import path from 'node:path'
|
|
import { fileURLToPath } from 'node:url'
|
|
import react from '@vitejs/plugin-react'
|
|
import vinext from 'vinext'
|
|
import { defineConfig } from 'vite'
|
|
import Inspect from 'vite-plugin-inspect'
|
|
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
import { createCodeInspectorPlugin, createForceInspectorClientInjectionPlugin } from './plugins/vite/code-inspector'
|
|
import { customI18nHmrPlugin } from './plugins/vite/custom-i18n-hmr'
|
|
|
|
const projectRoot = path.dirname(fileURLToPath(import.meta.url))
|
|
const isCI = !!process.env.CI
|
|
const browserInitializerInjectTarget = path.resolve(projectRoot, 'app/components/browser-initializer.tsx')
|
|
|
|
export default defineConfig(({ mode }) => {
|
|
const isTest = mode === 'test'
|
|
const isStorybook = process.env.STORYBOOK === 'true'
|
|
|| process.argv.some(arg => arg.toLowerCase().includes('storybook'))
|
|
|
|
return {
|
|
plugins: isTest
|
|
? [
|
|
tsconfigPaths(),
|
|
react(),
|
|
{
|
|
// Stub .mdx files so components importing them can be unit-tested
|
|
name: 'mdx-stub',
|
|
enforce: 'pre',
|
|
transform(_, id) {
|
|
if (id.endsWith('.mdx'))
|
|
return { code: 'export default () => null', map: null }
|
|
},
|
|
},
|
|
]
|
|
: isStorybook
|
|
? [
|
|
tsconfigPaths(),
|
|
react(),
|
|
]
|
|
: [
|
|
Inspect(),
|
|
createCodeInspectorPlugin({
|
|
injectTarget: browserInitializerInjectTarget,
|
|
}),
|
|
createForceInspectorClientInjectionPlugin({
|
|
injectTarget: browserInitializerInjectTarget,
|
|
projectRoot,
|
|
}),
|
|
vinext(),
|
|
customI18nHmrPlugin({ injectTarget: browserInitializerInjectTarget }),
|
|
// reactGrabOpenFilePlugin({
|
|
// injectTarget: browserInitializerInjectTarget,
|
|
// projectRoot,
|
|
// }),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'~@': projectRoot,
|
|
},
|
|
},
|
|
|
|
// vinext related config
|
|
...(!isTest && !isStorybook
|
|
? {
|
|
optimizeDeps: {
|
|
exclude: ['nuqs'],
|
|
},
|
|
server: {
|
|
port: 3000,
|
|
},
|
|
ssr: {
|
|
// SyntaxError: Named export not found. The requested module is a CommonJS module, which may not support all module.exports as named exports
|
|
noExternal: ['emoji-mart'],
|
|
},
|
|
}
|
|
: {}),
|
|
|
|
// Vitest config
|
|
test: {
|
|
environment: 'jsdom',
|
|
globals: true,
|
|
setupFiles: ['./vitest.setup.ts'],
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: isCI ? ['json', 'json-summary'] : ['text', 'json', 'json-summary'],
|
|
},
|
|
},
|
|
}
|
|
})
|