mirror of
https://github.com/langgenius/dify.git
synced 2026-03-07 08:35:58 +08:00
100 lines
2.9 KiB
TypeScript
100 lines
2.9 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 { customI18nHmrPlugin } from './plugins/vite/custom-i18n-hmr'
|
|
import { reactGrabOpenFilePlugin } from './plugins/vite/react-grab-open-file'
|
|
|
|
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(),
|
|
react(),
|
|
vinext(),
|
|
customI18nHmrPlugin({ injectTarget: browserInitializerInjectTarget }),
|
|
reactGrabOpenFilePlugin({
|
|
injectTarget: browserInitializerInjectTarget,
|
|
projectRoot,
|
|
}),
|
|
],
|
|
resolve: {
|
|
alias: {
|
|
'~@': projectRoot,
|
|
},
|
|
},
|
|
|
|
// vinext related config
|
|
...(!isTest && !isStorybook
|
|
? {
|
|
optimizeDeps: {
|
|
exclude: ['nuqs'],
|
|
// Make Prism in lexical works
|
|
// https://github.com/vitejs/rolldown-vite/issues/396
|
|
rolldownOptions: {
|
|
output: {
|
|
strictExecutionOrder: true,
|
|
},
|
|
},
|
|
},
|
|
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'],
|
|
},
|
|
// Make Prism in lexical works
|
|
// https://github.com/vitejs/rolldown-vite/issues/396
|
|
build: {
|
|
rolldownOptions: {
|
|
output: {
|
|
strictExecutionOrder: true,
|
|
},
|
|
},
|
|
},
|
|
}
|
|
: {}),
|
|
|
|
// Vitest config
|
|
test: {
|
|
environment: 'jsdom',
|
|
globals: true,
|
|
setupFiles: ['./vitest.setup.ts'],
|
|
coverage: {
|
|
provider: 'v8',
|
|
reporter: isCI ? ['json', 'json-summary'] : ['text', 'json', 'json-summary'],
|
|
},
|
|
},
|
|
}
|
|
})
|