116 lines
3.3 KiB
JavaScript
116 lines
3.3 KiB
JavaScript
import { defineConfig, loadEnv } from 'vite';
|
||
import vue from '@vitejs/plugin-vue';
|
||
import qiankun from 'vite-plugin-qiankun';
|
||
import eslintPlugin from 'vite-plugin-eslint';
|
||
import vueSetupExtend from 'vite-plugin-vue-setup-extend';
|
||
import compression from 'vite-plugin-compression';
|
||
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
|
||
import { createHtmlPlugin } from 'vite-plugin-html';
|
||
import AutoImport from 'unplugin-auto-import/vite';
|
||
import Components from 'unplugin-vue-components/vite';
|
||
import postcssImport from 'postcss-import';
|
||
import autoprefixer from 'autoprefixer';
|
||
import { resolve } from 'path';
|
||
|
||
export default defineConfig(({ command, mode }) => {
|
||
console.log('vite.config.js', command, mode, loadEnv(mode, process.cwd()));
|
||
const { VITE_PORT, VITE_APP_NAME, VITE_APP_BASE_API, VITE_APP_BASE_URL, VITE_APP_UPLOAD_API, VITE_APP_UPLOAD_URL } = loadEnv(mode, process.cwd());
|
||
const config = {
|
||
base: './',
|
||
build: {
|
||
target: 'ESNext',
|
||
outDir: 'dist',
|
||
minify: 'terser',
|
||
},
|
||
server: {
|
||
host: '0.0.0.0',
|
||
port: VITE_PORT,
|
||
open: true,
|
||
https: false,
|
||
headers: {
|
||
'Access-Control-Allow-Origin': '*',
|
||
},
|
||
proxy: {
|
||
// // 仅 Brand 模块走子应用 DevServer
|
||
// '/api/brand': {
|
||
// target: 'http://localhost:9526',
|
||
// changeOrigin: true,
|
||
// // 如果想去掉 /api/brand 前缀(比如子应用实际监听的是 /brand/...),
|
||
// // 可以加一个 rewrite:
|
||
// // rewrite: path => path.replace(/^\/api\/brand/, '/brand'),
|
||
// },
|
||
[VITE_APP_BASE_API]: {
|
||
target: VITE_APP_BASE_URL,
|
||
changeOrigin: true,
|
||
rewrite: (path) => path.replace(/^\/apis/, ''),
|
||
},
|
||
[VITE_APP_UPLOAD_API]: {
|
||
target: VITE_APP_UPLOAD_URL,
|
||
changeOrigin: true,
|
||
// rewrite: (path) => path.replace(/^\/uploadApis/, ''),
|
||
},
|
||
},
|
||
},
|
||
resolve: {
|
||
alias: {
|
||
'@': resolve(__dirname, 'src'),
|
||
},
|
||
extensions: ['.js', '.vue', '.json', '.ts'],
|
||
},
|
||
css: {
|
||
preprocessorOptions: {
|
||
scss: {
|
||
additionalData: '@import "@/styles/global.scss";',
|
||
api: 'modern-compiler',
|
||
},
|
||
},
|
||
postcss: {
|
||
plugins: [
|
||
postcssImport,
|
||
autoprefixer({
|
||
overrideBrowserslist: ['> 1%', 'last 2 versions'],
|
||
}),
|
||
],
|
||
},
|
||
},
|
||
plugins: [
|
||
vue(),
|
||
qiankun(),
|
||
vueSetupExtend(),
|
||
createHtmlPlugin({
|
||
inject: {
|
||
data: {
|
||
web_title: VITE_APP_NAME,
|
||
},
|
||
},
|
||
}),
|
||
eslintPlugin({
|
||
include: ['src/**/*.ts', 'src/**/*.vue', 'src/*.ts', 'src/*.vue'],
|
||
}),
|
||
Components({
|
||
dirs: ['src/components'],
|
||
extensions: ['vue', 'js', 'jsx', 'ts', 'tsx'],
|
||
resolvers: [],
|
||
}),
|
||
compression(),
|
||
AutoImport({
|
||
include: [/\.[tj]s?$/, /\.vue$/],
|
||
imports: ['vue', 'vue-router'],
|
||
}),
|
||
createSvgIconsPlugin({
|
||
iconDirs: [resolve(process.cwd(), 'src/assets/svgs')],
|
||
symbolId: 'icon-[name]',
|
||
}),
|
||
],
|
||
};
|
||
if (mode === 'production') {
|
||
config.build.terserOptions = {
|
||
compress: {
|
||
drop_console: true,
|
||
drop_debugger: true,
|
||
},
|
||
};
|
||
}
|
||
return config;
|
||
});
|