Adding ./src/*.txt to ./dist during build?

Using the Observable Framework, maybe I’m missing something… But “npm run build” does not copy all files to ./dist from the src/docs directory.

e.g.
./src/hello.txt --> ./dist/hello.txt

Basically, I couldn’t find built-in way other file types to be “included in build”. While adding a FileAttachment() somewhere in Markdown, does get the “hello.txt” file into cache, that also mangles name/path.

I can copy them outside “npm build”, but just seem strange…

Yes, we only copy files that are explicitly referenced, not everything in src. We view this as safer: you might have other files in src that are used to build the project but that you don’t want to make visible to users.

The recommended way to get these files included is to use FileAttachment, as you discovered. And we use content hashes to ensure that when the contents of the file changes, the path to the file also changes, allowing immutable caching and ensuring consistency when projects are deployed.

Maybe you could elaborate on why you want these additional files in src? Is it a robots.txt or something?

Yes, we only copy files that are explicitly referenced, not everything in src […]

Makes total sense, as a default… I guess I thought there be something in observable.config.ts to include “raw” files/directory in a build (i.e. some “whitelist”).

Maybe you could elaborate on why you want these additional files in src ? Is it a robots.txt or something?

The specific files I ran into were example plain-text router configuration files. I just wanted to have a “download” link to the plain text file within the OF page describing it.

And we use content hashes […]

I actually like that part, normally. And the mangled name be fine, even preferable, here.

But there other cases where stable/canonical URLs to some static files be useful. i.e. some neutral URL for “latest” version of some data.

The recommended way to get these files included is to use FileAttachment , as you discovered.

Well almost… I still couldn’t figure out how to build a link in Markdown nor html that linked to download the hello.txt.

I would have thought this would have worked, but it doesn’t:


\```js echo
const file = FileAttachment("hello.txt")
const txthref = file.href
\```

[Link Markdown](${txthref})

<a href=${txthref}>Link HTML</a>

It gets stuff like GET /$%7BFileAttachment(%22hello.txt%22).href%7D GET /%60$%7Btxthref%7D%60 since that’s what gets built in the HTML.

The ${txthref} works elsewhere but not in an href= or markdown’s ()

Anyway, most stuff has been pretty logical in Framework. But, one is confusing.