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
lib/utils/build.js now requires postBuild function in gatsby-node #273
Conversation
Removes requirement for a post-build.js file in the root of the project for a custom post build step in gatsby build. Instead it requires for a postBuild export in the gatsby-node file in the root of the domain, where the webpack custom configuration is also stored.
@@ -10,7 +10,8 @@ function customPost (program, callback) { | |||
const directory = program.directory | |||
let customPostBuild | |||
try { | |||
customPostBuild = require(`${directory}/post-build`) | |||
const gatsbyNodeConfig = require(`${directory}/gatsby-node`) | |||
customPostBuild = gatsbyNodeConfig.postBuild | |||
} catch (e) { | |||
if (e.code !== 'MODULE_NOT_FOUND') { | |||
console.log('Failed to load custom post build script. It will be skipped.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually want something here like
if (e.code !== 'MODULE_NOT_FOUND') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the text of the log message should be something like console.log("Failed to load gatsby-node.js", e)
Could you also remove the mention of Looking good otherwise! |
Added a better error message for custom post-build actions defined in gatsby-node.js, explains to user that file cannot be used. Updated README.md by removing post-build.js option in the project structure and including a new section explaining how to include a post-build function for users.
Correct some errors in the README.
Looks great now (other than the 1 lint error). |
Changed strings from double to single quotes to avoid eslint error.
Should be good now? |
Yup! |
It would be nice to have Promise compatibility over this. |
@cusspvz perhaps down the road when all the APIs are set we could add promise support but for now, let's stick with callbacks for simplicity. |
@KyleAMathews Deal! Feel free to mention me whenever you need help with it. |
@cusspvz deal 👍 :-) my rough plan is once we switch to plugins to have a centralized API dispatch controller (or whatever this sort of thing should be called) which would then make it easy to check if the implementor returned a promise or will call the callback. |
2 years ago I've built this. I've used it several times on private projects, it is quite deprecated since most of the things it does can already be achieved easily with ES6 (such as classes). But maybe you could rely on some of its code base and grab some ideas because based on what you're telling me, it doesn't seems too different of what it does. :) |
Hiya @LukeSheard! 👋 This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here. Gatsby is built by awesome people like you. Let us say “thanks” in two ways:
If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’. Thanks again! 💪💜 |
Removes requirement for a post-build.js file in the root of the project for a custom post build step in gatsby build. Instead it requires for a postBuild export in the gatsby-node file in the root of the domain, where the webpack custom configuration is also stored.
Closes #239