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

lib/utils/build.js now requires postBuild function in gatsby-node #273

Merged
merged 4 commits into from
May 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,6 @@ files which start with an underscore:
found' page. If you `<Link>` to an unknown URL, this page will be shown. Note: in
production, you'll need to [set up your server host to show this page when it can't find
the requested file](https://github.com/gatsbyjs/gatsby/pull/121#issuecomment-194715068).
* (optional) `post-build.js` - a `function(pages, cb)` you can provide to do final
processing on all generated content.
* (optional) `gatsby-browser.js` - a way to hook into key application events. Export
`onRouteChange` of type `function(location)` to be notified whenever React-Router
navigates.
Expand All @@ -249,8 +247,8 @@ Gatsby uses [webpack-configurator](https://github.com/lewie9021/webpack-configur
to make changing the webpack loaders easy. The default set of loaders is organized by [key](lib/utils/webpack.config.js#L125).

Gatsby uses `gatsby-node.js` to pass control to the user before
resolving the final webpack configuration. `gatsby-node.js` should
live in the root of your project and export a function which accepts a
resolving the final build configuration. `gatsby-node.js` should
live in the root of your project can export a function which accepts a
webpack-configurator config object and an environment string. The
environment string will be one of `develop`, `static` or
`production`.
Expand Down Expand Up @@ -339,6 +337,18 @@ which you can use to enhance Gatsby.
It is also possible to
[write your own plugins](https://webpack.github.io/docs/how-to-write-a-plugin.html).

### Perform additional post build step

Gatsby also uses `gatsby-node.js` to pass control of the final build step over
to the user when running `gatsby build`. The post build function takes two arguments, the pages and the callback for completing the build:

```javascript
export.postBuild = function(pages, callback) {
// perform actions on pages here

callback();
}
```

### How to write your own wrappers
* Coming...
Expand Down
12 changes: 6 additions & 6 deletions lib/utils/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ 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.')
console.log(e)
console.log('Failed to load gatsby-node.js, skipping custom post build script', e)
}
}

if (customPostBuild) {
console.log('Performing custom post-build steps')

globPages(directory, (globError, pages) =>
return globPages(directory, (globError, pages) =>
customPostBuild(pages, (error) => {
if (error) {
console.log('customPostBuild function failed')
Expand All @@ -30,9 +30,9 @@ function customPost (program, callback) {
return callback()
})
)
} else {
callback()
}

return callback()
}

function post (program, callback) {
Expand Down