总配置文件 Configure

配置文件

configure

Nuxt 配置参考

发现您可以在 nuxt.config.ts 文件中使用的所有选项。

alias

  • Type: object
  • Default
json
{
  "~~": "/<rootDir>",
  "@@": "/<rootDir>",
  "~": "/<rootDir>",
  "@": "/<rootDir>",
  "assets": "/<rootDir>/assets",
  "public": "/<rootDir>/public"
}

您可以通过定义额外的别名来访问您的 JavaScript 和 CSS 中的自定义目录来改进您的 DX。

Example:

js
export default {
  alias: {
    images: fileURLToPath(new URL('./assets/images', import.meta.url)),
    style: fileURLToPath(new URL('./assets/style', import.meta.url)),
    data: fileURLToPath(new URL('./assets/other/data', import.meta.url))
  }
}

app

Nuxt 应用程序配置。

baseURL

  • Type: string
  • Default: "/"

Nuxt 应用程序的基本路径。

这可以在运行时通过设置NUXT_APP_BASE_URL环境变量来设置。

Example:

.env
bash
NUXT_APP_BASE_URL=/prefix/

buildAssetsDir

  • Type: string
  • Default: "/_nuxt/"

构建站点资产的文件夹名称,相对于“baseURL”(或“cdnURL”,如果已设置)。 这是在构建时设置的,不应在运行时自定义。

cdnURL

  • Type: string
  • Default: ""

提供公用文件夹的绝对 URL(仅限生产)。

这可以在运行时通过设置NUXT_APP_CDN_URL环境变量设置为不同的值。

Example:

.env
bash
NUXT_APP_CDN_URL=https://mycdn.org/
  • Type: object
  • Default
json
{
  "meta": [
    {
      "name": "viewport",
      "content": "width=device-width, initial-scale=1"
    },
    {
      "charset": "utf-8"
    }
  ],
  "link": [],
  "style": [],
  "script": [],
  "noscript": []
}

在每个页面上为 <head> 设置默认配置。

Example:

js
app: {
  head: {
    meta: [
      // <meta name="viewport" content="width=device-width, initial-scale=1">
      { name: 'viewport', content: 'width=device-width, initial-scale=1' }
    ],
    script: [
      // <script src="https://myawesome-lib.js"></script>
      { src: 'https://awesome-lib.js' }
    ],
    link: [
      // <link rel="stylesheet" href="https://myawesome-lib.css">
      { rel: 'stylesheet', href: 'https://awesome-lib.css' }
    ],
    // 请注意,这是一个可能会改变的领域
    style: [
      // <style type="text/css">:root { color: red }</style>
      { children: ':root { color: red }', type: 'text/css' }
    ],
    noscript: [
      // <noscript>JavaScript is required</noscript>
      { children: 'JavaScript is required' }
    ]
  }
}

keepalive

  • Type: boolean
  • Default: false

页面之间 KeepAlive 配置的默认值。

这可以在单个页面上用 definePageMeta 覆盖。 只允许使用 JSON 可序列化的值。

See: https://vuejs.org/api/built-in-components.html#keepalive

layoutTransition

  • Type: boolean
  • Default: false

布局转换的默认值。

这可以在单个页面上用 definePageMeta 覆盖。 只允许使用 JSON 可序列化的值。

See: https://vuejs.org/api/built-in-components.html#transition

pageTransition

  • Type: boolean
  • Default: false

页面转换的默认值。

这可以在单个页面上用 definePageMeta 覆盖。 只允许使用 JSON 可序列化的值。

See: https://vuejs.org/api/built-in-components.html#transition

rootId

  • Type: string
  • Default: "__nuxt"

自定义 Nuxt 根元素 id。

rootTag

  • Type: string
  • Default: "div"

自定义 Nuxt 根元素标签。

appConfig

额外的应用程序配置

对于编程使用和类型支持,您可以直接提供带有此选项的应用程序配置。 它将作为默认值与 app.config 文件合并。

build

共享构建配置。

analyze

  • Type: boolean
  • Default: false

