119 lines
2.9 KiB
TypeScript
119 lines
2.9 KiB
TypeScript
import uni from '@dcloudio/vite-plugin-uni';
|
|
import { loadEnv } from 'vite';
|
|
import viteCompression from 'vite-plugin-compression';
|
|
import path from 'path';
|
|
import uniReadPagesV3Plugin from './src/sheep/router/utils/uni-read-pages-v3';
|
|
// import mpliveMainfestPlugin from './src/sheep/libs/mplive-manifest-plugin';
|
|
|
|
// https://vitejs.dev/config/
|
|
export default async (command: 'build' | 'serve', mode: string) => {
|
|
const env = loadEnv(mode, __dirname, 'SHOPRO_');
|
|
const { default: Unocss } = await import('unocss/vite');
|
|
|
|
const isH5 = process.env.UNI_PLATFORM === 'h5';
|
|
|
|
if (isH5) {
|
|
return {
|
|
envPrefix: 'SHOPRO_',
|
|
plugins: [
|
|
uni(),
|
|
Unocss(),
|
|
viteCompression({
|
|
verbose: false,
|
|
}),
|
|
uniReadPagesV3Plugin({
|
|
pagesJsonDir: path.resolve(__dirname, './src/pages.json'),
|
|
includes: ['path', 'aliasPath', 'name', 'meta'],
|
|
}),
|
|
],
|
|
server: {
|
|
host: true,
|
|
hmr: {
|
|
overlay: true,
|
|
},
|
|
proxy: {
|
|
// 应用相关api
|
|
'/app-api': {
|
|
target: env.SHOPRO_DEV_BASE_URL,
|
|
changeOrigin: true,
|
|
},
|
|
// 聊天相关api
|
|
'/api': {
|
|
target: 'http://im-platform.htysapp.com',
|
|
changeOrigin: true,
|
|
rewrite: (path: string) => path.replace(/^\/api/, ''),
|
|
},
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, 'src'),
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
api: 'modern-compiler',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
} else {
|
|
return {
|
|
envPrefix: 'SHOPRO_',
|
|
plugins: [
|
|
uni(),
|
|
Unocss(),
|
|
viteCompression({
|
|
verbose: false,
|
|
}),
|
|
uniReadPagesV3Plugin({
|
|
pagesJsonDir: path.resolve(__dirname, './src/pages.json'),
|
|
includes: ['path', 'aliasPath', 'name', 'meta'],
|
|
}),
|
|
],
|
|
esbuild: {
|
|
target: 'es2015',
|
|
supported: {
|
|
'optional-chain': false,
|
|
'nullish-coalescing': false,
|
|
},
|
|
},
|
|
build: {
|
|
target: 'es2015',
|
|
},
|
|
server: {
|
|
host: true,
|
|
hmr: {
|
|
overlay: true,
|
|
},
|
|
proxy: {
|
|
// 应用相关api
|
|
'/app-api': {
|
|
target: env.SHOPRO_DEV_BASE_URL,
|
|
changeOrigin: true,
|
|
},
|
|
// 聊天相关api
|
|
'/api': {
|
|
target: 'http://im-platform.htysapp.com',
|
|
changeOrigin: true,
|
|
rewrite: (path: string) => path.replace(/^\/api/, ''),
|
|
},
|
|
},
|
|
},
|
|
resolve: {
|
|
alias: {
|
|
'@': path.resolve(__dirname, 'src'),
|
|
},
|
|
},
|
|
css: {
|
|
preprocessorOptions: {
|
|
scss: {
|
|
api: 'modern-compiler',
|
|
},
|
|
},
|
|
},
|
|
};
|
|
}
|
|
};
|