1
1
import { tmpdir } from 'os'
2
2
import { join } from 'path'
3
- import getConfig from '../config'
4
3
import fs from 'mz/fs'
5
4
import uuid from 'uuid'
6
5
import del from 'del'
@@ -14,10 +13,8 @@ export default async function build (dir) {
14
13
15
14
try {
16
15
await runCompiler ( compiler )
17
-
18
- // Pass in both the buildDir and the dir to retrieve config
19
- await writeBuildStats ( buildDir , dir )
20
- await writeBuildId ( buildDir , dir )
16
+ await writeBuildStats ( buildDir )
17
+ await writeBuildId ( buildDir )
21
18
} catch ( err ) {
22
19
console . error ( `> Failed to build on ${ buildDir } ` )
23
20
throw err
@@ -48,24 +45,22 @@ function runCompiler (compiler) {
48
45
} )
49
46
}
50
47
51
- async function writeBuildStats ( buildDir , dir ) {
52
- const dist = getConfig ( dir ) . distDir
48
+ async function writeBuildStats ( dir ) {
53
49
// Here we can't use hashes in webpack chunks.
54
50
// That's because the "app.js" is not tied to a chunk.
55
51
// It's created by merging a few assets. (commons.js and main.js)
56
52
// So, we need to generate the hash ourself.
57
53
const assetHashMap = {
58
54
'app.js' : {
59
- hash : await md5File ( join ( buildDir , dist , 'app.js' ) )
55
+ hash : await md5File ( join ( dir , '.next' , 'app.js' ) )
60
56
}
61
57
}
62
- const buildStatsPath = join ( buildDir , dist , 'build-stats.json' )
58
+ const buildStatsPath = join ( dir , '.next' , 'build-stats.json' )
63
59
await fs . writeFile ( buildStatsPath , JSON . stringify ( assetHashMap ) , 'utf8' )
64
60
}
65
61
66
- async function writeBuildId ( buildDir , dir ) {
67
- const dist = getConfig ( dir ) . distDir
68
- const buildIdPath = join ( buildDir , dist , 'BUILD_ID' )
62
+ async function writeBuildId ( dir ) {
63
+ const buildIdPath = join ( dir , '.next' , 'BUILD_ID' )
69
64
const buildId = uuid . v4 ( )
70
65
await fs . writeFile ( buildIdPath , buildId , 'utf8' )
71
66
}
0 commit comments