1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

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

* Allow BUILD_ID to be set in the environment

This makes multi server deploys with Capistrano possible.

* next.config.js generateBuildId support

enable customising the build id via config

* Provide default for generateBuildId

* This is not used
This commit is contained in:
Craig McNamara 2018-03-31 07:34:52 -07:00 committed by Tim Neutkens
parent 085b2f806a
commit 7f335cb032
3 changed files with 18 additions and 3 deletions

View file

@ -1122,6 +1122,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>

View file

@ -1,10 +1,9 @@
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)
@ -12,7 +11,7 @@ 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)

View file

@ -1,5 +1,6 @@
// @flow
import findUp from 'find-up'
import uuid from 'uuid'
const cache = new Map()
@ -11,6 +12,7 @@ const defaultConfig = {
assetPrefix: '',
configOrigin: 'default',
useFileSystemPublicRoutes: true,
generateBuildId: () => uuid.v4(),
generateEtags: true,
pageExtensions: ['jsx', 'js']
}