Nuxt 使用 webpack-bundle-analyzer 可视化您的包以及如何优化它们。

设置为 true 以启用包分析,或传递带有选项的对象:for webpackfor vite

Example:

js
analyze: { analyzerMode: 'static' }

templates

  • Type: array

您可以提供自己的模板,这些模板将根据 Nuxt 配置进行渲染。 此功能对于与模块一起使用特别有用。

Templates are rendered using lodash.template.

Example:

js
templates: [
  {
    src: '~/modules/support/plugin.js', // `src` 可以是绝对的或相对的
    dst: 'support.js', // `dst` 是相对于项目 `.nuxt` 的目录
    options: {
      // 选项作为“options”键提供给模板
      live_chat: false
    }
  }
]

transpile

  • Type: array

如果你想用 Babel 转译特定的依赖,你可以在这里添加它们。 transpile 中的每一项都可以是包名、函数、字符串或匹配依赖文件名的正则表达式对象。 您还可以使用函数来有条件地转译。 该函数将接收一个对象 ({ isDev, isServer, isClient, isModern, isLegacy })

Example:

js
transpile: [({ isLegacy }) => isLegacy && 'ky']

buildDir

  • Type: string
  • Default: "/<rootDir>/.nuxt"

定义放置构建的 Nuxt 文件的目录。

许多工具假定 .nuxt 是一个隐藏目录(因为它以 . 开头)。 如果这是一个问题,您可以使用此选项来防止它。

Example:

js
export default {
  buildDir: 'nuxt-build'
}

builder

  • Type: string
  • Default: "@nuxt/vite-builder"

用于捆绑应用程序的 Vue 部分的构建器。

components

  • Type: object
  • Default
json
{
  "dirs": [
    {
      "path": "~/components/global",
      "global": true
    },
    "~/components"
  ]
}

配置 Nuxt 组件自动注册。

此处配置的目录中的任何组件都可以在整个页面、布局(和其他组件)中使用,而无需显式导入它们。

See: https://nuxt.com/docs/guide/directory-structure/components

css

  • Type: array

您可以定义要全局设置的 CSS 文件/模块/库(包含在每个页面中)。

Nuxt 会自动根据扩展名猜测文件类型,并使用适当的预处理器。 如果需要使用它们,您仍然需要安装所需的加载程序。

Example:

js
css: [
  // 直接加载一个 Node.js 模块(这里是一个 Sass 文件)。
  'bulma',
  // 项目中的CSS文件
  '@/assets/css/main.css',
  // 项目中的 SCSS 文件
  '@/assets/css/main.scss'
]

debug

  • Type: boolean
  • Default: false

设置为“true”以启用调试模式。

目前,它在服务器上打印出挂钩名称和时间,并在浏览器中记录挂钩参数。

dev

  • Type: boolean
  • Default: false

Nuxt 是否在开发模式下运行。

通常,您不需要设置此项。

devServer

host

  • Type: string
  • Default: "localhost"

开发服务器监听主机

https

  • Type: boolean
  • Default: false

是否开启HTTPS。

Example:

js
import { fileURLToPath } from 'node:url'
export default {
  server: {
    https: {
      key: fs.readFileSync(fileURLToPath(new URL('./server.key', import.meta.url))),
      cert: fs.readFileSync(fileURLToPath(new URL('./server.crt', import.meta.url)))
    }
  }
}

port

  • Type: number
  • Default: 3000

开发服务器监听端口

url

  • Type: string
  • Default: "http://localhost:3000"

监听开发服务器 url

devServerHandlers

  • Type: array

Nitro 仅开发服务器处理程序。

See: /docs/nitro/guide/introduction/routing

dir

自定义 Nuxt 使用的默认目录结构。

除非需要,否则最好坚持使用默认值。

assets

  • Type: string
  • Default: "assets"

资产目录(在您的构建中别名为 ~assets )。

layouts

  • Type: string
  • Default: "layouts"

布局目录,其中的每个文件都会自动注册为 Nuxt 布局。

middleware

  • Type: string
  • Default: "middleware"

