Open tombreit opened 1 year ago
I believe this is a vite thing. Can you generate them inside of public/**
instead? https://vitejs.dev/guide/assets.html#the-public-directory
Sorry, I do not know how to to that... How should/would I reference this vite public dir?
Currently I build these files via
---
pagination:
data: bibtex
size: 1
alias: bibtex
permalink: "publications/bibtex/{{ bibtex.bibtexLabel }}.bib"
layout: "layouts/bibtex.njk"
---
{{ bibtex.bibtexItem | safe }}
I've found a promising vite config option: https://vitejs.dev/config/shared-options.html#assetsinclude
eleventyConfig.addPlugin(EleventyVitePlugin, {
viteOptions: {
assetsInclude: ['**/*.bib'],
}
});
...but this did not resolve my issue....
Perhaps related:
eleventy-plugin-vite seems to choke every static asset which is mentioned in a addPassthroughCopy
statement and not handled by vite, like a PDF file:
├── assets
│ ├── app.js
│ └── app.scss
├── downloads
│ └── myfile.pdf
├── eleventy.config.js
└── src
├── _includes
│ └── layout.njk
└── index.md
// eleventy.config.js
const EleventyVitePlugin = require('@11ty/eleventy-plugin-vite')
module.exports = function (eleventyConfig) {
eleventyConfig.addPlugin(EleventyVitePlugin);
eleventyConfig.addPassthroughCopy('assets');
eleventyConfig.addPassthroughCopy('downloads');
return {
dir: {
input: "src",
output: "_site"
},
}
}
❌ Build via npx eleventy
or npx eleventy --watch
, got
# _site generated via `npx eleventy`
_site/
├── assets
│ ├── index.74d94aed.css
│ └── index.b2fff5ad.js
└── index.html
✅ ...but expected (and strangely I get the desired result with the --serve
option):
# _site generated via `npx eleventy --serve`
_site/
├── assets
│ ├── app.js
│ ├── app.scss
│ ├── index.74d94aed.css
│ └── index.b2fff5ad.js
├── downloads
│ └── myfile.pdf
└── index.html
Am I doing something completely wrong? Thanks in advance for any hints.
I've put together a minimal eleventy project for this setup: https://github.com/tombreit/eleventy-vite-minimal/tree/vite-and-pdfs
@tombreit So if you have a public
folder on the same level in your repository as your src
, vite will serve files in that folder as if they were in your site's root in development and copy them to the root level of your _site
in production. For instance:
public/
|-- test.txt
src/
|-- [usual 11ty stuff here
and running eleventy --serve
(using vite) should serve http://localhost:8080/test.txt while running eleventy
should copy public/test.txt
to _site/test.txt
. (I'm trying to figure out the same thing as you, this is as far as I got.)
Can you generate them inside of public/** instead?
@zachleat Do mean generate them from src/
to public/
, where vite would “pick them up” and copy them to _site/
? [insert short break to read the fantastic 11ty docs] Ooooooh, I think I got you – I was not aware that we can “override” the output directory, i.e. set permalink
to a different directory than _site
.
So for instance I have a src/robots.txt.njk
with permalink: robots.txt
which currently generates _site/robots.txt
. With
---
permalink: "public/robots.txt"
permalinkBypassOutputDir: true
---
that files is generated at public/robots.txt
, it is served at http://localhost:8080/robots.txt in development and … sadly not copied to _site/robots.txt
in a production build, which seems to be expected in hindsight because it is created during said build. 😞
I seem to be missing something here …?
I had a similar problem with PDF files. I've managed to get it to work by having this folder structure
public/
myfile.pdf
favicon.ico
...
src/
index.njk
...
and then passthrough-copying public:
eleventyConfig.addPassthroughCopy("public");
This then gives the output of:
_site/
index.html
myfile.pdf
favicon.ico
The passthrough copying is necessary, it doesn't work if you just put public inside src.
For things such as sitemaps and feeds, I was able to get them to work by leaving them in src with a permalink like /public/sitemap.xml
.
Hi,
I'm generating some
*.bib
-files from global datajs
viapagination
. When building vianpx eleventy --serve
everything works as expected: These*.bib
-files end up in the output directory (here:_site/publications/bibtex/*bib
).These
bib
-files are plaintext files with bibliographic data and are not meant to be further processed by vite:But in a production build via
npx eleventy
, it seems these*.bib
-files get rendered by eleventy, but somehow got choked/missed/deleted by vite afterwards...:via
npx eleventy --serve
via
npx eleventy
If I disable eleventy-plugin-vite or generate these files as
*.html
(instead of*.bib
) everything works as expected.What am I doing wrong or how do I keep my generated
.bib
files in a production build?Versions
``` npm list ├── @11ty/eleventy-navigation@0.3.5 ├── @11ty/eleventy-plugin-vite@4.0.0 ├── @11ty/eleventy@2.0.0-beta.3 ├── @citation-js/plugin-bibtex@0.6.6 └── citation-js@0.6.6 ```