56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { defineConfig } from 'vite';
|
|
import path from 'path';
|
|
import tailwindcss from '@tailwindcss/vite';
|
|
|
|
import pkgs from './package.json' with { type: 'json' };
|
|
const version = pkgs.version || '0.0.1';
|
|
const isDev = process.env.NODE_ENV === 'development';
|
|
console.log('isDev', isDev);
|
|
export default defineConfig({
|
|
root: '.',
|
|
plugins: [tailwindcss()],
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, './src'),
|
|
// react: './utils/h.ts', // 将 react 替换为自定义的 JSX 库
|
|
// 'react-dom': './utils/h.ts', // 将 react-dom 替换为自定义的 JSX 库
|
|
// 上到下,上面的先被匹配
|
|
// '@kevisual/store/config': 'https://kevisual.xiongxiao.me/system/lib/web-config.js', // 将本地路径替换为远程 URL
|
|
// '@kevisual/store/context': 'https://kevisual.xiongxiao.me/system/lib/web-context.js', // 将本地路径替换为远程 URL
|
|
// '@kevisual/store': 'https://kevisual.xiongxiao.me/system/lib/store.js', // 将本地路径替换为远程 URL
|
|
// '@kevisual/router/browser': 'https://kevisual.xiongxiao.me/system/lib/router-browser.js', // 将本地路径替换为远程 URL
|
|
},
|
|
},
|
|
base: './',
|
|
build: {
|
|
minify: false,
|
|
outDir: './dist',
|
|
rollupOptions: {
|
|
external: ['react'],
|
|
output: {
|
|
chunkFileNames: (chunkInfo) => {
|
|
if(isDev) {
|
|
return '[name].js';
|
|
}
|
|
if (chunkInfo.facadeModuleId && chunkInfo.facadeModuleId.includes('/routes/')) {
|
|
// 对以 routes/ 开头的代码分块使用不带 hash 的命名
|
|
return `routes/[name]-${version}.js`;
|
|
}
|
|
// 其他代码分块继续使用 hash
|
|
return '[name].[hash].js';
|
|
},
|
|
},
|
|
},
|
|
},
|
|
optimizeDeps: {
|
|
exclude: ['react'], // 排除 react 和 react-dom 以避免打包
|
|
},
|
|
esbuild: {
|
|
jsxFactory: 'h',
|
|
jsxFragment: 'Fragment',
|
|
},
|
|
server: {
|
|
port: 5002,
|
|
},
|
|
});
|