代码拉取完成,页面将自动刷新
import legacy from '@vitejs/plugin-legacy';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig, loadEnv } from 'vite';
import eslintPlugin from 'vite-plugin-eslint';
import Inspect from 'vite-plugin-inspect';
import progress from 'vite-plugin-progress';
import { wrapperEnv } from './src/utils/getEnv';
// https://vitejs.dev/config/
export default defineConfig(mode => {
const env = loadEnv(mode.mode, process.cwd());
const viteEnv = wrapperEnv(env);
return {
base: viteEnv.VITE_BASE,
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
},
},
css: {
devSourcemap: true,
preprocessorOptions: {
scss: {},
less: {
// modifyVars: {
// "primary-color": "#1DA57A",
// },
javascriptEnabled: true,
additionalData: `@import "@/styles/var.less";`,
},
},
},
server: {
host: '0.0.0.0', // 服务器主机名,如果允许外部访问,可设置为"0.0.0.0"
port: viteEnv.VITE_PORT,
open: viteEnv.VITE_OPEN,
cors: true,
hmr: {
// overlay: false,
},
proxy: {
'/base-web': {
target: 'http://www.jxkj-ai.com/',
// target: 'http://192.168.2.57:6888/',
// target: 'http://base.xueduoduo.com/',
// target: "http://192.168.2.7:7770/",
changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, "")
configure: proxy => {
proxy.on('proxyReq', proxyReq => {
// console.log(
// `代理请求:${proxyReq.method}${proxyReq.protocol}${proxyReq.host}${proxyReq.path}`
// );
});
},
},
// 字符串简写写法:http://localhost:5173/foo -> http://localhost:4567/foo
'/foo': 'http://localhost:4567',
// 带选项写法:http://localhost:5173/api/bar -> http://jsonplaceholder.typicode.com/bar
'/api': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ''),
},
// 正则表达式写法:http://localhost:5173/fallback/ -> http://jsonplaceholder.typicode.com/
'^/fallback/.*': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
rewrite: path => path.replace(/^\/fallback/, ''),
},
// 使用 proxy 实例
'/apiqwe': {
target: 'http://jsonplaceholder.typicode.com',
changeOrigin: true,
configure: (proxy, options) => {
// proxy 是 'http-proxy' 的实例
},
},
// 代理 websockets 或 socket.io 写法:ws://localhost:5173/socket.io -> ws://localhost:5174/socket.io
'/socket.io': {
target: 'ws://localhost:5174',
ws: true,
},
},
},
plugins: [
react(),
eslintPlugin(),
progress(),
Inspect(),
visualizer({
open: false,
}),
legacy({
targets: ['chrome > 52'],
additionalLegacyPolyfills: ['regenerator-runtime/runtime'],
renderLegacyChunks: true,
polyfills: [
'es.symbol',
'es.promise',
'es.promise.finally',
'es/map',
'es/set',
'es.array.filter',
'es.array.for-each',
'es.array.flat-map',
'es.object.define-properties',
'es.object.define-property',
'es.object.get-own-property-descriptor',
'es.object.get-own-property-descriptors',
'es.object.keys',
'es.object.to-string',
'web.dom-collections.for-each',
'esnext.global-this',
'esnext.string.match-all',
'es.array.flat-map',
],
}),
],
build: {
target: 'es2015',
assetsDir: 'spa',
outDir: 'dist/spa',
minify: 'terser',
terserOptions: {
compress: {
drop_console: viteEnv.VITE_DROP_CONSOLE,
drop_debugger: viteEnv.VITE_DROP_DEBUGGER,
},
},
rollupOptions: {
output: {
// Static resource classification and packaging
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
},
},
},
};
});
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。