Skip to content

assetsignore: keep .DS_Store off a Cloudflare Workers site

The problem

wrangler pages deploy skips **/.DS_Store on its own. A Worker with static assets ([assets] directory = "...") does not: every file in the folder is uploaded and served, including the .DS_Store files Finder leaves in each folder, which list the names of the files beside them. Wrangler reads <assets directory>/.assetsignore (.gitignore syntax), but for most sites that directory is a build output such as dist/, wiped on every build.

The method

Read every wrangler.toml / .json / .jsonc properly and collect each assets.directory, including [env.*] overrides. If the directory is inside a build folder (dist, out, build, .open-next), write the ignore file into the public/ beside it: the bundler copies public/ into the build every time, dotfiles included (checked with a real Vite build). Otherwise write it into the directory. Append only missing lines; a second run changes nothing.

# public/.assetsignore  ->  copied to dist/.assetsignore on build
.DS_Store
._*
Thumbs.db

A pattern with no slash matches at any depth, so these three lines cover every subfolder.

Sample

./assetsignore -n ~/sites          # what it would change
./assetsignore ~/sites             # write the files, then redeploy each site
./assetsignore --also '*.map' ~/sites

Limits

  • Only four build-folder names are known; other layouts need the file written by the build.
  • Files already live stay live until the next deploy.
  • The older Workers Sites ([site] bucket) config is not read.

Code

methods/assetsignore/ in the methods repository: the script, a README and a 20-check test (one more with the npm ignore package wrangler uses, when IGNORE_PKG points at it).