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

Allow BUILD_ID to be set using generateBuildId (minor) #3873

Merged
merged 5 commits into from
Mar 31, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1089,6 +1089,20 @@ module.exports = {
}
```

#### Configuring the build ID

Next.js uses a constant generated at build time to identify which version of your application is being served. This can cause problems in multi-server deployments when `next build` is ran on every server. In order to keep a static build id between builds you can provide the `generateBuildId` function:

```js
// next.config.js
module.exports = {
generateBuildId: async () => {
// For example get the latest git commit hash here
return 'my-build-id'
}
}
```

### Customizing webpack config

<p><details>
Expand Down
5 changes: 2 additions & 3 deletions server/build/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import { join } from 'path'
import promisify from '../lib/promisify'
import fs from 'fs'
import uuid from 'uuid'
import webpack from 'webpack'
import getConfig from '../config'
import {PHASE_PRODUCTION_BUILD} from '../../lib/constants'
import { PHASE_PRODUCTION_BUILD } from '../../lib/constants'
import getBaseWebpackConfig from './webpack'

const access = promisify(fs.access)
const writeFile = promisify(fs.writeFile)

export default async function build (dir, conf = null) {
const config = getConfig(PHASE_PRODUCTION_BUILD, dir, conf)
const buildId = uuid.v4()
const buildId = await config.generateBuildId() // defaults to a uuid

try {
await access(dir, (fs.constants || fs).W_OK)
Expand Down
2 changes: 2 additions & 0 deletions server/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import findUp from 'find-up'
import uuid from 'uuid'

const cache = new Map()

Expand All @@ -11,6 +12,7 @@ const defaultConfig = {
assetPrefix: '',
configOrigin: 'default',
useFileSystemPublicRoutes: true,
generateBuildId: () => uuid.v4(),
generateEtags: true,
pageExtensions: ['jsx', 'js']
}
Expand Down