-
-
Notifications
You must be signed in to change notification settings - Fork 491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add eleventy.beforeAll event #2427
Comments
Just thinking out loud, if you have an
Both of the above will only run at the beginning of a project. The exception being that if you save your |
@zachleat Thanks for the suggestion! That should definitely work for synchronous tasks. I'm trying to update some files on the file system once before running Eleventy... Is it possible to run async tasks before Eleventy from Again I can always still run some code in a separate script instead of putting it in the Eleventy config, but just trying to see if there's a way to finagle this in lieu of an Here's what I've tried:
|
I believe the original suggestion will work better now with the advent of async configs in v3.0. See #614. Let me know if this doesn’t work for this use case somehow! |
This works great in v3.x!
{
"type": "module",
"scripts": {
"compile": "eleventy",
"watch": "npm run compile -- --watch",
"serve": "npm run compile -- --serve"
},
"devDependencies": {
"@11ty/eleventy": "3.0.0-alpha.5"
}
}
import { writeFile } from 'node:fs/promises'
const content = `# The title
Lorem ipsum dolor sit amet.
`
await writeFile('src/index.md', content, 'utf8')
export default async function(eleventyConfig) {
return {
dir: {
input: 'src',
output: 'dist',
},
}
} This results in That's exactly what I was looking for. |
Problem: When I add some code to an event like
eleventy.before
oreleventy.beforeWatch
, this code runs before every build (or every re-build). But there is not an easy way to run some code only once before the very first build.Solution: A new
eleventy.beforeAll
event that would run once before the first build (but would not run again before any rebuilds while watching or serving) would provide a great way to run some code once before the first build.Alternatives: I could run some code in a separate script instead of putting it in the Eleventy config.
Context: An
eleventy.beforeAll
event would allow me to keep my code together in one place instead of splitting it apart across several files.The text was updated successfully, but these errors were encountered: