liveh5-nuxt/nuxt.config.js

134 lines
3.2 KiB
JavaScript
Raw Normal View History

import dotenv from 'dotenv'
2025-01-08 05:26:12 +00:00
import process from 'node:process'
import preload from './app/utils/preload'
import { currentLocales } from './i18n/i18n'
const envFile = process.env.ENV_FILE || '.env.test'
dotenv.config({ path: `./env/${envFile}` })
const publicConfig = Object.entries(process.env)
.filter(([key]) => key.startsWith('NUXT_PUBLIC_'))
.reduce((config, [key, value]) => {
config[key] = value
return config
}, {})
2025-01-08 05:26:12 +00:00
export default defineNuxtConfig({
modules: [
'@vant/nuxt',
'@unocss/nuxt',
'@nuxt/image',
'@nuxtjs/i18n',
2025-01-08 05:26:12 +00:00
],
image: {
provider: 'ipx',
format: ['webp'],
quality: 80,
},
2025-01-08 05:26:12 +00:00
runtimeConfig: {
// 私有配置,只有在服务端可用
apiSecret: process.env.NUXT_API_SECRET,
// 公共配置,客户端和服务端都可用
public: publicConfig,
2025-01-08 05:26:12 +00:00
},
css: [
'@unocss/reset/tailwind.css',
'@/static/styles/default-theme.css',
2025-01-08 05:26:12 +00:00
],
2025-01-08 05:26:12 +00:00
postcss: {
plugins: {
'autoprefixer': {},
// https://github.com/wswmsword/postcss-mobile-forever
2025-01-08 05:26:12 +00:00
'postcss-mobile-forever': {
appSelector: '#__nuxt',
viewportWidth: 375,
maxDisplayWidth: 600,
// devtools excluded
exclude: /@nuxt/,
border: true,
2025-01-08 05:26:12 +00:00
rootContainingBlockSelectorList: [
'van-tabbar',
'van-popup',
],
},
},
},
i18n: {
locales: currentLocales,
lazy: true,
strategy: 'no_prefix',
2025-01-08 05:26:12 +00:00
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
redirectOn: 'root',
alwaysRedirect: true,
fallbackLocale: 'zh-CN'
2025-01-08 05:26:12 +00:00
},
langDir: 'locales',
defaultLocale: 'zh-CN',
vueI18n: './i18n/i18n.config.ts',
2025-01-08 05:26:12 +00:00
},
app: {
layoutTransition: {
name: 'layout',
mode: 'out-in'
},
2025-01-08 05:26:12 +00:00
head: {
viewport: 'width=device-width,initial-scale=1,viewport-fit=cover',
link: [
{ rel: 'icon', href: '/favicon.ico', sizes: 'any' },
2025-01-08 05:26:12 +00:00
],
meta: [
{ name: 'viewport', content: 'width=device-width, initial-scale=1, viewport-fit=cover,user-scalable=no' },
{ name: 'apple-mobile-web-app-capable', content: 'yes' },
{ name: 'apple-mobile-web-app-status-bar-style', content: 'black-translucent' },
{ name: 'theme-color', media: '(prefers-color-scheme: light)', content: '#ffffff' },
{ name: 'theme-color', media: '(prefers-color-scheme: dark)', content: '#222222' },
2025-01-08 05:26:12 +00:00
],
script: [
{ innerHTML: preload(), type: 'text/javascript', tagPosition: 'head' },
2025-01-08 05:26:12 +00:00
],
},
},
vite: {
build: {
target: 'esnext',
2025-01-08 05:26:12 +00:00
},
optimizeDeps: {
include: [
'@intlify/core-base',
'@intlify/shared',
'is-https',
2025-01-08 05:26:12 +00:00
],
},
},
experimental: {
typedPages: true,
2025-01-08 05:26:12 +00:00
},
devtools: {
enabled: true,
2025-01-08 05:26:12 +00:00
},
typescript: {
shim: false,
2025-01-08 05:26:12 +00:00
},
features: {
// For UnoCSS
inlineStyles: false,
2025-01-08 05:26:12 +00:00
},
future: {
compatibilityVersion: 4,
2025-01-08 05:26:12 +00:00
},
// 指定 Nuxt 应用程序的兼容性日期,确保应用程序在未来的 Nuxt 版本中保持稳定性
compatibilityDate: '2025-01-09',
devServer: {
host: '0.0.0.0', // Set the host to 'localhost'
port: 3000, // Set the port to 3000 or any other port you prefer
},
})