// https://nuxt.com/docs/api/configuration/nuxt-config
/*
 * @Author: wjc
 * @Date: 2023-10-25 19:39:32
 * @LastEditors: LiZhiWei
 * @LastEditTime: 2026-01-14 15:15:30
 * @Description:
 */
import { loadEnv } from 'vite'
import { createResolver } from '@nuxt/kit'
const { resolve } = createResolver(import.meta.url)
import { fileURLToPath } from 'url'
import { appDescription } from './app/constants/index'

const envName = process.env.npm_lifecycle_script?.match(/--mode\s(.*)/)?.[1] ?? 'development'
const envData = loadEnv(envName, process.cwd()) // 获取.env文件中的配置
Object.assign(process.env, envData) // 将环境配置信息，添加到process.env

export default defineNuxtConfig({
  compatibilityDate: '2026-01-09',
  routeRules: {},
  alias: {
    '@': fileURLToPath(new URL('./app', import.meta.url)),
  },
  modules: [
    '@vueuse/nuxt',
    '@unocss/nuxt',
    '@pinia/nuxt',
    '@element-plus/nuxt',
    // '@nuxtjs/color-mode',
    // '@nuxtjs/i18n',
  ],
  experimental: {
    // when using generate, payload js assets included in sw precache manifest
    // but missing on offline, disabling extraction it until fixed
    payloadExtraction: false,
    renderJsonPayloads: false,
    typedPages: false,
  },
  imports: {
    dirs: [resolve('./stores'), '~/stores'],
  },
  css: ['@unocss/reset/tailwind.css', '~/assets/scss/common.scss'],
  vite: {
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@use "~/assets/scss/vars.scss";`,
        },
      },
    },
  },
  nitro: {
    devProxy: {
      '/yyds': {
        target: 'https://wisdomcity.eu.org:30032/yyds',
        changeOrigin: true,
        prependPath: true,
        secure: false,
      },
    },
  },
  build: {},
  runtimeConfig: {
    public: {
      apiBase: process.env.NUXT_PUBLIC_API_BASE,
    },
  },
  app: {
    head: {
      viewport: 'width=device-width,initial-scale=1',
      link: [
        { rel: 'icon', href: '/logo.png', sizes: 'any' },
        { rel: 'icon', href: '/logo.png' },
        { rel: 'apple-touch-icon', href: '/logo.png' },
      ],
      meta: [
        { name: 'viewport', content: 'width=device-width, initial-scale=1' },
        { name: 'description', content: appDescription },
        { name: 'apple-mobile-web-app-status-bar-style', content: 'black-translucent' },
      ],
    },
  },
  features: {
    inlineStyles: false,
  },
  components: true,
  sourcemap: {
    client: true,
    server: false,
  },
})
