Skip to main contentSkip to docs navigation

Chassis

Web Applications

View on GitHub

How a web application gets the fonts, images, icons and other files of the web output of Chassis Assets, and how it reads them.

This documentation is a work in progress. Some information may be incomplete, outdated, or differ from the current product behavior.

Introduction

The web output of an app and a brand is the folder dist/web/<app>/<brand>/. The build copies the source files into it and renames them to kebab-case, with the @2x and @3x indicators kept. It does not convert, resize or optimize a file, so the output holds the formats and the variants the designer exported.

TypeWhat the web output holds
fonts/The WOFF and WOFF2 files, the .css and .scss stylesheets and the license files
images/Every file, in the subfolders of the source
icons/Every file, in the subfolders of the source
Any other folderEvery file

Each brand of the app has a folder of its own, with the type folders of the source in it. A type folder is there when the brand or the default brand has files of the type.

TEXT
dist/web/<app>/
├── <brand>/
│   ├── fonts/
│   ├── icons/
│   ├── images/
│   └── <folder>/      -> any other folder of the source
└── <brand>/
    └── ...

The commands of this page build the web app site for the brand acme, the configuration of the quick start; with another configuration, use the names of your own app and brand. The file names of the samples, such as images/hero-banner.png, are examples: your output has the files of your source, under the names that Output names describes.

Installation

A web application gets the output of its repository of assets from a release archive, from a Git submodule that it builds, or from a build in a clone. The commands below name a repository acme/acme-assets; use the address of your own.

Release archive

The release workflow of a repository of assets attaches one archive per platform, app and brand to each GitHub release. The archive of a job is named <name>-<platform>-<app>-<brand>-<version>.zip, after the name and the version of the package.json of the repository, and holds the content of dist/<platform>/<app>/<brand>/ at its top level.

Download the archive of your job from the releases of the repository and extract it into the folder your application serves static files from:

Shell
mkdir -p public/assets
unzip "acme-assets-web-site-acme-<version>.zip" -d public/assets

An archive needs no Node.js, no package and no Git LFS on the machine that uses it.

Git submodule

A submodule pins the assets to a commit and builds them inside your project. The submodule needs nothing installed; the project installs @chassis-ui/assets and runs the build on the folder with --cwd.

Shell
git submodule add https://github.com/acme/acme-assets.git vendor/assets
git -C vendor/assets lfs pull
npm install --save-dev @chassis-ui/assets
npx chassis-assets build --cwd vendor/assets --clean --brand acme --app site --platform web

The build writes vendor/assets/dist/web/site/acme/; --out <dir> writes elsewhere, relative to the submodule, so give it an absolute path to write into the project. For another job, give the filters of that job.

While you change the assets, npx chassis-assets build --cwd vendor/assets --watch --brand acme --app site keeps running and builds the job again on every change under source/.

A project that reads a few files of the output does not have to fetch and build all of it. The --include option builds the files that match a pattern, and chassis-assets lfs prints the Git LFS paths of the same patterns, so git lfs pull fetches those files only:

Shell
FILTERS=(--cwd vendor/assets --brand acme --app site --include "fonts/**" "images/logo/**")
git -C vendor/assets lfs pull --include "$(npx chassis-assets lfs "${FILTERS[@]}")"
npx chassis-assets build --clean "${FILTERS[@]}"

A pattern is a path of source/ in the folder of the app. The build system page has the patterns and the --type option.

The fonts and the raster images are Git LFS files. A checkout without Git LFS holds pointer files in their place, and the build fails and lists them. Install Git LFS from git-lfs.com and run git lfs pull in the submodule.

Build from a clone

A clone is the way to go when you change the assets yourself, in your own repository of assets. It needs Node.js 22.12 or later and Git LFS; the Quick Start page has the setup and the scripts the repository holds.

Shell
git clone https://github.com/acme/acme-assets.git
cd acme-assets
npm install
npx chassis-assets build --platform web

--brand, --app and --platform each take one or more values and combine. npx chassis-assets build --dry-run prints the jobs without writing, and npx chassis-assets build --help prints every option. The build system page describes them.

Output layout

The folder of a job holds one folder per type, with the subfolders of the source kept. For a source with a font role, a few images, a few icons and a data/ folder, the build writes:

TEXT
dist/web/<app>/<brand>/
├── data/
│   └── country-list.json
├── fonts/
│   ├── fonts.css
│   ├── ui-license.txt
│   ├── ui-normal.woff2
│   └── ...
├── icons/
│   ├── arrow-right-solid.svg
│   └── ...
└── images/
    ├── hero-banner.png
    ├── hero-banner@2x.png
    └── logo/
        └── wordmark.svg

