123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import { resolve } from 'path'
- import fs from 'fs';
- import AutoImport from 'unplugin-auto-import/vite'
- import Components from 'unplugin-vue-components/vite'
- import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
- import Icons from 'unplugin-icons/vite'
- import IconsResolver from 'unplugin-icons/resolver'
- import topLevelAwait from 'vite-plugin-top-level-await'
- // 手动导入
- import ElementPlus from 'unplugin-element-plus/vite'
- // https://vitejs.dev/config/
- export default defineConfig(({ mode}) => {
- return{
- base: './',
- css: {
- preprocessorOptions: {
- scss: {
- // 自定义的主题色
- additionalData: `@use "@/assets/style/element/index.scss" as *;`,
- },
- },
- },
- plugins: [
- vue(),
- ElementPlus({
- useSource: true,
- }),
- AutoImport({
- imports: ["vue", "vue-router"],
- resolvers: [
- IconsResolver(),
- ElementPlusResolver({
- // 自动引入修改主题色添加这一行,使用预处理样式,不添加将会导致使用ElMessage,ElNotification等组件时默认的主题色会覆盖自定义的主题色
- // importStyle: "sass",
- importStyle: mode === "development" ? false : "sass",
- })
- ],
- }),
- Components({
- resolvers: [
- IconsResolver(),
- ElementPlusResolver({
- // 自动引入修改主题色添加这一行,使用预处理样式
- // importStyle: "sass",
- importStyle: mode === "development" ? false : "sass",
- })
- ],
- }),
- Icons({
- autoInstall: true,
- }),
- topLevelAwait({
- // The export name of top-level await promise for each chunk module
- promiseExportName: '__tla',
- // The function to generate import names of top-level await promise in each chunk module
- promiseImportName: i => `__tla_${i}`
- })
- ],
- server: {
- host: '0.0.0.0', //解决“vite use `--host` to expose”
- port: 8080,
- open: false,
- hmr:true,
- cors: true, // 允许跨域
- proxy: {
- '/api': {
- target: "http://idea-ad.wenxingshuju.com",
- changeOrigin: true,
- secure: false,
- },
- }
- },
- resolve:{
- alias:[
- {
- find:'@',
- replacement:resolve(__dirname,'src')
- }
- ]
- },
- build: {
- outDir: "dist",
- // outDir:'../',
- // /** 打包后静态资源目录 */
- // assetsDir: "./static",
- sourcemap: false,
- minify: 'terser',
- chunkSizeWarningLimit: 1500,
- terserOptions: {
- compress: {
- drop_console: false,
- drop_debugger: false
- }
- },
- rollupOptions: {
- output: {
- manualChunks(id) {
- if (id.includes('node_modules')) {
- return id
- .toString()
- .split('node_modules/')[1]
- .split('/')[0]
- .toString();
- }
- },
- chunkFileNames: (chunkInfo) => {
- const facadeModuleId = chunkInfo.facadeModuleId
- ? chunkInfo.facadeModuleId.split('/')
- : [];
- const fileName =
- facadeModuleId[facadeModuleId.length - 2] || '[name]';
- return `js/${fileName}/[name].[hash].js`;
- }
- }
- }
- },
- }
- })
|