中间件目录,其中的每个文件都会自动注册为Nuxt中间件。

pages

  • Type: string
  • Default: "pages"

将被处理以自动生成应用程序页面路由的目录。

plugins

  • Type: string
  • Default: "plugins"

plugins 目录,其中的每个文件都会自动注册为 Nuxt 插件。

public

  • Type: string
  • Default: "public"

包含静态文件的目录,可以通过 Nuxt 服务器直接访问这些文件,并在生成应用程序时将其复制到“dist”文件夹中。

static

  • Type: string
  • Default: "public"

experimental

asyncEntry

  • Type: boolean
  • Default: false

设置为 true 以生成 Vue 包的异步入口点(用于模块联合支持)。

componentIslands

  • Type: boolean
  • Default: false

实验性组件岛支持 with 和 .island.vue 文件。

configSchema

  • Type: boolean
  • Default: false

启用实验性配置模式支持

See: https://github.com/nuxt/nuxt/issues/15592

crossOriginPrefetch

  • Type: boolean
  • Default: false

使用 Speculation Rules API 启用跨源预取。

externalVue

  • Type: boolean
  • Default: true

在构建时外部化 vue@vue/*vue-router

See: https://github.com/nuxt/nuxt/issues/13632

inlineSSRStyles

  • Type: boolean
  • Default: true

呈现 HTML 时的内联样式(目前仅 vite)。

您还可以传递一个函数,该函数接收 Vue 组件的路径并返回一个布尔值,指示是否内联该组件的样式。

noScripts

  • Type: boolean
  • Default: false

关闭 Nuxt 脚本和 JS 资源提示的呈现。

payloadExtraction

  • Type: boolean
  • Default: false

当启用此选项时(默认情况下),将提取使用 nuxt generate 生成的页面的有效负载

reactivityTransform

  • Type: boolean
  • Default: false

启用 Vue 的反应性转换

See: https://vuejs.org/guide/extras/reactivity-transform.html

treeshakeClientOnly

  • Type: boolean
  • Default: true

Tree shakes 服务器包中仅客户端组件的内容。

See: https://github.com/nuxt/framework/pull/5750

viteNode

  • Type: boolean
  • Default: true

使用 vite-node 进行按需服务器块加载

viteServerDynamicImports

  • Type: boolean
  • Default: true

将服务器包拆分为多个块并动态导入它们。

See: https://github.com/nuxt/nuxt/issues/14525

writeEarlyHints

  • Type: boolean
  • Default: false

使用节点服务器时写早期提示。

extends

  • Default: null

从多个本地或远程源扩展项目。

值应该是指向源目录或相对于当前配置的配置路径的字符串或字符串数组。 您可以使用 github:gitlab:bitbucket:https:// 从远程 git 存储库进行扩展。

extensions

  • Type: array
  • Default
js
['.js', '.jsx', '.mjs', '.ts', '.tsx', '.vue']

应该由 Nuxt 解析器解析的扩展。

generate

exclude

  • Type: array

不再使用此选项。 相反,请使用 nitro.prerender.ignore

routes

  • Type: array

要生成的路线。

如果您使用的是爬虫,这将只是路由生成的起点。 这在使用动态路由时通常是必需的。 最好使用 nitro.prerender.routes

Example:

routes: ['/users/1', '/users/2', '/users/3']

hooks

  • Default: null

钩子是 Nuxt 事件的侦听器,通常在模块中使用,但也可在 nuxt.config 中使用。

在内部,挂钩遵循使用冒号的命名模式(例如,build:done)。 为了便于配置,您还可以在 nuxt.config 中将它们构造为分层对象(如下所示)。

Example:

js
import fs from 'node:fs'
import path from 'node:path'
export default {
  hooks: {
    build: {
      done(builder) {
        const extraFilePath = path.join(
          builder.nuxt.options.buildDir,
          'extra-file'
        )
        fs.writeFileSync(extraFilePath, 'Something extra')
      }
    }
  }
}

ignore

  • Type: array
  • Default
js
[
  '**/*.stories.{js,ts,jsx,tsx}',
  '**/*.{spec,test}.{js,ts,jsx,tsx}',
  '**/*.d.ts',
  '.output',
  '**/-*.*'
]

