-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.ts
48 lines (41 loc) · 1.11 KB
/
webpack.config.ts
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
import path from 'path'
import type {
BuildEnv,
BuildMode,
BuildOptions,
BuildPath,
} from './config/build/types/config'
import buildWebpackConfig from './config/build/buildWebpackConfig'
const getApiUrl = (mode: BuildMode, apiUrl?: string) => {
if (apiUrl) {
return apiUrl
}
if (mode === 'production') {
return '/api'
}
return 'http://localhost:8000'
}
export default (env?: BuildEnv) => {
const paths: BuildPath = {
entry: path.resolve(__dirname, 'src', 'index.tsx'),
build: path.resolve(__dirname, 'build'),
html: path.resolve(__dirname, 'public', 'index.html'),
src: path.resolve(__dirname, 'src'),
locales: path.resolve(__dirname, 'public', 'locales'),
buildLocales: path.resolve(__dirname, 'build', 'locales'),
}
const mode: BuildOptions['mode'] = env?.mode ?? 'development'
const PORT = env?.port ?? 3000
const apiURL = getApiUrl(mode, env?.apiUrl)
const isAnalyze = env?.analyze ?? false
const isDev = mode === 'development'
return buildWebpackConfig({
mode,
paths,
isDev,
isAnalyze,
port: PORT,
apiURL,
project: 'frontend',
})
}