mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
support custom build directory in next export (#2135)
* use custom build directory instead of .next if specified, helpful log messages. * Remove some unwanted newlines.
This commit is contained in:
parent
24439f96ec
commit
ca9146c421
|
@ -10,21 +10,23 @@ import { printAndExit } from '../lib/utils'
|
||||||
|
|
||||||
export default async function (dir, options) {
|
export default async function (dir, options) {
|
||||||
dir = resolve(dir)
|
dir = resolve(dir)
|
||||||
const outDir = options.outdir
|
const config = getConfig(dir)
|
||||||
const nextDir = join(dir, '.next')
|
const nextDir = join(dir, config.distDir || '.next')
|
||||||
|
|
||||||
log(` Exporting to: ${outDir}\n`)
|
log(` using build directory: ${nextDir}`)
|
||||||
|
|
||||||
if (!existsSync(nextDir)) {
|
if (!existsSync(nextDir)) {
|
||||||
console.error('Build your with "next build" before running "next start".')
|
console.error(
|
||||||
|
`Build directory ${nextDir} does not exist. Make sure you run "next build" before running "next start" or "next export".`
|
||||||
|
)
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
const config = getConfig(dir)
|
|
||||||
const buildId = readFileSync(join(nextDir, 'BUILD_ID'), 'utf8')
|
const buildId = readFileSync(join(nextDir, 'BUILD_ID'), 'utf8')
|
||||||
const buildStats = require(join(nextDir, 'build-stats.json'))
|
const buildStats = require(join(nextDir, 'build-stats.json'))
|
||||||
|
|
||||||
// Initialize the output directory
|
// Initialize the output directory
|
||||||
|
const outDir = options.outdir
|
||||||
await del(join(outDir, '*'))
|
await del(join(outDir, '*'))
|
||||||
await mkdirp(join(outDir, '_next', buildStats['app.js'].hash))
|
await mkdirp(join(outDir, '_next', buildStats['app.js'].hash))
|
||||||
await mkdirp(join(outDir, '_next', buildId))
|
await mkdirp(join(outDir, '_next', buildId))
|
||||||
|
|
Loading…
Reference in a new issue