Eleventy (Build Awesome)
repository·main·Indexed 12 days ago
https://github.com/11ty/buildawesomeA JavaScript-based static site generator that transforms various template types into HTML. It supports multiple template languages, is extensible via plugins, and provides both a CLI and a programmatic API via the Core and CoreMinimal classes. Version 4.0.0-alpha.10 includes a browser-friendly client implementation (@11ty/client) with support for Markdown, Nunjucks, and Liquid.
What's inside Eleventy
- Build Awesome (Eleventy) is a JavaScript-based static site generator and an alternative to Jekyll. It transforms a directory of templates into HTML. It supports a wide range of template languages and can be extended with addons for technologies like WebC, Sass, Vue, Svelte, TypeScript, and JSX.
Install Build Awesome (Eleventy)
mainYou can install Build Awesome (Eleventy) via npm. The package
@awesome.me/buildawesomeis the current naming convention, but@11ty/eleventyremains available for backwards compatibility.npm install @awesome.me/buildawesome --save-dev # Backwards compatible version: npm install @11ty/eleventy --save-devInstall @11ty/client
mainInstall the browser-friendly version of Eleventy using npm. This package provides a client-side implementation of the static site generator capabilities.
npm install @11ty/client --saveConfigure library amendments for a TemplateEngine
mainThe
TemplateEnginesupports applying amendments to the underlying engine library. These amendments are defined in the configuration underconfig.libraryAmendments[this.name].When
setEngineLib(engineLib)is called, the engine iterates through the array of amendment functions provided in the configuration for that specific engine name and executes them, passing theengineLibas an argument.How configuration resets work during watch
mainWhen running in watch mode, Eleventy monitors specific files to determine if a full configuration reset is required. A reset is triggered if:
- A local project configuration file (e.g.,
buildawesome.config.js) is modified. - A file matching the globs defined in
userConfig.watchTargetsConfigResetis modified. - A dependency of a configuration file is modified.
When a reset is triggered, Eleventy emits the
buildawesome.resetevent, reloads the global configuration, and restarts the build process to ensure all new configuration settings are applied.- A local project configuration file (e.g.,
How TemplateConfig manages configuration merging
mainThe configuration follows a specific hierarchy and merging logic:
- Root Config: Starts with a default configuration (or a
customRootConfigif provided). - Local Project Config: Loads the local file (e.g.,
.eleventy.js). It supports both a function return (e.g.,module.exports = function(eleventyConfig) { ... }) and a direct object export (e.g.,export const config = { ... }). - Plugin Execution: Plugins are processed during the merge, allowing them to interact with the
userConfigand modify the resulting configuration. - Configuration API Overrides: Settings applied via programmatic API methods (like
setPathPrefixorsetDirectories) take precedence over the values returned by the configuration files.
Note on Template Formats:
templateFormatscan be set via the config object.templateFormatsAddedis additive and is used to append new formats to the existing list.
- Root Config: Starts with a default configuration (or a
Install and configure the RenderPlugin
mainThe
RenderPluginallows you to render an Eleventy template string or file inside another template using shortcodes or filters.To use it, add it to your Eleventy configuration using
$config.addPlugin(RenderPlugin, options).Plugin Options:
tagName(string, default:"renderTemplate"): The name of the shortcode used to render a template string.tagNameFile(string, default:"renderFile"): The name of the shortcode used to render a template file.filterName(string, default:"renderContent"): The name of the async filter used to render template strings.templateConfig(TemplateConfig, optional): A configuration object.accessGlobalData(boolean, default:false): Iftrue, the rendered template will have access to the parent template's data cascade.
import RenderPlugin from "@11ty/eleventy/render-plugin"; export default function (eleventyConfig) { eleventyConfig.addPlugin(RenderPlugin, { tagName: "renderTemplate", tagNameFile: "renderFile", accessGlobalData: true }); };Use the Build Awesome (Eleventy) CLI
mainThe Build Awesome (Eleventy) CLI allows you to build, watch, or serve your site from the command line. It supports various modes including standard builds, file watching, and a local development server. You can also output the build results as JSON instead of writing to the file system.
# Example: Standard build eleventy # Example: Serve the site on a specific port eleventy --serve --port 8080 # Example: Watch for changes eleventy --watch # Example: Output build data as JSON eleventy --to jsonConfigure Chokidar options for file watching
mainYou can customize the underlying file watcher behavior by providing a
chokidarConfigobject within your Eleventy configuration.By default, the watcher uses the following settings:
ignoreInitial: trueawaitWriteFinish: { stabilityThreshold: 150, pollInterval: 25 }
Note: Providing a custom
ignoredproperty in yourchokidarConfigis unsupported and will be deleted by the internal watcher logic to allow Eleventy to manage its own ignore patterns.// Example of how chokidarConfig might be structured in your user config module.exports = { chokidarConfig: { usePolling: true, interval: 100 } };ESLint configuration patterns in Build Awesome
mainThe project uses a flat configuration format for ESLint. It is composed of several named configuration blocks that establish a baseline for JavaScript development, project-specific rules, test file handling, and Prettier integration.
Key configuration blocks include:
11ty/setup/js: Uses@eslint/jsrecommended settings.11ty/rules/project-specific: Configures Node.js globals, ECMAScript module support, and specific stylistic and logic rules.11ty/ignores: Specifically targets test files to relax certain rules likeno-unused-vars.11ty/setup/prettier: Integrateseslint-config-prettierto ensure compatibility with Prettier.
Configure the loader (ESM vs CJS)
mainYou can explicitly control how modules are loaded using the
loaderoption in the constructor. This is useful if you want to bypass the automatic detection frompackage.json.Supported values:
'esm': Forces ECMAScript Modules.'cjs': Forces CommonJS.'auto': Automatically detects based onpackage.json(or defaults to ESM in Deno environments).
const eleventy = new CoreMinimal({ options: { loader: 'esm' } });Use @11ty/client sub-exports
mainThe
@11ty/clientpackage provides specific entry points for different template engines and plugins via sub-exports. You can import these directly to use specific functionalities in your browser-side code:@11ty/client: The core client package.@11ty/client/md: Markdown Template Engine.@11ty/client/njk: Nunjucks Template Engine.@11ty/client/liquid: Liquid Template Engine.@11ty/client/i18n: i18n Plugin.