-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnext.config.js
97 lines (84 loc) · 2.34 KB
/
next.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Created by lei_sun on 2019/7/9.
*/
const { PHASE_DEVELOPMENT_SERVER, PHASE_EXPORT } = require('next/constants')
const fs = require('fs')
module.exports = (phase, defaultConfig, options) => {
let projectConfig = null
let pkg = null
const curFolder = process.cwd()
const curProjectConfigPath = curFolder + '/project.config.js'
const curPkgPath = curFolder + '/package.json'
if (fs.existsSync(curProjectConfigPath)) {
projectConfig = require(curProjectConfigPath)
} else {
projectConfig = require('./project.config.js')
}
if (fs.existsSync(curPkgPath)) {
pkg = require(curPkgPath)
} else {
pkg = require('./package.json')
}
// const env = (pkg && pkg.config && pkg.config.env && pkg.config.env.toUpperCase()) || 'PROD'
// console.log('projectConfig', projectConfig)
let { env, version, prefix, protocol, host, port } = projectConfig
// console.log('options', options)
if (options != undefined) {
version = options.version
prefix = options.prefix
protocol = options.protocol
host = options.host
port = options.port
}
if (phase === PHASE_DEVELOPMENT_SERVER) {
prefix = ''
}
// console.log('phase', phase, version, prefix, protocol, host, port)
let configObj = {
// target: 'serverless',
// crossOrign: 'anonymous',
serverRuntimeConfig: {},
publicRuntimeConfig: {
version,
prefix,
protocol,
host,
port,
env,
phase,
isExport: (phase === PHASE_EXPORT)
},
transpilePackages: ["antd", "@ant-design", "rc-util", "rc-pagination", "rc-picker", "rc-notification", "rc-tooltip", "rc-tree", "rc-table"],
generateBuildId: async () => {
return 'nsgm-cli-' + version
},
exportPathMap: async function (defaultPathMap, { dev, dir, outDir }) {
if (dev) {
return defaultPathMap
}
return defaultPathMap
},
generateEtags: false,
useFileSystemPublicRoutes: true,
}
if (phase !== PHASE_DEVELOPMENT_SERVER) {
configObj = {
...configObj,
distDir: 'build',
assetPrefix: prefix,
async rewrites() {
return [
{
source: prefix === '' ? '/' : prefix,
destination: '/'
},
{
source: prefix + '/:slug*',
destination: '/:slug*'
}
]
}
}
}
return configObj
}