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
Next.js 70.65s

在命令行下使用

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

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

npm pnpm yarn
# Searches the current directory, outputs to ./_site
npx @11ty/eleventy

# `npx @11ty/eleventy` is the same as:
npx @11ty/eleventy --input=. --output=_site
# Searches the current directory, outputs to ./_site
pnpm exec eleventy

# `pnpm exec eleventy` is the same as:
pnpm exec eleventy --input=. --output=_site
# Searches the current directory, outputs to ./_site
yarn exec eleventy

# `yarn exec eleventy` is the same as:
yarn exec eleventy --input=. --output=_site

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

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

npm pnpm yarn
# Use only a subset of template types
npx @11ty/eleventy --formats=md,html,ejs

# Find out the most up-to-date list of commands (there are more)
npx @11ty/eleventy --help
# Use only a subset of template types
pnpm exec eleventy --formats=md,html,ejs

# Find out the most up-to-date list of commands (there are more)
pnpm exec eleventy --help
# Use only a subset of template types
yarn exec eleventy --formats=md,html,ejs

# Find out the most up-to-date list of commands (there are more)
yarn exec eleventy --help

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

npm pnpm yarn
# Add a web server to apply changes and
# refresh automatically. We’ll also --watch for you.
npx @11ty/eleventy --serve

# Change the web server’s port—use localhost:8081
npx @11ty/eleventy --serve --port=8081

# Watch and re-run when files change, without the web server.
npx @11ty/eleventy --watch
# Add a web server to apply changes and
# refresh automatically. We’ll also --watch for you.
pnpm exec eleventy --serve

# Change the web server’s port—use localhost:8081
pnpm exec eleventy --serve --port=8081

# Watch and re-run when files change, without the web server.
pnpm exec eleventy --watch
# Add a web server to apply changes and
# refresh automatically. We’ll also --watch for you.
yarn exec eleventy --serve

# Change the web server’s port—use localhost:8081
yarn exec eleventy --serve --port=8081

# Watch and re-run when files change, without the web server.
yarn exec eleventy --watch

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

npm pnpm yarn
# Shhhhh—Don’t log so much to the console
npx @11ty/eleventy --quiet
# Shhhhh—Don’t log so much to the console
pnpm exec eleventy --quiet
# Shhhhh—Don’t log so much to the console
yarn exec eleventy --quiet

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

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

npm pnpm yarn
# Run Eleventy but don’t write any files
npx @11ty/eleventy --dryrun
# Run Eleventy but don’t write any files
pnpm exec eleventy --dryrun
# Run Eleventy but don’t write any files
yarn exec eleventy --dryrun

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

npm pnpm yarn
# Override the default eleventy project config filename (.eleventy.js)
npx @11ty/eleventy --config=myeleventyconfig.js
# Override the default eleventy project config filename (.eleventy.js)
pnpm exec eleventy --config=myeleventyconfig.js
# Override the default eleventy project config filename (.eleventy.js)
yarn exec eleventy --config=myeleventyconfig.js

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

npm pnpm yarn
# Output a JSON structure (does not write to the file system)
npx @11ty/eleventy --to=json

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

# 默认行为(输出到文件系统)
npx @11ty/eleventy --to=fs
# Output a JSON structure (does not write to the file system)
pnpm exec eleventy --to=json

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

# 默认行为(输出到文件系统)
pnpm exec eleventy --to=fs
# Output a JSON structure (does not write to the file system)
yarn exec eleventy --to=json

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

# 默认行为(输出到文件系统)
yarn exec eleventy --to=fs

更多信息请参阅 ndjson

--incremental for Partial Incremental Builds Jump to heading

npm pnpm yarn
# *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
# *Repeat* builds only operate on files that have changed
pnpm exec eleventy --watch --incremental
pnpm exec eleventy --serve --incremental

# Skip the initial full build with `--ignore-initial`
pnpm exec eleventy --serve --incremental --ignore-initial
# *Repeat* builds only operate on files that have changed
yarn exec eleventy --watch --incremental
yarn exec eleventy --serve --incremental

# Skip the initial full build with `--ignore-initial`
yarn exec 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!

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

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

# Works great with Incremental
pnpm exec eleventy --serve --incremental --ignore-initial
# Don’t build when Eleventy starts, only build on file changes
yarn exec eleventy --watch --ignore-initial
yarn exec eleventy --serve --ignore-initial

# Works great with Incremental
yarn exec eleventy --serve --incremental --ignore-initial

Using the Same Input and Output Jump to heading

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

npm pnpm yarn
# Parse and write Markdown to HTML, respecting directory structure.
npx @11ty/eleventy --input=. --output=. --formats=md
# Parse and write Markdown to HTML, respecting directory structure.
pnpm exec eleventy --input=. --output=. --formats=md
# Parse and write Markdown to HTML, respecting directory structure.
yarn exec eleventy --input=. --output=. --formats=md
WARNING:
请注意这里的 --formats=html 参数!如果你多次运行 eleventy,它也会尝试处理前面输出的文件。请参阅 HTML 模板相关文档

Other pages in Getting Started: