2026-01-26 12:20:14 +00:00
|
|
|
import path from 'node:path'
|
|
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
|
|
import react from '@vitejs/plugin-react'
|
2026-03-01 01:54:39 +00:00
|
|
|
import vinext from 'vinext'
|
2026-03-05 02:45:16 +00:00
|
|
|
import Inspect from 'vite-plugin-inspect'
|
2026-03-13 10:18:44 +00:00
|
|
|
import { defineConfig } from 'vite-plus'
|
2026-03-06 09:01:18 +00:00
|
|
|
import { createCodeInspectorPlugin, createForceInspectorClientInjectionPlugin } from './plugins/vite/code-inspector'
|
2026-03-06 06:54:24 +00:00
|
|
|
import { customI18nHmrPlugin } from './plugins/vite/custom-i18n-hmr'
|
2026-03-16 08:48:22 +00:00
|
|
|
import { nextStaticImageTestPlugin } from './plugins/vite/next-static-image-test'
|
2026-01-26 12:20:14 +00:00
|
|
|
|
2026-03-06 06:54:24 +00:00
|
|
|
const projectRoot = path.dirname(fileURLToPath(import.meta.url))
|
2026-03-01 01:54:39 +00:00
|
|
|
const isCI = !!process.env.CI
|
2026-03-06 06:54:24 +00:00
|
|
|
const browserInitializerInjectTarget = path.resolve(projectRoot, 'app/components/browser-initializer.tsx')
|
2026-03-05 02:45:16 +00:00
|
|
|
|
2026-03-01 01:54:39 +00:00
|
|
|
export default defineConfig(({ mode }) => {
|
2026-03-04 02:07:29 +00:00
|
|
|
const isTest = mode === 'test'
|
2026-03-05 08:13:02 +00:00
|
|
|
const isStorybook = process.env.STORYBOOK === 'true'
|
|
|
|
|
|| process.argv.some(arg => arg.toLowerCase().includes('storybook'))
|
2026-03-01 12:27:57 +00:00
|
|
|
|
2026-03-01 01:54:39 +00:00
|
|
|
return {
|
2026-03-04 02:07:29 +00:00
|
|
|
plugins: isTest
|
2026-03-01 01:54:39 +00:00
|
|
|
? [
|
2026-03-16 08:48:22 +00:00
|
|
|
nextStaticImageTestPlugin({ projectRoot }),
|
2026-03-01 01:54:39 +00:00
|
|
|
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 }
|
|
|
|
|
},
|
2026-03-06 06:54:24 +00:00
|
|
|
},
|
2026-03-01 01:54:39 +00:00
|
|
|
]
|
2026-03-05 08:13:02 +00:00
|
|
|
: isStorybook
|
|
|
|
|
? [
|
|
|
|
|
react(),
|
|
|
|
|
]
|
|
|
|
|
: [
|
|
|
|
|
Inspect(),
|
2026-03-06 09:01:18 +00:00
|
|
|
createCodeInspectorPlugin({
|
|
|
|
|
injectTarget: browserInitializerInjectTarget,
|
|
|
|
|
}),
|
|
|
|
|
createForceInspectorClientInjectionPlugin({
|
2026-03-06 06:54:24 +00:00
|
|
|
injectTarget: browserInitializerInjectTarget,
|
|
|
|
|
projectRoot,
|
|
|
|
|
}),
|
2026-03-13 04:52:19 +00:00
|
|
|
react(),
|
|
|
|
|
vinext({ react: false }),
|
2026-03-06 09:01:18 +00:00
|
|
|
customI18nHmrPlugin({ injectTarget: browserInitializerInjectTarget }),
|
|
|
|
|
// reactGrabOpenFilePlugin({
|
|
|
|
|
// injectTarget: browserInitializerInjectTarget,
|
|
|
|
|
// projectRoot,
|
|
|
|
|
// }),
|
2026-03-05 08:13:02 +00:00
|
|
|
],
|
2026-03-01 01:54:39 +00:00
|
|
|
resolve: {
|
2026-03-12 09:56:22 +00:00
|
|
|
tsconfigPaths: true,
|
2026-01-26 12:20:14 +00:00
|
|
|
},
|
2026-03-01 01:54:39 +00:00
|
|
|
|
|
|
|
|
// vinext related config
|
2026-03-05 08:13:02 +00:00
|
|
|
...(!isTest && !isStorybook
|
2026-03-01 01:54:39 +00:00
|
|
|
? {
|
|
|
|
|
optimizeDeps: {
|
2026-03-12 05:18:11 +00:00
|
|
|
exclude: ['@tanstack/react-query'],
|
2026-03-01 01:54:39 +00:00
|
|
|
},
|
|
|
|
|
server: {
|
|
|
|
|
port: 3000,
|
|
|
|
|
},
|
2026-03-03 13:42:47 +00:00
|
|
|
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'],
|
|
|
|
|
},
|
2026-03-01 01:54:39 +00:00
|
|
|
}
|
|
|
|
|
: {}),
|
|
|
|
|
|
|
|
|
|
// Vitest config
|
|
|
|
|
test: {
|
|
|
|
|
environment: 'jsdom',
|
|
|
|
|
globals: true,
|
|
|
|
|
setupFiles: ['./vitest.setup.ts'],
|
|
|
|
|
coverage: {
|
|
|
|
|
provider: 'v8',
|
|
|
|
|
reporter: isCI ? ['json', 'json-summary'] : ['text', 'json', 'json-summary'],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
2026-01-26 12:20:14 +00:00
|
|
|
})
|