Output names

An application reads a file by its path in the folder of the job, and the build derives that path from the source. A file of source/<brand>/<app>/<type>/ or source/_default/<app>/<type>/, or of the _shared/<type>/ folder of either brand, is at <type>/ of the job, in the same subfolders, with its name in kebab-case:

SourceWeb output
images/logo/wordmark.svgimages/logo/wordmark.svg
images/HeroBanner@2x.pngimages/hero-banner@2x.png
data/brand.tokens.jsondata/brand-tokens.json

The indicator stays at the end of a name, and a dot inside a name becomes a hyphen. The build renames files, not folders. A path so stays the same in every brand that has the file, whether the file comes from the folder of the brand or from the default brand.

To find the name of a file, list the output of the job, or the folder of a type:

Shell
find dist/web/site/acme/images -name 'hero-banner*'

Copy the output

A web application serves the files from its static folder. Copy the folder of the job as it is, so that the paths inside it stay the ones this page uses. From the root of a project with the submodule at vendor/assets:

Shell
mkdir -p public/assets
cp -R vendor/assets/dist/web/site/acme/. public/assets/

The samples of this page read the files from /assets/, as this copy serves them.

Bundler alias

A bundler can read the output where the build wrote it, without a copy. Add an alias to the folder of the job, and import a file by its output name. In vite.config.js:

JavaScript
import { fileURLToPath } from 'node:url'
import { defineConfig } from 'vite'

export default defineConfig({
  resolve: {
    alias: {
      '@assets': fileURLToPath(new URL('./vendor/assets/dist/web/site/acme', import.meta.url))
    }
  }
})

In webpack.config.js, the alias goes with a rule that emits the fonts and the images as files:

JavaScript
const path = require('node:path')

module.exports = {
  resolve: {
    alias: {
      '@assets': path.resolve(__dirname, 'vendor/assets/dist/web/site/acme')
    }
  },
  module: {
    rules: [{ test: /\.(woff2?|png|jpe?g|webp|svg)$/, type: 'asset/resource' }]
  }
}

With either one, an import gives the URL of the file:

JavaScript
import '@assets/fonts/fonts.css'
import wordmark from '@assets/images/logo/wordmark.svg'

Vite gives a small file, such as this SVG, as a data: URL in place of a path. The import of the stylesheet needs a webpack that reads CSS without a rule for it; with an older one, add a rule with css-loader.

Parcel needs no alias: it resolves a relative path to a file of the output in url() of a stylesheet and in new URL('<path>', import.meta.url) of a script.

Fonts

The fonts/ folder holds the WOFF and WOFF2 files of the source, the stylesheets and the licenses. A font file is named by its role and its weight, not by its family, so a brand with other families has the same file names for its roles. A variable font holds every weight of its role and is named by the role alone, ui.woff2, with ui-italic.woff2 for the italic. A role that the brand sets in the family of another role has no files, so the roles that have files differ by brand.

TEXT
dist/web/<app>/<brand>/fonts/
├── code-license.txt
├── code-normal.woff2
├── fonts.css
├── ui-italic.woff2
├── ui-license.txt
├── ui-normal-italic.woff2
├── ui-normal.woff2
├── ui-strong.woff2
└── ui.woff2

The fonts page has the roles, the weights and what each platform gets.

A font of the default output has every character of its source file. If your pages are written in a few scripts only, build with --subset: the same files, under the same names, hold the characters of the ranges you name and are smaller to download. See Font subsets.

A variable font with an optical size axis, opsz, is drawn in another cut at each font size, since a browser sets the axis from the size of the text. A build with --subset fixes the axis at the value that axes of chassis.subset names for the brand, so every size shows the same cut. With a default build, font-optical-sizing: none in your styles keeps the cut of the default value of the axis.

Add --split to the build, and it writes each declared font once per range too, such as ui-latin.woff2 and ui-latin-ext.woff2, and the stylesheet gets a rule per range. Your pages stay as they are: link the stylesheet, and a browser downloads the file of a range only for a page that has a character of it. If you preload a font, name the file of the range.

Font stylesheets

The stylesheet fonts.css of a brand declares every family of the brand, under the family name of each font. It declares the variable font of a role where the family has one, and one file per weight where it has none. Link it and the declarations are done:

HTML
<link rel="stylesheet" href="/assets/fonts/fonts.css" />