比 ignorePrefix 更具可定制性:所有与 ignore 数组中指定的 glob 模式匹配的文件都将在构建中被忽略。

ignoreOptions

将选项直接传递给 node-ignore(Nuxt 使用它来忽略文件)。

See: node-ignoreExample:

js
ignoreOptions: { ignorecase: false }

ignorePrefix

  • Type: string
  • Default: "-"

如果文件名以 ignorePrefix 指定的前缀开头,则 pages/layouts/middleware/store/ 中的任何文件都将在构建期间被忽略。

imports

配置 Nuxt 如何将可组合项自动导入您的应用程序。

See: Nuxt 3 documentation

dirs

  • Type: array

一组将自动导入的自定义目录。 请注意,此选项不会覆盖默认目录(/composables、/utils)。

Example:

js
imports: {
  // 自动导入 `~/stores` 中定义的 pinia 商店
  dirs: ['stores']
}

global

  • Type: boolean
  • Default: false

modules

  • Type: array

模块是 Nuxt 扩展,可以扩展其核心功能并添加无穷无尽的集成。

每个模块要么是一个字符串(可以引用一个包,也可以是一个文件的路径),一个以模块作为第一个字符串,选项作为第二个对象的元组,或者一个内联模块函数。 Nuxt 尝试使用节点要求路径(在 node_modules 中)解析模块数组中的每个项目,然后如果使用 ~ 别名,将从项目 srcDir 中解析。

Example:

js
modules: [
  // 使用包名
  '@nuxtjs/axios',
  // 相对于你的项目 srcDir
  '~/modules/awesome.js',
  // 提供选项
  ['@nuxtjs/google-analytics', { ua: 'X1234567' }],
  // 内联定义
  function () {}
]

modulesDir

  • Type: array
  • Default
js
[
  '/<rootDir>/node_modules',
  '/Users/daniel/code/nuxt.js/packages/schema/node_modules'
]

用于设置路径解析的模块目录(例如,webpack 的 resolveLoadingnodeExternalspostcss)。

配置路径是相对于 options.rootDir 的(默认是当前工作目录)。 如果您的项目被组织为纱线工作区样式的单一存储库,则可能需要设置此字段。

Example:

js
export default {
  modulesDir: ['../../node_modules']
}

nitro

硝基的配置。

See: /docs/nitro/config/

routeRules

  • Type: object

pages

  • Type: boolean

是否在 Nuxt 3 中使用 vue-router 集成。如果你没有提供一个值,如果你的源文件夹中有一个 pages/ 目录,它将被启用。

plugins

  • Type: array

一系列 nuxt 应用程序插件。

每个插件都可以是一个字符串(可以是文件的绝对路径或相对路径)。 如果它以 .client 或 .server 结尾,那么它将仅在适当的上下文中自动加载。 它也可以是一个带有 srcmode 键的对象。

See: https://nuxt.com/docs/guide/directory-structure/pluginsExample:

js
plugins: [
  '~/plugins/foo.client.js', // 仅在客户端
  '~/plugins/bar.server.js', // 仅在服务器端
  '~/plugins/baz.js', // 客户端和服务器
  { src: '~/plugins/both-sides.js' },
  { src: '~/plugins/client-only.js', mode: 'client' }, // 仅在客户端
  { src: '~/plugins/server-only.js', mode: 'server' } // 仅在服务器端
]

postcss

plugins

配置 PostCSS 插件的选项。

https://postcss.org/

autoprefixer

https://github.com/postcss/autoprefixer

cssnano

  • Type: boolean
  • Default: true

postcss-import

  • Type: object

https://github.com/postcss/postcss-import

postcss-url

https://github.com/postcss/postcss-url

rootDir

  • Type: string
  • Default: "/<rootDir>"

定义应用程序的根目录。

