mirror of
https://github.com/Lifeforge-app/lifeforge.git
synced 2026-06-29 15:25:50 +00:00
129 lines
3.1 KiB
TypeScript
129 lines
3.1 KiB
TypeScript
// import MillionLint from '@million/lint'
|
|
import tailwindcss from '@tailwindcss/vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import { globSync } from 'glob'
|
|
import path from 'node:path'
|
|
import { type Alias, defineConfig } from 'vite'
|
|
|
|
const ReactCompilerConfig = {
|
|
sources: filename => {
|
|
return true
|
|
}
|
|
}
|
|
|
|
export const alias: Alias[] = [
|
|
{
|
|
find: '@providers',
|
|
replacement: path.resolve(__dirname, './src/providers')
|
|
},
|
|
{ find: '@utils', replacement: path.resolve(__dirname, './src/utils') },
|
|
{ find: '@apps', replacement: path.resolve(__dirname, './src/apps') },
|
|
{ find: '@server', replacement: path.resolve(__dirname, '../server/src') },
|
|
{ find: '@modules', replacement: path.resolve(__dirname, '../apps') },
|
|
{
|
|
find: '@',
|
|
replacement: '@',
|
|
customResolver: (id, importer, options) => {
|
|
let rootDir = ''
|
|
const isAppModule =
|
|
importer?.includes('/apps/') &&
|
|
importer?.includes('/client/') &&
|
|
!importer?.includes('/client/src/')
|
|
|
|
if (importer?.endsWith('manifest.ts')) {
|
|
rootDir = importer.replace('manifest.ts', 'client/')
|
|
} else if (isAppModule) {
|
|
const clientMatch = importer?.match(/(.+\/client)\//)
|
|
rootDir = clientMatch?.[1] || ''
|
|
} else {
|
|
rootDir = importer?.split('/src/')[0] + '/src' || ''
|
|
}
|
|
|
|
const matched = globSync([
|
|
path.resolve(rootDir, id.slice(2) + '.{tsx,ts,json}'),
|
|
path.resolve(rootDir, id.slice(2), 'index.{tsx,ts}'),
|
|
path.resolve(rootDir, id.slice(2))
|
|
])
|
|
if (!matched[0]) {
|
|
console.log([
|
|
path.resolve(rootDir, id.slice(2) + '.{tsx,ts,json}'),
|
|
path.resolve(rootDir, id.slice(2), 'index.{tsx,ts}'),
|
|
path.resolve(rootDir, id.slice(2))
|
|
])
|
|
console.log(
|
|
`[vite] failed to resolve import "${id}" from "${importer}"`
|
|
)
|
|
return null
|
|
}
|
|
return matched[0]
|
|
}
|
|
}
|
|
]
|
|
|
|
export default defineConfig({
|
|
envDir: path.resolve(__dirname, '../env'),
|
|
plugins: [
|
|
// MillionLint.vite({}),
|
|
react({
|
|
babel: {
|
|
plugins: [['babel-plugin-react-compiler', ReactCompilerConfig]]
|
|
}
|
|
}),
|
|
tailwindcss()
|
|
],
|
|
server: {
|
|
fs: {
|
|
strict: true
|
|
},
|
|
watch: {
|
|
ignored: ['**/node_modules/**', '**/.git/**']
|
|
}
|
|
},
|
|
resolve: {
|
|
alias
|
|
},
|
|
build: {
|
|
commonjsOptions: {
|
|
transformMixedEsModules: true
|
|
},
|
|
target: 'esnext',
|
|
sourcemap: false,
|
|
rollupOptions: {
|
|
output: {
|
|
manualChunks(id) {
|
|
if (id.includes('node_modules')) {
|
|
return id
|
|
.toString()
|
|
.split('node_modules/')
|
|
.pop()!
|
|
.split('/')[0]
|
|
.toString()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
optimizeDeps: {
|
|
esbuildOptions: {
|
|
sourcemap: false,
|
|
target: 'esnext'
|
|
}
|
|
},
|
|
css: {
|
|
postcss: {
|
|
plugins: [
|
|
{
|
|
postcssPlugin: 'internal:charset-removal',
|
|
AtRule: {
|
|
charset: atRule => {
|
|
if (atRule.name === 'charset') {
|
|
atRule.remove()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
]
|
|
}
|
|
}
|
|
})
|