配置

学习如何根据您的需求配置Nuxt Bridge。

功能标志

您可以选择禁用Bridge的某些功能,或启用不太稳定的功能。在正常情况下,始终建议使用默认设置!

您可以查看bridge/src/module.ts以获取最新的默认值。

nuxt.config.ts
import { defineNuxtConfig } from '@nuxt/bridge'
export default defineNuxtConfig({
  bridge: {

    // -- 选择启用的功能 --

    // 使用Vite作为打包工具,替代webpack 4
    // vite: true,

    // 启用Nuxt 3兼容的useHead
    // meta: true,

    // 启用definePageMeta宏
    // macros: {
    //   pageMeta: true
    // },

    // 使用esbuild启用TypeScript转译
    // typescript: {
    //   esbuild: true
    // },

    // -- 默认功能 --

    // 使用旧版服务器而非Nitro
    // nitro: false,

    // 禁用Nuxt 3兼容的`nuxtApp`接口
    // app: false,

    // 禁用组合式API支持
    // capi: false,

    // ... 或仅禁用旧版组合式API支持
    // capi: {
    //   legacy: false
    // },

    // 不转译模块
    // transpile: false,

    // 禁用<script setup>支持
    // scriptSetup: false,

    // 禁用组合式API的自动导入
    // imports: false,

    // 不警告模块不兼容问题
    // constraints: false
  },

  vite: {
    // Vite的配置
  }
})

各选项的迁移

router.base

export default defineNuxtConfig({
- router: {
-   base: '/my-app/'
- }
+ app: {
+   baseURL: '/my-app/'
+ }
})

build.publicPath

export default defineNuxtConfig({
- build: {
-   publicPath: 'https://my-cdn.net'
- }
+ app: {
+   cdnURL: 'https://my-cdn.net'
+ }
})