Skip to content
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

Provide build & config information to afterBuild event handlers #1600

Closed
MoritzLost opened this issue Jan 21, 2021 · 1 comment
Closed

Provide build & config information to afterBuild event handlers #1600

MoritzLost opened this issue Jan 21, 2021 · 1 comment

Comments

@MoritzLost
Copy link

Is your feature request related to a problem? Please describe.

The beforeBuild and afterBuild events allow site and plugin authors to perform custom tasks before or after the build. However, they need to be passed some information on the build progress and configuration. In particular, if I want to perform some post-processing on the site output, the afterBuild event handler needs to know the output directory. This is trivial in a site configuration file, but not in a plugin configuration file. Currently, a plugin would need to get that information directly from the site using it:

// .eleventy.js
const myEleventyPlugin = require('my-eleventy-plugin');
eleventyConfig.addPlugin(myEleventyPlugin({ outputDir: path.resolve(__dirname, 'dist/') } ));

Describe the solution you'd like

Eleventy should pass any information it has on the completed build (for afterBuild) or the pending build (for beforeBuild) as well as the configuration to event handlers to enable a wide range of use cases. I don't know how much data is available internally and how much can be exposed at those points in the lifecycle, but passing as much data as possible would be beneficial to allow plugins to perform whatever tasks they want. The most important information, at least for my use case, would be the input and output directories, as specified with the dir key.

Describe alternatives you've considered

Maybe eleventy could just pass the elventyConfig to the event handler instead of a custom data object? Though the documentation currently doesn't list a way to get configuration options like the dir options back, only how to set them. So if this approach is possible, it should be documented how to access this configuration through the eleventyConfig API.

Additional context

This is a follow-up to #1143 and #729

@zachleat
Copy link
Member

I think this was solved with #1320

eleventyConfig.dir is available to plugins and should also be available in event callbacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants