vue3 网站访问页面缓存优化

vite.config.js

javascript 复制代码
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'
//引入path用于写别名配置,自带无须安装
import path from 'path'
//使用svg-icons插件
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
// eslint
import eslintPlugin from 'vite-plugin-eslint'
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '') // 仅加载以 VITE_ 开头的环境变量
  console.log('Current mode:', env)
  return {
    build: {
      outDir: 'dist',
      assetsDir: 'assets',
      rollupOptions: {
        output: {
          entryFileNames: `assets/[name]-${env.VITE_APP_VERSION}-[hash].js`,
          chunkFileNames: `assets/[name]-${env.VITE_APP_VERSION}-[hash][hash].js`,
          assetFileNames: `assets/[name]-${env.VITE_APP_VERSION}-[hash][hash].[ext]`
        }
      }
    },
    plugins: [
      vue(),
      // 注册所有的svg文件生成svg雪碧图
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')], //svg图片存放的目录
        symbolId: 'icon-[name]', // symbol的id
        inject: 'body-last', // 插入的位置
        customDomId: '__svg__icons__dom__' // svg的id
      }),
      // eslint引入
      eslintPlugin({
        include:['src/**/*.js','src/**/*.vue','src/*.vue','src/*.vue']
      })
    ],
    'process.env': {},
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    }
  }
})
相关推荐
不像程序员的程序媛2 小时前
Nginx日志切分
服务器·前端·nginx
Daniel李华2 小时前
echarts使用案例
android·javascript·echarts
北原_春希2 小时前
如何在Vue3项目中引入并使用Echarts图表
前端·javascript·echarts
JY-HPS2 小时前
echarts天气折线图
javascript·vue.js·echarts
尽意啊2 小时前
echarts树图动态添加子节点
前端·javascript·echarts
吃面必吃蒜2 小时前
echarts 极坐标柱状图 如何定义柱子颜色
前端·javascript·echarts
O_oStayPositive2 小时前
Vue3使用ECharts
前端·javascript·echarts
竹秋…2 小时前
echarts自定义tooltip中的内容
前端·javascript·echarts
宝贝露.2 小时前
Axure引入Echarts图无法正常显示问题
前端·javascript·echarts
shmily麻瓜小菜鸡2 小时前
前端文字转语音
前端