Table of Contents
assets-core
Note: The options API is still evolving; expect tweaks as the project grows.
What it does
assets-core is Baseline's single assets plugin. It owns all the Eleventy wiring for JS and CSS: template formats, extensions, compile guards, inline filters, watch targets, and global data. Processing itself is delegated to assets-esbuild and assets-postcss — pure functions that know nothing about Eleventy.
Defaults
- Assets directory:
src/assets/(fixed convention, mirrorsdir.assets). - JS entries: any
index.jsundersrc/assets/js/(including nested folders). - CSS entries: any
index.cssundersrc/assets/css/(including nested folders). - esbuild:
minify: true,target: 'es2020'(defaults live in assets-esbuild). - PostCSS: uses your project's
postcss.config.js, or falls back to Baseline's bundled config. - Watch target:
src/assets/**/*.{css,js,svg,png,jpeg,jpg,webp,gif,avif}— edits trigger reloads during--serve. - Output: under
dist/assets/(matching Eleventy'sdir.output).
Options
| Option | Type | Default | Description |
|---|---|---|---|
esbuild.minify |
boolean | true |
Forward to esbuild's minify flag. |
esbuild.target |
string | 'es2020' |
Forward to esbuild's target. |
Pass esbuild options via Baseline's assetsESBuild option in your Eleventy config:
eleventyConfig.addPlugin(
baseline({
assetsESBuild: {
minify: process.env.ELEVENTY_ENV === 'production',
target: 'es2017'
}
})
);
PostCSS has no plugin-level options — configure it through your postcss.config.js (see the custom PostCSS config guide).
How it works
-
Directory resolution.
On the
eleventy.directoriesevent, assets-core resolves input/output/assets paths and defines a virtualdirectories.assetsproperty. Global data at_baseline.assetsexposesinputandoutputfor use in templates. -
Template formats and extensions.
Registers
jsandcssas Eleventy template formats. Each gets an extension handler withread: false— the process functions own their I/O. -
Compile guards.
Only
index.jsfiles undersrc/assets/js/andindex.cssfiles undersrc/assets/css/are compiled. Everything else (partials,11tydata.jsfiles, non-entry scripts) is skipped. Anignores.addrule also prevents11tydata.jsfiles from entering the template graph. -
Inline filters.
inlineESbuildandinlinePostCSSare async filters that process a file and wrap the result in<script>or<style>tags. They call the same process functions as the compile step. See assets-esbuild and assets-postcss for usage. -
Watch target.
Covers common asset formats under
src/assets/so edits trigger reloads duringnpm run dev.
Tips
- Keep assets in
src/assets/— the directory convention is fixed by design. - Only
index.jsandindex.cssare compiled. Use them as entry points; import everything else from there. - The watch target covers images too, so editing an SVG or PNG triggers a reload without extra config.
- See the Assets Pipeline Quickstart for a guided setup.
Peer deps
None — built-in. esbuild and PostCSS dependencies are managed by Baseline.
Previous: Modules
Next: assets-esbuild