Skip to navigation Skip to main content
11ty Logo Sustainability Fundraising
Eleventy
Eleventy Documentation
Stable
2.0.1
Canary
3.0.0-alpha.16
Toggle Menu
Eleventy 1.93s
Gatsby 29.05s

调试模式

Contents

遇到麻烦了吗?是否想看看 Eleventy 在幕后到底做了什么? DEBUG 模式可以帮你解惑。这一功能是基于 出色的 debug 软件包 实现的。

debug 能够明确地告诉你 data、includes、input 和 output 各自对应的是哪个目录,它还能告诉你查找模板时用的是什么 glob(类似正则表达式的东西),以及找到了哪些模板。如果你遇到了问题,请开启此功能。

你可以通过 环境变量(environment variable) DEBUG 开启此功能。实际使用时,在运行 Eleventy 的命令前添加一些设置环境变量的字符串即可。

命令 Jump to heading

以下命令假定 Eleventy 是安装在本地的(推荐),当然,你可以了解更多关于本地安装(Local installation)和全局安装(Global installation) 的区别。

macOS or Linux (et al) Jump to heading

DEBUG=Eleventy* npx @11ty/eleventy

Windows Jump to heading

阅读有关 Windows 环境变量 的更多信息。

cmd.exe Jump to heading

set DEBUG=Eleventy* & npx @11ty/eleventy

Powershell (default in VS Code) Jump to heading

$env:DEBUG="Eleventy*"; npx @11ty/eleventy

Cross Platform Jump to heading

Use the cross-env package to compatibly set your environment variables cross-platform.

npm install cross-env

Now add an npm script in your package.json, unlocking npm run debug:

{
"scripts": {
"debug": "cross-env DEBUG=Eleventy* npx @11ty/eleventy"
}
}

了解更多 Jump to heading

请参阅 debug 软件包的文档 以了解更多信息。

--dryrun 参数 Jump to heading

如果你想运行 Eleventy 但不希望输出到文件系统的话,请添加 --dryrun 参数。

查看所有信息 Jump to heading

前述命令通过设置 DEBUG=Eleventy* 将来自 debug 的消息限定为 Eleventy 相关的信息,但是你可以通过设置 DEBUG=* 查看来自所有依赖包输出的所有信息。

分析性能 Jump to heading

阅读有关如何 使用 debug 来分析 Eleventy 构建性能 的更多信息。

调试单个变量 Jump to heading

In addition to using debug, you can use the global filter log to console.log anything from inside a template file.