Each rule reads its file by a relative URL, url("ui.woff2"), so the stylesheet works only beside the font files. The family name of each role, to use in font-family, is in the comment above its rules. One stylesheet declares every family because a brand may set several roles in one family, which a stylesheet per role would declare twice.

Own declarations

Write the @font-face rules yourself when the family name has to be one of your own, such as the name a design token holds. Use the file names of the output, and one rule per file:

CSS
@font-face {
  font-family: 'Brand Text';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('/assets/fonts/ui-normal.woff2') format('woff2');
}

@font-face {
  font-family: 'Brand Text';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('/assets/fonts/ui-strong.woff2') format('woff2');
}

body {
  font-family: 'Brand Text', sans-serif;
}

The weight of a role is the choice of the brand; read it in the stylesheet of the brand. To declare a variable font, give the rule the range of weights the file holds, such as font-weight: 100 900; the range is in the stylesheet too. Chassis Tokens owns the names of the font roles, see the Chassis Tokens docs.

Licenses

The build copies the license of each role beside its fonts, as <role>-license.txt. Keep these files, such as ui-license.txt and code-license.txt, with the fonts when you copy them to another folder.

Images

The images/ folder holds every image of the source, in the same subfolders, with kebab-case names and the indicator kept. An image has the formats and the variants the designer exported: the default build writes no @2x file and no WebP file of its own.

TEXT
dist/web/<app>/<brand>/images/
├── hero-banner.png
├── hero-banner@2x.png
├── hero-banner@3x.png
├── logo/
│   ├── wordmark.png
│   └── wordmark.svg
└── onboarding/
    ├── welcome-dark.png
    ├── welcome-dark@2x.png
    ├── welcome-light.png
    └── welcome-light@2x.png

The images page has the naming rules and what each platform gets.

Variants

An image with @2x and @3x variants goes into srcset, one variant per pixel density. Use the file without an indicator as src:

HTML
<img
  src="/assets/images/hero-banner.png"
  srcset="/assets/images/hero-banner.png 1x, /assets/images/hero-banner@2x.png 2x, /assets/images/hero-banner@3x.png 3x"
  alt="Hero banner"
/>

Formats

An image that the output has as WebP and as PNG goes into a <picture> element, with the PNG as the fallback. In the default output these are the images the designer exported in both formats, so use the element only for an image that has both files. A build with chassis-assets build --webp writes a WebP beside every PNG and JPEG, and --avif an AVIF; both need the package sharp, see the build system page.

HTML
<picture>
  <source
    type="image/webp"
    srcset="/assets/images/hero-banner.webp 1x, /assets/images/hero-banner@2x.webp 2x"
  />
  <img
    src="/assets/images/hero-banner.png"
    srcset="/assets/images/hero-banner.png 1x, /assets/images/hero-banner@2x.png 2x"
    alt="Hero banner"
  />
</picture>

Icons

The icons/ folder holds every file of icons/ of the source, in its subfolders, with kebab-case names, one file per icon:

TEXT
dist/web/<app>/<brand>/icons/
├── arrow-right-outline.svg
├── arrow-right-solid.svg
└── ...

The icons page has what each platform gets.

An icon file is an image. Show it with an <img> element, or put its markup into the page, where an icon drawn in currentcolor takes the color of the text:

HTML
<img src="/assets/icons/arrow-right-solid.svg" alt="" width="24" height="24" />

Other assets

The build copies any other folder under an app as it is, with the names in kebab-case. A source file source/<brand>/<app>/data/country-list.json is in the output of the brand as data/country-list.json:

TEXT
dist/web/<app>/<brand>/data/
└── country-list.json

A folder that only some brands hold is in the output of those brands only. Read a file of such a folder by its output name:

JavaScript
const countries = await fetch('/assets/data/country-list.json').then((response) => response.json())

The other assets page describes these folders.

Brand switching

Every brand of chassis.build.brands has a folder of its own beside the others, dist/web/<app>/<brand>/. A file has the same path in each brand that has it, so an application changes brand by reading another folder, with no change to the paths in its code.

To ship one brand, copy the folder of that brand at build time:

Shell
BRAND=globex
mkdir -p public/assets
cp -R vendor/assets/dist/web/site/$BRAND/. public/assets/

To choose the brand in the browser, copy each brand into a folder of its name and build the path from the brand:

Shell
mkdir -p public/assets
cp -R vendor/assets/dist/web/site/. public/assets/
JavaScript
export function assetUrl(brand, path) {
  return `/assets/${brand}/${path}`
}

document.querySelector('#logo').src = assetUrl('globex', 'images/logo/wordmark.svg')

Brand fallback