此属性可以被覆盖(例如,运行 nuxt ./my-app/ 会将 rootDir 设置为当前/工作目录中 ./my-app/ 的绝对路径。通常不需要 配置此选项。

routeRules

应用于匹配服务器路由的全局路由选项。

实验性:这是一项实验性功能,API 将来可能会发生变化。 参见/docs/nitro/config/#routes

router

options

传递给 vue-router 的附加选项。

注意:nuxt 配置只应传递 JSON 可序列化选项。 要获得更多控制,您可以使用 app/router.options.ts 文件。

See: Router文档.

runtimeConfig

  • Type: object
  • Default
json
{
  "public": {},
  "app": {
    "baseURL": "/",
    "buildAssetsDir": "/_nuxt/",
    "cdnURL": ""
  }
}

运行时配置允许将动态配置和环境变量传递给 Nuxt 应用上下文。

该对象的值只能使用 useRuntimeConfig 从服务器访问。 它主要应该持有不暴露在前端的_private_配置。 这可能包括对您的 API 秘密令牌的引用。 publicapp 下的任何内容也会暴露给前端。 值在运行时自动替换为匹配的环境变量,例如 设置环境变量 NUXT_API_KEY=my-api-key NUXT_PUBLIC_BASE_URL=/foo/ 将覆盖下面示例中的两个值。

Example:

js
export default {
 runtimeConfig: {
    apiKey: '' // 默认为空字符串,在运行时使用 process.env.NUXT_API_KEY 自动设置
    public: {
       baseURL: '' // 也暴露在前端。
    }
  }
}

serverDir

  • Type: string
  • Default: "/<rootDir>/server"

定义 Nuxt 应用程序的服务器目录,其中保存了 Nitro 路由、中间件和插件。

If a relative path is specified, it will be relative to your rootDir.

serverHandlers

  • Type: array

硝基服务器处理程序。

每个处理程序接受以下选项: - 处理程序:定义处理程序的文件的路径。 - 路线:处理程序可用的路线。 这遵循 https://github.com/unjs/radix3 的约定。 - 方法:应处理的请求的 HTTP 方法。 - 中间件:指定它是否是中间件处理程序。 - lazy:指定是否使用延迟加载来导入处理程序。

See: https://nuxt.com/docs/guide/directory-structure/server

Example:

js
serverHandlers: [
  { route: '/path/foo/**:name', handler: '~/server/foohandler.ts' }
]

sourcemap

  • Type: object
  • Default
json
{
  "server": true,
  "client": false
}

是否生成 sourcemaps。

srcDir

  • Type: string
  • Default: "/<rootDir>"

定义 Nuxt 应用程序的源目录。

如果指定了相对路径,它将相对于 rootDir

Example:

js
export default { srcDir: 'src/' }

这适用于以下文件夹结构:

-| app/
---| node_modules/
---| nuxt.config.js
---| package.json
---| src/
------| assets/
------| components/
------| layouts/
------| middleware/
------| pages/
------| plugins/
------| static/
------| store/
------| server/

ssr

  • Type: boolean
  • Default: true

是否启用 HTML 呈现 - 动态(在服务器模式下)或在生成时。 如果设置为“false”并与“static”目标结合使用,生成的页面将只显示一个没有内容的加载屏幕。

telemetry

  • Type: boolean

手动禁用 nuxt 遥测。

See: Nuxt Telemetry for more information.

test

  • Type: boolean
  • Default: false

您的应用程序是否正在接受单元测试。

theme

  • Type: string
  • Default: null

从本地或远程源扩展项目。

值应该是指向源目录或相对于当前配置的配置路径的字符串。 您可以使用 github:gitlab:bitbucket:https:// 从远程 git 存储库进行扩展。

typescript

Nuxt 的 TypeScript 集成配置。

includeWorkspace

  • Type: boolean
  • Default: false

在 Nuxt 项目中包含父工作区。 对主题和模块作者最有用。

shim

  • Type: boolean
  • Default: true

生成一个 *.vue shim。

我们建议改为启用 接管模式 或添加 TypeScript Vue 插件 (Volar)** 👉 [下载]。

strict

  • Type: boolean
  • Default: true

TypeScript 带有某些检查,可以为您的程序提供更多安全性和分析。 将代码库转换为 TypeScript 后,您可以开始启用这些检查以提高安全性。 阅读更多

tsConfig

您可以使用此选项扩展生成的 .nuxt/tsconfig.json

typeCheck

  • Type: boolean
  • Default: false

启用构建时类型检查。

如果设置为 true,这将在开发中进行类型检查。 您可以通过将其设置为 build 来将其限制为构建时类型检查。 需要安装 typescriptvue-tsc 作为开发依赖。

See: https://nuxt.com/docs/guide/concepts/typescript

vite

将直接传递给 Vite 的配置。

有关详细信息,请参阅 https://vitejs.dev/config。 请注意,并非所有 vite 选项都在 Nuxt 中受支持。

build

assetsDir

  • Type: string
  • Default: "_nuxt/"

emptyOutDir

  • Type: boolean
  • Default: false

clearScreen

  • Type: boolean
  • Default: false

define

  • Type: object
  • Default

esbuild

jsxFactory

  • Type: string
  • Default: "h"

jsxFragment

  • Type: string
  • Default: "Fragment"

tsconfigRaw

  • Type: string
  • Default: "{}"

logLevel

  • Type: string
  • Default: "info"

mode

  • Type: string
  • Default: "production"

optimizeDeps

exclude

  • Type: array
  • Default

publicDir

  • Type: string
  • Default: "/<rootDir>/public"

resolve

extensions

  • Type: array
  • Default
js
['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']

root

  • Type: string
  • Default: "/<rootDir>"

server

fs

allow
  • Type: array
  • Default
js
[
  '/<rootDir>/.nuxt',
  '/<rootDir>',
  '/<rootDir>',
  '/<rootDir>',
  '/<rootDir>/node_modules',
  '/Users/daniel/code/nuxt.js/packages/schema/node_modules'
]

vue

isProduction

  • Type: boolean
  • Default: true

template

compilerOptions
  • Type: object

vue

Vue.js config

compilerOptions

将在构建时传递的 Vue 编译器选项。

See: documentation

watchers

watchers 属性让您可以覆盖 nuxt.config 中的观察者配置。

chokidar

直接传递给 chokidar 的选项。

See: chokidar

ignoreInitial

  • Type: boolean
  • Default: true

rewatchOnRawEvents

一组事件类型,当接收到这些事件类型时,将导致观察者重新启动。

webpack

watchOptions 直接传递给 webpack。

See: webpack@4 watch options.

aggregateTimeout

  • Type: number
  • Default: 1000

webpack

aggressiveCodeRemoval

  • Type: boolean
  • Default: false

将“typeof process”、“typeof window”和“typeof document”硬替换为 tree-shake 包。

analyze

  • Type: boolean
  • Default: false

Nuxt 使用 webpack-bundle-analyzer 可视化您的包以及如何优化它们。

设置为 true 以启用包分析,或传递带有选项的对象:for webpackfor vite

Example:

js
analyze: {
  analyzerMode: 'static'
}

cssSourceMap

  • Type: boolean
  • Default: false

启用 CSS 源映射支持(在开发中默认为“true”)。

devMiddleware

有关可用选项,请参阅 webpack-dev-middleware

stats

  • Type: string
  • Default: "none"

extractCSS

  • Type: boolean
  • Default: true

使用 Vue 服务器渲染器指南 启用通用 CSS 提取。

在后台使用 extract-css-chunks-webpack-plugin,您的 CSS 将被提取到单独的文件中,通常每个文件一个 成分。 这允许分别缓存您的 CSS 和 JavaScript,如果您有大量全局或共享 CSS,则值得尝试。

Example:

js
export default {
  webpack: {
    extractCSS: true,
    // 或者
    extractCSS: {
      ignoreOrder: true
    }
  }
}

Example:

js
export default {
  webpack: {
    extractCSS: true,
    optimization: {
      splitChunks: {
        cacheGroups: {
          styles: {
            name: 'styles',
            test: /\.(css|vue)$/,
            chunks: 'all',
            enforce: true
          }
        }
      }
    }
  }
}

filenames

自定义捆绑包文件名。

要进一步了解清单的使用,请查看 此 webpack 文档

Example:

js
filenames: {
  chunk: ({ isDev }) => (isDev ? '[name].js' : '[id].[contenthash].js')
}

app

  • Type: function

chunk

  • Type: function

css

  • Type: function

font

  • Type: function

img

  • Type: function

video

  • Type: function

friendlyErrors

  • Type: boolean
  • Default: true

设置为“false”以禁用 FriendlyErrorsWebpackPlugin 提供的覆盖。

hotMiddleware

有关可用选项,请参阅 webpack-hot-middleware

loaders

自定义 Nuxt 的集成 webpack 加载器的选项。

css

esModule
  • Type: boolean
  • Default: false
importLoaders
  • Type: number
  • Default: 0
url
filter
  • Type: function

cssModules

esModule
  • Type: boolean
  • Default: false
importLoaders
  • Type: number
  • Default: 0
modules
localIdentName
  • Type: string
  • Default: "[local]_[hash:base64:5]"
url
filter
  • Type: function

file

esModule
  • Type: boolean
  • Default: false

fontUrl

esModule
  • Type: boolean
  • Default: false
limit
  • Type: number
  • Default: 1000

imgUrl

esModule
  • Type: boolean
  • Default: false
limit
  • Type: number
  • Default: 1000

less

  • Default

pugPlain

sass

sassOptions
indentedSyntax
  • Type: boolean
  • Default: true

scss

  • Default

stylus

  • Default

vue

compilerOptions
  • Type: object
productionMode
  • Type: boolean
  • Default: true
transformAssetUrls
embed
  • Type: string
  • Default: "src"
object
  • Type: string
  • Default: "src"
source
  • Type: string
  • Default: "src"
video
  • Type: string
  • Default: "src"

vueStyle

  • Default

optimization

Configure webpack optimization.

minimize

  • Type: boolean
  • Default: true

将最小化设置为“false”以禁用所有最小化器。 (默认情况下在开发中禁用)。

minimizer

您可以将最小化器设置为自定义的插件数组。

runtimeChunk

  • Type: string
  • Default: "single"

splitChunks

automaticNameDelimiter
  • Type: string
  • Default: "/"
cacheGroups
chunks
  • Type: string
  • Default: "all"

optimizeCSS

  • Type: boolean
  • Default: false

OptimizeCSSAssets 插件选项。

启用 extractCSS 时默认为 true。

See: css-minimizer-webpack-plugin documentation.

plugins

  • Type: array

添加 webpack 插件。

Example:

js
import webpack from 'webpack'
import { version } from './package.json'
// ...
plugins: [
  new webpack.DefinePlugin({
    'process.VERSION': version
  })
]

postcss

自定义 PostCSS 加载器。 与 https://github.com/webpack-contrib/postcss-loader#options 相同的选项

execute

  • Type: undefined

implementation

  • Type: undefined

order

  • Type: string
  • Default: ""

postcssOptions

config
plugins
  • Type: object
  • Default
js
{
  "postcss-import": {},
  "postcss-url": {},
  "autoprefixer": {},
  "cssnano": true
}

sourceMap

  • Type: undefined

profile

  • Type: boolean
  • Default: false

在 webpackbar 中启用分析器。

它通常由 CLI 参数 --profile 启用。

See: webpackbar.

serverURLPolyfill

  • Type: string
  • Default: "url"

要加载的 polyfill 库以提供 URL 和 URLSearchParams。

Defaults to 'url' (see package).

terser

Terser 插件选项。

设置为 false 以禁用此插件,或传递一个选项对象。

See: terser-webpack-plugin documentation.

warningIgnoreFilters

  • Type: array

过滤器以隐藏构建警告。

workspaceDir

  • Type: string
  • Default: "/<rootDir>"

确定应用程序的工作区目录。

这通常在 monorepo 设置中使用。 Nuxt 将尝试自动检测您的工作区目录,但您可以在此处覆盖它。 通常不需要配置此选项。