feat: enhance project configuration and add new features
This commit is contained in:
114
vite.config.ts
114
vite.config.ts
@@ -1,18 +1,110 @@
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
|
||||
import { defineConfig } from 'vite'
|
||||
import vue from '@vitejs/plugin-vue'
|
||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||
import vueDevTools from 'vite-plugin-vue-devtools'
|
||||
import { defineConfig, type DepOptimizationOptions } from 'vite'
|
||||
|
||||
import { cloudflare } from '@cloudflare/vite-plugin'
|
||||
import { createViteProxy } from 'utils4u/vite'
|
||||
import path from 'node:path'
|
||||
|
||||
import { Plugins } from './vite.config.plugins'
|
||||
|
||||
function formatFilename(id: string, prefix: string) {
|
||||
const filename = path
|
||||
.basename(id)
|
||||
.split('?')[0]
|
||||
.replace(/\.\w+$/, '')
|
||||
return `${prefix}/${filename}`
|
||||
}
|
||||
function isInNodeModules(id: string) {
|
||||
return id.includes('node_modules')
|
||||
}
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [vue(), vueJsx(), vueDevTools(), cloudflare()],
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
export default defineConfig(({ command /* mode */ }) => {
|
||||
const isBuild = command === 'build'
|
||||
// const env = loadEnv(mode, process.cwd())
|
||||
|
||||
return {
|
||||
build: {
|
||||
rolldownOptions: {
|
||||
output: {
|
||||
advancedChunks: {
|
||||
groups: [
|
||||
{
|
||||
name: (moduleId) => (moduleId.includes('node_modules') ? 'libss' : 'app'),
|
||||
// minSize: 100 * 1024,
|
||||
},
|
||||
{
|
||||
name: 'libs',
|
||||
test: /node_modules/,
|
||||
},
|
||||
// {
|
||||
// name: 'vue',
|
||||
// test: /node_modules[\\/]vue/,
|
||||
// },
|
||||
// {
|
||||
// name(moduleId, _ctx) {
|
||||
// if (isInNodeModules(moduleId)) {
|
||||
// let pkgName = moduleId
|
||||
// pkgName = pkgName.split('.pnpm/')?.[1] || pkgName
|
||||
// pkgName = pkgName.split('node_modules/')?.[1] || pkgName
|
||||
// pkgName = pkgName.startsWith('@')
|
||||
// ? pkgName.split('/')[0] + '/' + pkgName.split('/')[1]
|
||||
// : pkgName.split('/')[0]
|
||||
// if (pkgName.startsWith('@vue/')) pkgName = 'vue'
|
||||
// return `libs/${pkgName}`;
|
||||
// }
|
||||
// },
|
||||
// },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
// base: env.VITE_BASE,
|
||||
plugins: Plugins(),
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': fileURLToPath(new URL('./src', import.meta.url)),
|
||||
},
|
||||
},
|
||||
define: {
|
||||
__DEV__: JSON.stringify(!isBuild),
|
||||
},
|
||||
server: {
|
||||
allowedHosts: ['.nwct.dev'],
|
||||
proxy: createViteProxy(),
|
||||
},
|
||||
optimizeDeps: optimizeDeps(),
|
||||
}
|
||||
})
|
||||
|
||||
// const primevuecomponents = await (async () => {
|
||||
// const { components } = await import('@primevue/metadata')
|
||||
// return components.map((c) => c.from).filter((c) => c !== undefined)
|
||||
// })()
|
||||
function optimizeDeps(): DepOptimizationOptions {
|
||||
return {
|
||||
include: [
|
||||
// ...primevuecomponents,
|
||||
'@primeuix/themes',
|
||||
'@primeuix/themes/lara',
|
||||
'class-variance-authority',
|
||||
'clsx',
|
||||
'tailwind-merge',
|
||||
'reka-ui',
|
||||
'axios',
|
||||
'@ant-design/icons-vue',
|
||||
'ant-design-vue/es',
|
||||
'p5',
|
||||
'@splinetool/runtime',
|
||||
'satellite.js',
|
||||
'ts-enum-util',
|
||||
'unplugin-vue-router',
|
||||
'unplugin-vue-router/runtime',
|
||||
'unplugin-vue-router/data-loaders/basic',
|
||||
'unplugin-vue-router/data-loaders/pinia-colada',
|
||||
'eruda',
|
||||
],
|
||||
exclude: ['quill', 'chart.js/auto'],
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user