The build fills the output of a brand with the files of its folder in source/ and with the files of the default brand that the brand does not replace. A file of the brand replaces the default file of the same path, so a file that every brand shares is held once by the default brand, and a file that differs is held by each brand under the same name.

The brands of an app do not have to hold the same files. A file that only the folder of one brand holds, with no default file of its path, is in the output of that brand only, and a font role that a brand sets in the family of another role has no files in its output. Read such a file only for the brands that have it, and list the output of each brand to see which they are:

Shell
diff <(cd vendor/assets/dist/web/site/acme && find . -type f | sort) \
     <(cd vendor/assets/dist/web/site/globex && find . -type f | sort)

fonts.css of each brand declares the fonts of that brand: link the stylesheet and you get the fonts of the brand, whichever roles have files.

A brand with font files and no stylesheet of its own gets fonts.css of the default brand if there is one, which declares the family names of the default fonts, and no stylesheet otherwise. Add fonts.css to fonts/ of the brand in source/, or write own declarations.

Continuous integration

A workflow of your application builds the job before it builds the application, so the output is never committed. This GitHub Actions job checks out the submodule, pulls its Git LFS files, installs the package of the project, builds the job and copies it:

YAML
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
        with:
          submodules: true

      - uses: actions/setup-node@v7
        with:
          node-version-file: vendor/assets/.nvmrc

      - name: Build the assets
        run: |
          git -C vendor/assets lfs pull
          npm ci
          npx chassis-assets build --cwd vendor/assets --clean --brand acme --app site --platform web

      - name: Copy the assets
        run: |
          mkdir -p public/assets
          cp -R vendor/assets/dist/web/site/acme/. public/assets/

A workflow that uses a release archive needs none of these steps: download the archive of the job with gh release download and extract it.

The commands of this job were run in a project with the submodule; the workflow itself was not run on GitHub Actions.

Best practices

These practices keep your application reading the output as the build wrote it, with the names and the folders of dist/web/.

  • Read a file by its output name: the web names are kebab-case and a dot inside a name is a hyphen, so a source file brand.tokens.json is brand-tokens.json in the output. Find a name with find dist/web/<app>/<brand> -name '<pattern>'.
  • Keep the stylesheet beside its fonts: fonts.css reads its font files by a relative URL. Copy fonts/ whole.
  • Ship the licenses: copy <role>-license.txt with the fonts of fonts/.
  • Pin what you build: a submodule is pinned to a commit and an archive to a version, so a renamed file reaches your application only when you move the pin. A change to a name of dist/ is a breaking change of the repository of assets.

Avoid the habits that undo this:

  • Do not edit dist/: a full chassis-assets build removes it first, and --clean removes the folders of the selected jobs. Change the file in source/ and build again.
  • Do not expect a file the designer did not export: the default build copies. An image without an @2x file in source/ has none in the output, and one without a .webp file has one only in a build with --webp.

Troubleshooting

Each entry gives the message or the symptom, then the cause and the fix.

Build fails on pointers

The build stops with <count> source file(s) are Git LFS pointers, not files: <files>. Run `git lfs pull`, or pass --allow-lfs-pointers to copy the pointers. The checkout has no Git LFS files, so the fonts and the raster images are pointers of a few lines. Install Git LFS, run git lfs pull in the repository or the submodule, and build again.

Font does not load

The browser logs Failed to decode downloaded font for a file of fonts/. The output was built with --allow-lfs-pointers or CHASSIS_ALLOW_LFS_POINTERS=1, so the font is a pointer file. Run git lfs pull and build again without the option.

Font file not found

The browser gets a 404 for a font that the stylesheet of fonts/ names. The stylesheet was copied without the font files beside it, and its URLs are relative. Copy the whole folder.

File not found

The browser gets a 404 for a file that is in source/. The build renamed it, or left it out: the web names are kebab-case with a hyphen for a dot inside the name, and fonts/ keeps only .woff, .woff2, .css, .scss and .txt files. List the output of the type, find dist/web/<app>/<brand>/fonts, and use the name it prints.

Unknown brand

The build stops with Unknown brand "<name>". Configured: <brands>. The value of --brand is not in chassis.build.brands of package.json. Use a configured brand, or add the brand to the configuration. --app and --platform fail in the same way.

No job selected

The build stops with The filters select no job. Check --brand, --app and --platform together. Each filter value is configured, but no app has that platform: chassis-assets build --app mobile --platform web fails in the configuration of this page, where mobile is built for iOS and Android. Read the jobs with chassis-assets build --dry-run.

Next steps

Continue with one of these pages: