0

I want to implement the cache negotiation for the public folder in the root directory. I configured it as follows in nuxt.config.ts. However, after running pnpm dev and pnpm generate, and then npx serve .vercel/output/static, I found that the cache was not implemented. Every time I get the resources in the public directory, data is transmitted in the network console. Is there any friend willing to answer my questions?

my nuxt.config.ts:

import AutoImport from 'unplugin-auto-import/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
const env = import.meta.env.NODE_ENV;

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  modules: [
    'nuxtjs-naive-ui',
    '@pinia/nuxt',
    'pinia-plugin-persistedstate/nuxt',
    '@nuxtjs/tailwindcss',
    '@nuxt/eslint',
    '@nuxt/icon'
  ],
  app: {
    baseURL: '/',
    pageTransition: { name: 'page', mode: 'out-in' },
    head: {
      viewport: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover',
      meta: [
        { name: 'format-detection', content: 'telephone=no' },
        { name: 'msapplication-tap-highlight', content: 'no' },
        { name: 'apple-mobile-web-app-capable', content: 'yes' },
        { name: 'apple-mobile-web-app-status-bar-style', content: 'black-translucent' },
        { name: 'apple-touch-fullscreen', content: 'yes' },
        { name: 'theme-color', content: '#0f172a' },
        { name: 'msapplication-TileColor', content: '#0f172a' },
        { 'http-equiv': 'X-UA-Compatible', content: 'IE=edge' },
        { name: 'renderer', content: 'webkit' }
      ]
    }
  },
  router: {
    options: {
      hashMode: false
    }
  },
  devtools: { enabled: env === 'development' },
  css: [
    '~/assets/css/main.css',
    '~/assets/css/mobile.css'
  ],
  compatibilityDate: '2025-05-15',
  vite: {
    css: {
      devSourcemap: true
    },
    plugins: [
      AutoImport({
        imports: [
          {
            'naive-ui': [
              'useDialog',
              'useMessage',
              'useNotification',
              'useLoadingBar'
            ]
          }
        ]
      }),
      Components({
        resolvers: [NaiveUiResolver()]
      })
    ],
    ssr: {
      noExternal: ['naive-ui', 'vueuc', '@css-render/vue3-ssr']
    },
    build: {
      rollupOptions: {
        output: {
          manualChunks: {
            vue: ['vue', 'vue-router'],
            ui: ['naive-ui'],
            utils: ['@vueuse/core']
          }
        }
      },
      minify: 'terser',
      chunkSizeWarningLimit: 1000
    }
  },
  sourcemap: true,
  build: {
    transpile: ['naive-ui', 'vueuc', '@css-render/vue3-ssr']
  },
  postcss: {
    plugins: {
      tailwindcss: {},
      autoprefixer: {}
    }
  },
  ssr: true,
  experimental: {
    payloadExtraction: false
  },
  nitro: {
    preset: 'vercel',
    publicAssets: [
      {
        baseURL: '/',
        dir: 'public',
        maxAge: 60 * 60 * 24 * 7
      }
    ],
    compressPublicAssets: {
      brotli: true,
      gzip: true
    }
  }
});

generate pnpm dev

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.