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:
parent
085b2f806a
commit
7f335cb032
14
readme.md
14
readme.md
|
@ -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>
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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']
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue