Eleventy(11ty) logo Eleventy
The possum is Eleventy’s mascot
Eleventy 中文文档
Menu
Eleventy 5.81s
Remix 40.14s

在命令行下使用

Prerequisites:

  1. Eleventy runs in a Terminal window. Well, wait—what is a Terminal window?
  2. Have you already installed Eleventy?

Here’s the first command you can enter in your Terminal window to run Eleventy:

# 搜索当前目录下的所有文件并输出到 ./_site 目录下
npx @11ty/eleventy
WARNING:
请确保始终采用 npx @11ty/eleventy 形式的指令(即,包含 @11ty/ 前缀)!如果你没有包含 @11ty/ 前缀并且也未(无论本地还是全局)安装 Eleventy ,将会执行这个 错误的软件包。因此,为了一致和准确,请始终使用 npx @11ty/eleventy 形式。

如果你使用的是全局安装的 Eleventy,请从每个指令的开头删除 npx @11ty/ 字样,如下所示:

# 全局安装的
eleventy
# `npx @11ty/eleventy` 等价于以下形式
npx @11ty/eleventy --input=. --output=_site

阅读有关 --input--output 的更多信息。请注意,通过 配置 文件设置 input 和 output 参数更加可靠,尤其是在使用类似 netlify dev 等工具时。

假定当前目录下有一个名为 template.md 的文件,最终将被渲染并输出为 _site/template/index.html 文件。请参考 永久链接 章节以了解更多信息。

# 仅使用部分模板类型
npx @11ty/eleventy --formats=md,html,ejs
# 查看最新的命令列表
npx @11ty/eleventy --help

文件保存时重新运行 Eleventy Jump to heading

# 启动 Browsersync web 服务来监测更改并
# 自动刷新页面。我们默认添加了 --watch 参数。
npx @11ty/eleventy --serve
# 更改 web 服务的端口号,即 localhost:8081
npx @11ty/eleventy --serve --port=8081
INFO:
重要说明Browsersync 需要页面中包含 <body> 标签 才能正常工作。
# 模板文件有修改时自动运行 Eleventy。
# 如果你启动了自己的 web 服务的话则非常有用。
npx @11ty/eleventy --watch

--quiet 参数让输出更安静 Jump to heading

# 减少日志输出
npx @11ty/eleventy --quiet

--dryrun 参数用于小测试 Jump to heading

运行但不向文件系统写入任何文件。在 调试 时很有用。

# 运行 Eleventy 但不输出任何文件
npx @11ty/eleventy --dryrun

--config 参数用于指定配置文件的文件名 Jump to heading

# 改变默认的配置文件名(默认文件名是 .eleventy.js)
npx @11ty/eleventy --config=myeleventyconfig.js

--to 参数用于输出 JSON Added in v1.0.0 Jump to heading

# 以 JSON 格式输出(不写入文件系统)
npx @11ty/eleventy --to=json

# 以通过换行符分隔的 JSON 格式输出(不写入文件系统)
npx @11ty/eleventy --to=ndjson

# 默认行为(输出到文件系统)
npx @11ty/eleventy --to=fs

更多信息请参阅 ndjson

--incremental 参数用于增量构建 Jump to heading

# *Repeat* builds only operate on files that have changed
npx @11ty/eleventy --watch --incremental
npx @11ty/eleventy --serve --incremental

# Skip the initial full build with `--ignore-initial`
npx @11ty/eleventy --serve --incremental --ignore-initial

更多信息请参阅 增量构建(incremental builds) 章节。

--ignore-initial to run Eleventy without an Initial Build Added in v2.0.0 Jump to heading

Be wary of any file changes that happened while Eleventy wasn’t running!

# Don’t build when Eleventy starts, only build on file changes
npx @11ty/eleventy --watch --ignore-initial
npx @11ty/eleventy --serve --ignore-initial
npx @11ty/eleventy --serve --incremental --ignore-initial

Using the Same Input and Output Jump to heading

的确,你可以将 inputoutput 参数设置为同一个目录,如下所示:

# 解析 Markdown 并输出为 HTML 文件,且遵循目录结构。
npx @11ty/eleventy --input=. --output=. --formats=md
WARNING:
请注意这里的 --formats=html 参数!如果你多次运行 eleventy,它也会尝试处理前面输出的文件。请参阅 HTML 模板相关文档

Other pages in Getting Started: