-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
69 lines (62 loc) · 1.58 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { Configuration } from 'webpack'
import compact from 'lodash/compact'
import concat from 'lodash/concat'
import map from 'lodash/map'
import split from 'lodash/split'
import trim from 'lodash/trim'
import { Presets } from './webpack/build-utils/presets/types'
import clientConfig from './webpack/webpack.client'
import serverConfig from './webpack/webpack.server'
delete process.env['TS_NODE_PROJECT'] // needed to make sure other loaders don't use the tsconfig version from the environment
/**
* The environment
*
* This object is also passed down to all presets
*/
export type Env = {
mode: 'production' | 'development'
presets: Presets[]
type?: 'client' | 'server'
target?: 'client' | 'server'
watch: boolean
}
/**
* The default environment
*
* Presets that are both used on the server and client
* can be added here
*/
const defaultEnv: Env = {
mode: 'production',
presets: ['base', 'babel', 'tsconfigpaths'],
watch: false,
}
/**
* Args already parsed by webpack and passed to the config function
*/
type Args = {
color?: boolean
watch?: boolean
}
/**
* Entry point for webpack
*/
function config(
{ presets, ...rest }: Record<string, string> = {},
args: Args = {}
): Configuration[] {
const env: Env = Object.assign({}, defaultEnv, rest, {
presets: compact(
concat<Presets>(
map(split(presets, ','), trim) as Presets[],
defaultEnv.presets
)
),
watch: !!args.watch,
})
const sConfig = serverConfig(env)
const cConfig = clientConfig(env)
// console.log(cConfig)
return [sConfig, cConfig]
}
export default config