This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 238
/
config.ts
153 lines (134 loc) · 4.88 KB
/
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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import * as appRoot from 'app-root-path';
import * as path from 'path';
import { env } from '../env';
import { ensureAbsolutePath } from '../utils/utils';
import { IPublicConfig } from './IPublicConfig';
import { PrivateConfig } from './PrivateConfig';
export function createConfig(props: IPublicConfig): PrivateConfig {
const config = new PrivateConfig(props);
config.root = process.env.APP_ROOT || appRoot.path;
config.defaultCollectionName = 'default';
if (props.homeDir) {
config.homeDir = ensureAbsolutePath(props.homeDir, env.SCRIPT_PATH);
} else {
config.homeDir = env.SCRIPT_PATH;
}
config.modules = [env.FUSE_MODULES];
if (props.modules) {
config.modules = config.modules.concat(props.modules).map(item => ensureAbsolutePath(item, env.SCRIPT_PATH));
}
// make sure we have node_modules if that exists relatively to the script path (fuse.js)
// const relativeNodeModulePath = pathJoin(env.SCRIPT_PATH, 'node_modules');
// if (fileExists(relativeNodeModulePath)) {
// if (!config.modules.find(i => i === relativeNodeModulePath)) {
// config.modules.push(relativeNodeModulePath);
// }
// }
if (props.output) {
config.output = props.output;
}
if (props.alias) {
config.alias = props.alias;
}
if (props.tsConfig) {
if (typeof props.tsConfig === 'string') {
config.tsConfig = ensureAbsolutePath(props.tsConfig, env.SCRIPT_PATH);
} else {
config.tsConfig = props.tsConfig;
}
}
if (props.target) {
config.target = props.target;
}
// allow them by default
config.allowSyntheticDefaultImports = true;
if (props.allowSyntheticDefaultImports !== undefined) {
config.allowSyntheticDefaultImports = props.allowSyntheticDefaultImports;
}
config.webIndex = {
enabled: false,
};
if (typeof props.webIndex === 'boolean') {
config.webIndex.enabled = props.webIndex;
} else if (typeof props.webIndex === 'object') {
config.webIndex = props.webIndex;
config.webIndex.enabled = typeof props.webIndex.enabled === 'boolean' ? props.webIndex.enabled : true;
}
config.sourceMap = {
css: true,
vendor: false,
project: true,
sourceRoot: '/',
};
if (props.sourceMap !== undefined) {
if (props.sourceMap === false) {
config.sourceMap.project = false;
config.sourceMap.css = false;
}
if (typeof props.sourceMap === 'object') {
if (props.sourceMap.sourceRoot) {
config.sourceMap.sourceRoot = props.sourceMap.sourceRoot;
}
if (props.sourceMap.css === false) {
config.sourceMap.css = false;
}
if (props.sourceMap.vendor === true) {
config.sourceMap.vendor = true;
}
if (props.sourceMap.project === false) {
config.sourceMap.project = false;
}
}
}
config.plugins = props.plugins ? props.plugins : [];
if (props.logging) {
config.logging = props.logging;
} else {
config.logging = { level: 'succinct' };
}
config.webWorkers = { enabled: true };
if (props.webWorkers) {
if (typeof props.webWorkers === 'boolean') config.webWorkers.enabled = props.webWorkers;
if (typeof props.webWorkers === 'object') {
config.webWorkers = props.webWorkers;
config.webWorkers.enabled = props.webWorkers.enabled !== undefined ? props.webWorkers.enabled : true;
}
}
// dev server *********************************************************************************************
config.devServer = { enabled: false };
if (typeof props.devServer === 'boolean') {
config.devServer.enabled = props.devServer;
} else if (typeof props.devServer === 'object') {
config.devServer.enabled = typeof props.devServer.enabled === 'boolean' ? props.devServer.enabled : true;
config.devServer = props.devServer;
}
// entry scripts ****************************************************************************************
if (props.entry) {
config.entries = [].concat(props.entry);
}
// cache ************************************************************************************************
config.cache = {
enabled: false,
FTL: config.target !== 'server' && config.webIndex.enabled,
root: path.join(env.APP_ROOT, 'node_modules/.fusebox'),
};
if (typeof props.cache === 'boolean') {
config.cache.enabled = props.cache;
} else if (typeof props.cache === 'object') {
config.cache.enabled = typeof props.cache.enabled === 'boolean' ? props.cache.enabled : env.isTest ? false : true;
if (props.cache.root !== undefined) {
config.cache.root = ensureAbsolutePath(props.cache.root, env.SCRIPT_PATH);
}
if (props.cache.FTL !== undefined) {
config.cache.FTL = props.cache.FTL;
}
} else if (props.cache === undefined && !env.isTest) {
config.cache.enabled = true;
}
config.stylesheet = {};
if (props.stylesheet) {
config.stylesheet = { ...config.stylesheet, ...props.stylesheet };
}
config.init(props);
return config;
}