1 | 'use strict'
|
2 |
|
3 | const fs = require('fs')
|
4 | const { join } = require('path')
|
5 |
|
6 |
|
7 | module.exports = function decorateOptions({ paths = {}, target, ...rest } = {}) {
|
8 | const { NODE_ENV } = process.env
|
9 |
|
10 | const flags = {
|
11 | mode: NODE_ENV,
|
12 | storybook: target && target.includes('storybook'),
|
13 | electron: target && target.includes('electron'),
|
14 | development: NODE_ENV !== 'production',
|
15 | production: NODE_ENV === 'production',
|
16 | }
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | const context = paths.context || fs.realpathSync(process.cwd())
|
22 | const src = paths.src || join(context, 'src', flags.electron ? 'renderer' : '')
|
23 |
|
24 | const defaults = {
|
25 | chunkHash: flags.production ? '.[chunkhash]' : '',
|
26 | devServer: {},
|
27 | flags,
|
28 | publicPath: '/',
|
29 | sassOptions: {},
|
30 | paths: {
|
31 | context,
|
32 | output: join(context, 'public'),
|
33 | static: join(context, 'static'),
|
34 | appIndex: join(src, 'index.js'),
|
35 | htmlTemplate: join(src, 'index.html'),
|
36 | iconSpriteIncludes: [join(src, 'media/icons')],
|
37 | jsLoaderIncludes: [src],
|
38 | },
|
39 | }
|
40 |
|
41 | if (flags.electron) {
|
42 |
|
43 |
|
44 | defaults.chunkHash = ''
|
45 | defaults.paths.output = join(context, 'src/build')
|
46 | }
|
47 |
|
48 |
|
49 | return {
|
50 | ...defaults,
|
51 | ...rest,
|
52 | paths: {
|
53 | ...defaults.paths,
|
54 | ...paths,
|
55 | },
|
56 | }
|
57 | }
|