@modern-js/core 1.5.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +0 -2
- package/CHANGELOG.md +48 -0
- package/dist/js/modern/config/defaults.js +4 -1
- package/dist/js/modern/config/index.js +11 -7
- package/dist/js/modern/config/mergeConfig.js +1 -1
- package/dist/js/modern/config/schema/index.js +1 -1
- package/dist/js/modern/config/types/index.js +1 -0
- package/dist/js/modern/config/types/less.js +0 -0
- package/dist/js/modern/config/types/sass.js +0 -0
- package/dist/js/modern/config/types/ssg.js +0 -0
- package/dist/js/modern/config/types/test.js +0 -0
- package/dist/js/modern/config/types/unbundle.js +0 -0
- package/dist/js/modern/context.js +8 -1
- package/dist/js/modern/index.js +26 -9
- package/dist/js/modern/initWatcher.js +2 -2
- package/dist/js/modern/loadPlugins.js +41 -41
- package/dist/js/modern/utils/commander.js +15 -15
- package/dist/js/node/config/defaults.js +4 -1
- package/dist/js/node/config/index.js +38 -11
- package/dist/js/node/config/mergeConfig.js +2 -4
- package/dist/js/node/config/schema/index.js +3 -5
- package/dist/js/node/config/types/index.js +5 -0
- package/dist/js/node/config/types/less.js +0 -0
- package/dist/js/node/config/types/sass.js +0 -0
- package/dist/js/node/config/types/ssg.js +0 -0
- package/dist/js/node/config/types/test.js +0 -0
- package/dist/js/node/config/types/unbundle.js +0 -0
- package/dist/js/node/context.js +8 -1
- package/dist/js/node/index.js +31 -10
- package/dist/js/node/initWatcher.js +2 -3
- package/dist/js/node/loadPlugins.js +40 -41
- package/dist/js/node/utils/commander.js +16 -19
- package/dist/types/config/defaults.d.ts +3 -0
- package/dist/types/config/index.d.ts +4 -129
- package/dist/types/config/types/index.d.ts +239 -0
- package/dist/types/config/types/less.d.ts +10 -0
- package/dist/types/config/types/sass.d.ts +8 -0
- package/dist/types/config/types/ssg.d.ts +13 -0
- package/dist/types/config/types/test.d.ts +15 -0
- package/dist/types/config/types/unbundle.d.ts +28 -0
- package/dist/types/context.d.ts +18 -6
- package/dist/types/index.d.ts +19 -0
- package/dist/types/initWatcher.d.ts +1 -2
- package/dist/types/loadPlugins.d.ts +24 -10
- package/dist/types/manager.d.ts +1 -1
- package/dist/types/utils/commander.d.ts +4 -3
- package/jest.config.js +0 -1
- package/package.json +17 -17
- package/tests/config.test.ts +14 -5
- package/tests/context.test.ts +17 -2
- package/tests/fixtures/index-test/modern.server-runtime.config.js +0 -0
- package/tests/index.test.ts +15 -1
- package/tests/initWatcher.test.ts +1 -1
- package/tests/loadPlugin.test.ts +31 -6
- package/tests/utils.test.ts +1 -2
package/dist/js/node/index.js
CHANGED
|
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
|
+
mergeOptions: true,
|
|
7
8
|
cli: true,
|
|
8
9
|
initAppDir: true,
|
|
9
10
|
initAppContext: true,
|
|
@@ -57,6 +58,7 @@ Object.defineProperty(exports, "manager", {
|
|
|
57
58
|
return _manager.manager;
|
|
58
59
|
}
|
|
59
60
|
});
|
|
61
|
+
exports.mergeOptions = void 0;
|
|
60
62
|
Object.defineProperty(exports, "mountHook", {
|
|
61
63
|
enumerable: true,
|
|
62
64
|
get: function () {
|
|
@@ -162,7 +164,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
162
164
|
|
|
163
165
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
164
166
|
|
|
165
|
-
|
|
167
|
+
_utils.program.name('modern').usage('<command> [options]').version(process.env.MODERN_JS_VERSION || '0.1.0');
|
|
166
168
|
|
|
167
169
|
const initAppDir = async cwd => {
|
|
168
170
|
if (!cwd) {
|
|
@@ -183,6 +185,15 @@ const initAppDir = async cwd => {
|
|
|
183
185
|
|
|
184
186
|
exports.initAppDir = initAppDir;
|
|
185
187
|
|
|
188
|
+
const mergeOptions = options => {
|
|
189
|
+
const defaultOptions = {
|
|
190
|
+
serverConfigFile: _utils.DEFAULT_SERVER_CONFIG
|
|
191
|
+
};
|
|
192
|
+
return _objectSpread(_objectSpread({}, defaultOptions), options);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
exports.mergeOptions = mergeOptions;
|
|
196
|
+
|
|
186
197
|
const createCli = () => {
|
|
187
198
|
let hooksRunner;
|
|
188
199
|
let isRestart = false;
|
|
@@ -190,22 +201,32 @@ const createCli = () => {
|
|
|
190
201
|
let restartOptions;
|
|
191
202
|
|
|
192
203
|
const init = async (argv = [], options) => {
|
|
193
|
-
var
|
|
204
|
+
var _mergedOptions$option, _mergedOptions$option2;
|
|
194
205
|
|
|
195
206
|
(0, _node.enable)();
|
|
196
207
|
|
|
197
208
|
_manager.manager.clear();
|
|
198
209
|
|
|
199
|
-
|
|
210
|
+
const mergedOptions = mergeOptions(options);
|
|
211
|
+
restartOptions = mergedOptions;
|
|
200
212
|
const appDirectory = await initAppDir();
|
|
201
|
-
|
|
213
|
+
(0, _commander.initCommandsMap)();
|
|
214
|
+
const metaName = (_mergedOptions$option = mergedOptions === null || mergedOptions === void 0 ? void 0 : (_mergedOptions$option2 = mergedOptions.options) === null || _mergedOptions$option2 === void 0 ? void 0 : _mergedOptions$option2.metaName) !== null && _mergedOptions$option !== void 0 ? _mergedOptions$option : 'MODERN';
|
|
202
215
|
(0, _loadEnv.loadEnv)(appDirectory, process.env[`${metaName.toUpperCase()}_ENV`]);
|
|
203
|
-
const loaded = await (0, _config.loadUserConfig)(appDirectory,
|
|
216
|
+
const loaded = await (0, _config.loadUserConfig)(appDirectory, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.configFile, mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.packageJsonConfig);
|
|
204
217
|
const plugins = (0, _loadPlugins.loadPlugins)(appDirectory, loaded.config, {
|
|
205
|
-
internalPlugins:
|
|
218
|
+
internalPlugins: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.plugins
|
|
206
219
|
});
|
|
207
220
|
plugins.forEach(plugin => plugin.cli && _manager.manager.usePlugin(plugin.cli));
|
|
208
|
-
const appContext = (0, _context.initAppContext)(
|
|
221
|
+
const appContext = (0, _context.initAppContext)({
|
|
222
|
+
appDirectory,
|
|
223
|
+
plugins,
|
|
224
|
+
configFile: loaded.filePath,
|
|
225
|
+
options: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.options,
|
|
226
|
+
serverConfigFile: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.serverConfigFile
|
|
227
|
+
}); // 将 server.config 加入到 loaded.dependencies,以便对文件监听做热更新
|
|
228
|
+
|
|
229
|
+
(0, _config.addServerConfigToDeps)(loaded.dependencies, appDirectory, mergedOptions.serverConfigFile);
|
|
209
230
|
|
|
210
231
|
_manager.manager.run(() => {
|
|
211
232
|
_context.ConfigContext.set(loaded.config);
|
|
@@ -263,11 +284,11 @@ const createCli = () => {
|
|
|
263
284
|
resolved
|
|
264
285
|
} = await init(argv, options);
|
|
265
286
|
await hooksRunner.commands({
|
|
266
|
-
program:
|
|
287
|
+
program: _utils.program
|
|
267
288
|
});
|
|
268
289
|
(0, _initWatcher.initWatcher)(loadedConfig, appContext.appDirectory, resolved.source.configDir, hooksRunner, argv);
|
|
269
290
|
|
|
270
|
-
_manager.manager.run(() =>
|
|
291
|
+
_manager.manager.run(() => _utils.program.parse(process.argv));
|
|
271
292
|
}
|
|
272
293
|
|
|
273
294
|
async function restart() {
|
|
@@ -291,7 +312,7 @@ const createCli = () => {
|
|
|
291
312
|
hasGetError = true;
|
|
292
313
|
} finally {
|
|
293
314
|
if (!hasGetError) {
|
|
294
|
-
_manager.manager.run(() =>
|
|
315
|
+
_manager.manager.run(() => _utils.program.parse(process.argv));
|
|
295
316
|
}
|
|
296
317
|
}
|
|
297
318
|
}
|
|
@@ -13,8 +13,6 @@ var _path = _interopRequireDefault(require("path"));
|
|
|
13
13
|
|
|
14
14
|
var _utils = require("@modern-js/utils");
|
|
15
15
|
|
|
16
|
-
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
17
|
-
|
|
18
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
17
|
|
|
20
18
|
const debug = (0, _utils.createDebugger)('watch-files');
|
|
@@ -33,8 +31,9 @@ const initWatcher = async (loaded, appDirectory, configDir, hooksRunner, argv) =
|
|
|
33
31
|
const watched = [`${configPath}/html`, ...extraFiles, loaded === null || loaded === void 0 ? void 0 : loaded.filePath, ...loaded.dependencies].filter(Boolean);
|
|
34
32
|
debug(`watched: %o`, watched);
|
|
35
33
|
|
|
36
|
-
const watcher =
|
|
34
|
+
const watcher = _utils.chokidar.watch(watched, {
|
|
37
35
|
cwd: appDirectory,
|
|
36
|
+
ignoreInitial: true,
|
|
38
37
|
ignorePermissionErrors: true,
|
|
39
38
|
ignored: [/node_modules/, '**/__test__/**', '**/*.test.(js|jsx|ts|tsx)', '**/*.spec.(js|jsx|ts|tsx)', '**/*.stories.(js|jsx|ts|tsx)']
|
|
40
39
|
});
|
|
@@ -10,12 +10,6 @@ var _utils = require("@modern-js/utils");
|
|
|
10
10
|
|
|
11
11
|
var _manager = require("./manager");
|
|
12
12
|
|
|
13
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
14
|
-
|
|
15
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
16
|
-
|
|
17
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
18
|
-
|
|
19
13
|
const debug = (0, _utils.createDebugger)('load-plugins');
|
|
20
14
|
|
|
21
15
|
/**
|
|
@@ -43,7 +37,7 @@ const tryResolve = (name, appDirectory) => {
|
|
|
43
37
|
return filePath;
|
|
44
38
|
};
|
|
45
39
|
|
|
46
|
-
function getAppPlugins(appDirectory,
|
|
40
|
+
function getAppPlugins(appDirectory, oldPluginConfig, internalPlugins) {
|
|
47
41
|
const allPlugins = internalPlugins || _utils.INTERNAL_PLUGINS;
|
|
48
42
|
const appPlugins = [...Object.keys(allPlugins).filter(name => {
|
|
49
43
|
const config = allPlugins[name];
|
|
@@ -54,9 +48,31 @@ function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
|
|
|
54
48
|
}
|
|
55
49
|
|
|
56
50
|
return (0, _utils.isDepExists)(appDirectory, name);
|
|
57
|
-
}).map(name => allPlugins[name]), ...
|
|
51
|
+
}).map(name => allPlugins[name]), ...oldPluginConfig];
|
|
58
52
|
return appPlugins;
|
|
59
53
|
}
|
|
54
|
+
|
|
55
|
+
const resolveCliPlugin = (p, appDirectory) => {
|
|
56
|
+
const pkg = typeof p === 'string' ? p : p[0];
|
|
57
|
+
const path = tryResolve(pkg, appDirectory);
|
|
58
|
+
const module = (0, _utils.compatRequire)(path);
|
|
59
|
+
|
|
60
|
+
if (typeof module === 'function') {
|
|
61
|
+
const pluginOptions = Array.isArray(p) ? p[1] : undefined;
|
|
62
|
+
const result = module(pluginOptions);
|
|
63
|
+
return (0, _manager.createPlugin)(result.setup, result);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return module;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const isOldPluginConfig = config => Array.isArray(config) && config.some(item => {
|
|
70
|
+
if (typeof item === 'string' || Array.isArray(item)) {
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return 'cli' in item || 'server' in item;
|
|
75
|
+
});
|
|
60
76
|
/**
|
|
61
77
|
* Load internal plugins which in @modern-js scope and user's custom plugins.
|
|
62
78
|
* @param appDirectory - Application root directory.
|
|
@@ -67,30 +83,9 @@ function getAppPlugins(appDirectory, pluginConfig, internalPlugins) {
|
|
|
67
83
|
|
|
68
84
|
|
|
69
85
|
const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const resolvePlugin = p => {
|
|
75
|
-
const pkg = typeof p === 'string' ? p : p[0];
|
|
76
|
-
const path = tryResolve(pkg, appDirectory);
|
|
77
|
-
let module = (0, _utils.compatRequire)(path);
|
|
78
|
-
const pluginOptions = Array.isArray(p) ? p[1] : undefined;
|
|
79
|
-
|
|
80
|
-
if (typeof module === 'function') {
|
|
81
|
-
const plugin = module(pluginOptions);
|
|
82
|
-
module = (0, _manager.createPlugin)(plugin.setup, plugin);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
pkg,
|
|
87
|
-
path,
|
|
88
|
-
module
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const plugins = getAppPlugins(appDirectory, userConfig.plugins || [], internalPlugins);
|
|
93
|
-
return plugins.map(plugin => {
|
|
86
|
+
const pluginConfig = userConfig.plugins;
|
|
87
|
+
const plugins = getAppPlugins(appDirectory, isOldPluginConfig(pluginConfig) ? pluginConfig : [], options.internalPlugins);
|
|
88
|
+
const loadedPlugins = plugins.map(plugin => {
|
|
94
89
|
const _plugin = typeof plugin === 'string' || Array.isArray(plugin) ? {
|
|
95
90
|
cli: plugin
|
|
96
91
|
} : plugin;
|
|
@@ -102,15 +97,7 @@ const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
102
97
|
const loadedPlugin = {};
|
|
103
98
|
|
|
104
99
|
if (cli) {
|
|
105
|
-
|
|
106
|
-
pkg,
|
|
107
|
-
path,
|
|
108
|
-
module
|
|
109
|
-
} = resolvePlugin(cli);
|
|
110
|
-
loadedPlugin.cli = _objectSpread(_objectSpread({}, module), {}, {
|
|
111
|
-
pluginPath: path
|
|
112
|
-
});
|
|
113
|
-
loadedPlugin.cliPkg = pkg;
|
|
100
|
+
loadedPlugin.cli = resolveCliPlugin(cli, appDirectory);
|
|
114
101
|
} // server plugins don't support to accept params
|
|
115
102
|
|
|
116
103
|
|
|
@@ -125,6 +112,18 @@ const loadPlugins = (appDirectory, userConfig, options = {}) => {
|
|
|
125
112
|
});
|
|
126
113
|
return loadedPlugin;
|
|
127
114
|
});
|
|
115
|
+
|
|
116
|
+
if (!isOldPluginConfig(pluginConfig)) {
|
|
117
|
+
const cliPlugins = Array.isArray(pluginConfig) ? pluginConfig : pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.cli;
|
|
118
|
+
|
|
119
|
+
if (cliPlugins !== null && cliPlugins !== void 0 && cliPlugins.length) {
|
|
120
|
+
loadedPlugins.push(...cliPlugins.map(item => ({
|
|
121
|
+
cli: (0, _manager.createPlugin)(item.setup, item)
|
|
122
|
+
})));
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return loadedPlugins;
|
|
128
127
|
};
|
|
129
128
|
|
|
130
129
|
exports.loadPlugins = loadPlugins;
|
|
@@ -3,33 +3,30 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _commander.Command;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
6
|
+
exports.initCommandsMap = initCommandsMap;
|
|
12
7
|
Object.defineProperty(exports, "program", {
|
|
13
8
|
enumerable: true,
|
|
14
9
|
get: function () {
|
|
15
|
-
return
|
|
10
|
+
return _utils.program;
|
|
16
11
|
}
|
|
17
12
|
});
|
|
18
13
|
|
|
19
|
-
var
|
|
14
|
+
var _utils = require("@modern-js/utils");
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
function initCommandsMap() {
|
|
17
|
+
if (!_utils.program.hasOwnProperty('commandsMap')) {
|
|
18
|
+
Object.defineProperty(_utils.program, 'commandsMap', {
|
|
19
|
+
get() {
|
|
20
|
+
const map = new Map();
|
|
25
21
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
for (const command of _utils.program.commands) {
|
|
23
|
+
map.set(command._name, command);
|
|
24
|
+
}
|
|
29
25
|
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
return map;
|
|
27
|
+
},
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
configurable: false
|
|
30
|
+
});
|
|
31
|
+
}
|
|
35
32
|
}
|
|
@@ -1,137 +1,12 @@
|
|
|
1
1
|
import { ErrorObject } from 'ajv';
|
|
2
|
-
import { MetaOptions } from '@modern-js/utils';
|
|
3
|
-
import { PluginConfig } from '../loadPlugins';
|
|
4
2
|
import { defaults } from './defaults';
|
|
5
3
|
import { mergeConfig, NormalizedConfig } from './mergeConfig';
|
|
6
4
|
import { PluginValidateSchema } from './schema';
|
|
5
|
+
import type { UserConfig, ConfigParam, LoadedConfig } from './types';
|
|
7
6
|
export { defaults as defaultsConfig };
|
|
8
7
|
export { mergeConfig };
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
entry: string;
|
|
12
|
-
enableFileSystemRoutes?: boolean;
|
|
13
|
-
disableMount?: boolean;
|
|
14
|
-
}>;
|
|
15
|
-
disableDefaultEntries?: boolean;
|
|
16
|
-
entriesDir?: string;
|
|
17
|
-
configDir?: string;
|
|
18
|
-
apiDir?: string;
|
|
19
|
-
envVars?: Array<string>;
|
|
20
|
-
globalVars?: Record<string, string>;
|
|
21
|
-
alias?: Record<string, string> | ((aliases: Record<string, string>) => Record<string, unknown>);
|
|
22
|
-
moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => void) | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
|
|
23
|
-
include?: Array<string | RegExp>;
|
|
24
|
-
}
|
|
25
|
-
interface OutputConfig {
|
|
26
|
-
assetPrefix?: string;
|
|
27
|
-
htmlPath?: string;
|
|
28
|
-
jsPath?: string;
|
|
29
|
-
cssPath?: string;
|
|
30
|
-
mediaPath?: string;
|
|
31
|
-
path?: string;
|
|
32
|
-
title?: string;
|
|
33
|
-
titleByEntries?: Record<string, string>;
|
|
34
|
-
meta?: MetaOptions;
|
|
35
|
-
metaByEntries?: Record<string, MetaOptions>;
|
|
36
|
-
inject?: 'body' | 'head' | boolean;
|
|
37
|
-
injectByEntries?: Record<string, 'body' | 'head' | boolean>;
|
|
38
|
-
mountId?: string;
|
|
39
|
-
favicon?: string;
|
|
40
|
-
faviconByEntries?: Record<string, string | undefined>;
|
|
41
|
-
copy?: Array<Record<string, unknown> & {
|
|
42
|
-
from: string;
|
|
43
|
-
}>;
|
|
44
|
-
scriptExt?: Record<string, unknown>;
|
|
45
|
-
disableTsChecker?: boolean;
|
|
46
|
-
disableHtmlFolder?: boolean;
|
|
47
|
-
disableCssModuleExtension?: boolean;
|
|
48
|
-
disableCssExtract?: boolean;
|
|
49
|
-
enableCssModuleTSDeclaration?: boolean;
|
|
50
|
-
disableMinimize?: boolean;
|
|
51
|
-
enableInlineStyles?: boolean;
|
|
52
|
-
enableInlineScripts?: boolean;
|
|
53
|
-
disableSourceMap?: boolean;
|
|
54
|
-
disableInlineRuntimeChunk?: boolean;
|
|
55
|
-
disableAssetsCache?: boolean;
|
|
56
|
-
enableLatestDecorators?: boolean;
|
|
57
|
-
polyfill?: 'off' | 'usage' | 'entry' | 'ua';
|
|
58
|
-
dataUriLimit?: number;
|
|
59
|
-
templateParameters?: Record<string, unknown>;
|
|
60
|
-
templateParametersByEntries?: Record<string, Record<string, unknown> | undefined>;
|
|
61
|
-
cssModuleLocalIdentName?: string;
|
|
62
|
-
enableModernMode?: boolean;
|
|
63
|
-
federation?: boolean;
|
|
64
|
-
disableNodePolyfill?: boolean;
|
|
65
|
-
enableTsLoader?: boolean;
|
|
66
|
-
}
|
|
67
|
-
interface ServerConfig {
|
|
68
|
-
routes?: Record<string, string | string[] | {
|
|
69
|
-
route: string | string[];
|
|
70
|
-
disableSpa?: boolean;
|
|
71
|
-
}>;
|
|
72
|
-
publicRoutes?: {
|
|
73
|
-
[filepath: string]: string;
|
|
74
|
-
};
|
|
75
|
-
ssr?: boolean | Record<string, unknown>;
|
|
76
|
-
ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
|
|
77
|
-
baseUrl?: string | Array<string>;
|
|
78
|
-
port?: number;
|
|
79
|
-
logger?: boolean | Record<string, any>;
|
|
80
|
-
metrics?: boolean | Record<string, any>;
|
|
81
|
-
enableMicroFrontendDebug?: boolean;
|
|
82
|
-
}
|
|
83
|
-
interface DevConfig {
|
|
84
|
-
assetPrefix?: string | boolean;
|
|
85
|
-
https?: boolean;
|
|
86
|
-
}
|
|
87
|
-
interface MicroFrontend {
|
|
88
|
-
enableHtmlEntry?: boolean;
|
|
89
|
-
externalBasicLibrary?: boolean;
|
|
90
|
-
moduleApp?: string;
|
|
91
|
-
}
|
|
92
|
-
interface DeployConfig {
|
|
93
|
-
microFrontend?: false | MicroFrontend;
|
|
94
|
-
domain?: string | Array<string>;
|
|
95
|
-
domainByEntries?: Record<string, string | Array<string>>;
|
|
96
|
-
}
|
|
97
|
-
declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>) => Record<string, unknown> | void);
|
|
98
|
-
interface ToolsConfig {
|
|
99
|
-
webpack?: ConfigFunction;
|
|
100
|
-
babel?: ConfigFunction;
|
|
101
|
-
autoprefixer?: ConfigFunction;
|
|
102
|
-
postcss?: ConfigFunction;
|
|
103
|
-
styledComponents?: ConfigFunction;
|
|
104
|
-
lodash?: ConfigFunction;
|
|
105
|
-
devServer?: Record<string, unknown>;
|
|
106
|
-
tsLoader?: ConfigFunction;
|
|
107
|
-
terser?: ConfigFunction;
|
|
108
|
-
minifyCss?: ConfigFunction;
|
|
109
|
-
esbuild?: Record<string, unknown>;
|
|
110
|
-
}
|
|
111
|
-
declare type RuntimeConfig = Record<string, any>;
|
|
112
|
-
interface RuntimeByEntriesConfig {
|
|
113
|
-
[name: string]: RuntimeConfig;
|
|
114
|
-
}
|
|
115
|
-
interface UserConfig {
|
|
116
|
-
source?: SourceConfig;
|
|
117
|
-
output?: OutputConfig;
|
|
118
|
-
server?: ServerConfig;
|
|
119
|
-
dev?: DevConfig;
|
|
120
|
-
deploy?: DeployConfig;
|
|
121
|
-
tools?: ToolsConfig;
|
|
122
|
-
plugins?: PluginConfig;
|
|
123
|
-
runtime?: RuntimeConfig;
|
|
124
|
-
runtimeByEntries?: RuntimeByEntriesConfig;
|
|
125
|
-
}
|
|
126
|
-
declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
|
|
127
|
-
interface LoadedConfig {
|
|
128
|
-
config: UserConfig;
|
|
129
|
-
filePath: string | false;
|
|
130
|
-
dependencies: string[];
|
|
131
|
-
pkgConfig: UserConfig;
|
|
132
|
-
jsConfig: UserConfig;
|
|
133
|
-
}
|
|
8
|
+
export * from './types';
|
|
9
|
+
export declare const addServerConfigToDeps: (dependencies: string[], appDirectory: string, serverConfigFile: string) => Promise<void>;
|
|
134
10
|
export declare const defineConfig: (config: ConfigParam) => ConfigParam;
|
|
135
11
|
export declare const loadUserConfig: (appDirectory: string, filePath?: string | undefined, packageJsonConfig?: string | undefined) => Promise<LoadedConfig>;
|
|
136
|
-
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void) => Promise<NormalizedConfig>;
|
|
137
|
-
export type { SourceConfig, OutputConfig, ServerConfig, DevConfig, DeployConfig, ToolsConfig, RuntimeConfig, RuntimeByEntriesConfig, UserConfig, ConfigParam, LoadedConfig };
|
|
12
|
+
export declare const resolveConfig: (loaded: LoadedConfig, configs: UserConfig[], schemas: PluginValidateSchema[], restartWithExistingPort: number, argv: string[], onSchemaError?: (error: ErrorObject) => void) => Promise<NormalizedConfig>;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { IncomingMessage, ServerResponse } from 'http';
|
|
3
|
+
import type { NextFunction, BffProxyOptions } from '@modern-js/types';
|
|
4
|
+
import type { MetaOptions } from '@modern-js/utils';
|
|
5
|
+
import type { TransformOptions } from '@babel/core';
|
|
6
|
+
import type { Configuration as WebpackConfiguration } from 'webpack';
|
|
7
|
+
import autoprefixer from 'autoprefixer';
|
|
8
|
+
import type { BasePluginOptions, TerserOptions as RawTerserOptions } from 'terser-webpack-plugin';
|
|
9
|
+
import type { PluginConfig } from '../../loadPlugins';
|
|
10
|
+
import type { TestConfig, JestConfig } from './test';
|
|
11
|
+
import type { SassConfig, SassLoaderOptions } from './sass';
|
|
12
|
+
import type { LessConfig, LessLoaderOptions } from './less';
|
|
13
|
+
import type { UnbundleConfig } from './unbundle';
|
|
14
|
+
import type { SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions } from './ssg';
|
|
15
|
+
declare type AutoprefixerOptions = autoprefixer.Options;
|
|
16
|
+
declare type TerserOptions = BasePluginOptions & RawTerserOptions;
|
|
17
|
+
export type { TestConfig, JestConfig, UnbundleConfig, SassConfig, SassLoaderOptions, LessConfig, LessLoaderOptions, SSGConfig, SSGRouteOptions, SSGMultiEntryOptions, SSGSingleEntryOptions, TransformOptions, AutoprefixerOptions, TerserOptions };
|
|
18
|
+
export interface SourceConfig {
|
|
19
|
+
entries?: Record<string, string | {
|
|
20
|
+
entry: string;
|
|
21
|
+
enableFileSystemRoutes?: boolean;
|
|
22
|
+
disableMount?: boolean;
|
|
23
|
+
}>;
|
|
24
|
+
disableDefaultEntries?: boolean;
|
|
25
|
+
entriesDir?: string;
|
|
26
|
+
configDir?: string;
|
|
27
|
+
apiDir?: string;
|
|
28
|
+
envVars?: Array<string>;
|
|
29
|
+
globalVars?: Record<string, string>;
|
|
30
|
+
alias?: Record<string, string> | ((aliases: Record<string, string>) => Record<string, unknown>);
|
|
31
|
+
moduleScopes?: Array<string | RegExp> | ((scopes: Array<string | RegExp>) => void) | ((scopes: Array<string | RegExp>) => Array<string | RegExp>);
|
|
32
|
+
include?: Array<string | RegExp>;
|
|
33
|
+
/**
|
|
34
|
+
* The configuration of `source.designSystem` is provided by plugin `@modern-js/plugin-tailwindcss`.
|
|
35
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
36
|
+
* @requires `@modern-js/plugin-tailwindcss`
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
designSystem?: Record<string, any>;
|
|
40
|
+
}
|
|
41
|
+
export interface OutputConfig {
|
|
42
|
+
assetPrefix?: string;
|
|
43
|
+
htmlPath?: string;
|
|
44
|
+
jsPath?: string;
|
|
45
|
+
cssPath?: string;
|
|
46
|
+
mediaPath?: string;
|
|
47
|
+
path?: string;
|
|
48
|
+
title?: string;
|
|
49
|
+
titleByEntries?: Record<string, string>;
|
|
50
|
+
meta?: MetaOptions;
|
|
51
|
+
metaByEntries?: Record<string, MetaOptions>;
|
|
52
|
+
inject?: 'body' | 'head' | boolean;
|
|
53
|
+
injectByEntries?: Record<string, 'body' | 'head' | boolean>;
|
|
54
|
+
mountId?: string;
|
|
55
|
+
favicon?: string;
|
|
56
|
+
faviconByEntries?: Record<string, string | undefined>;
|
|
57
|
+
copy?: Array<Record<string, unknown> & {
|
|
58
|
+
from: string;
|
|
59
|
+
}>;
|
|
60
|
+
scriptExt?: Record<string, unknown>;
|
|
61
|
+
disableTsChecker?: boolean;
|
|
62
|
+
disableHtmlFolder?: boolean;
|
|
63
|
+
disableCssModuleExtension?: boolean;
|
|
64
|
+
disableCssExtract?: boolean;
|
|
65
|
+
enableCssModuleTSDeclaration?: boolean;
|
|
66
|
+
disableMinimize?: boolean;
|
|
67
|
+
enableInlineStyles?: boolean;
|
|
68
|
+
enableInlineScripts?: boolean;
|
|
69
|
+
disableSourceMap?: boolean;
|
|
70
|
+
disableInlineRuntimeChunk?: boolean;
|
|
71
|
+
disableAssetsCache?: boolean;
|
|
72
|
+
enableLatestDecorators?: boolean;
|
|
73
|
+
polyfill?: 'off' | 'usage' | 'entry' | 'ua';
|
|
74
|
+
dataUriLimit?: number;
|
|
75
|
+
templateParameters?: Record<string, unknown>;
|
|
76
|
+
templateParametersByEntries?: Record<string, Record<string, unknown> | undefined>;
|
|
77
|
+
cssModuleLocalIdentName?: string;
|
|
78
|
+
enableModernMode?: boolean;
|
|
79
|
+
federation?: boolean;
|
|
80
|
+
disableNodePolyfill?: boolean;
|
|
81
|
+
enableTsLoader?: boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Disables lazy import support for styles, currently supports antd and arco-design.
|
|
84
|
+
* The configuration of `output.disableAutoImportStyle` is provided by plugin `@modern-js/plugin-unbundle`.
|
|
85
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
86
|
+
* @requires `@modern-js/plugin-unbundle`
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
disableAutoImportStyle?: boolean;
|
|
90
|
+
/**
|
|
91
|
+
* The configuration of `output.ssg` is provided by plugin `@modern-js/plugin-ssg`.
|
|
92
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
93
|
+
* @requires `@modern-js/plugin-ssg`
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
ssg?: SSGConfig;
|
|
97
|
+
}
|
|
98
|
+
export interface ServerConfig {
|
|
99
|
+
routes?: Record<string, string | string[] | {
|
|
100
|
+
route: string | string[];
|
|
101
|
+
disableSpa?: boolean;
|
|
102
|
+
}>;
|
|
103
|
+
publicRoutes?: {
|
|
104
|
+
[filepath: string]: string;
|
|
105
|
+
};
|
|
106
|
+
ssr?: boolean | Record<string, unknown>;
|
|
107
|
+
ssrByEntries?: Record<string, boolean | Record<string, unknown>>;
|
|
108
|
+
baseUrl?: string | Array<string>;
|
|
109
|
+
port?: number;
|
|
110
|
+
logger?: boolean | Record<string, any>;
|
|
111
|
+
metrics?: boolean | Record<string, any>;
|
|
112
|
+
enableMicroFrontendDebug?: boolean;
|
|
113
|
+
}
|
|
114
|
+
export declare type DevProxyOptions = string | Record<string, string>;
|
|
115
|
+
export interface DevConfig {
|
|
116
|
+
assetPrefix?: string | boolean;
|
|
117
|
+
https?: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* The configuration of `dev.proxy` is provided by plugin `@modern-js/plugin-proxy`.
|
|
120
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
121
|
+
* @requires `@modern-js/plugin-proxy`
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
proxy?: DevProxyOptions;
|
|
125
|
+
/**
|
|
126
|
+
* The configuration of `dev.unbundle` is provided by plugin `@modern-js/plugin-unbundle`.
|
|
127
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
128
|
+
* @requires `@modern-js/plugin-unbundle`
|
|
129
|
+
*/
|
|
130
|
+
|
|
131
|
+
unbundle?: UnbundleConfig;
|
|
132
|
+
}
|
|
133
|
+
export interface MicroFrontend {
|
|
134
|
+
enableHtmlEntry?: boolean;
|
|
135
|
+
externalBasicLibrary?: boolean;
|
|
136
|
+
moduleApp?: string;
|
|
137
|
+
}
|
|
138
|
+
export interface DeployConfig {
|
|
139
|
+
microFrontend?: false | MicroFrontend;
|
|
140
|
+
domain?: string | Array<string>;
|
|
141
|
+
domainByEntries?: Record<string, string | Array<string>>;
|
|
142
|
+
}
|
|
143
|
+
declare type ConfigFunction = Record<string, unknown> | ((config: Record<string, unknown>, utils?: any) => Record<string, unknown> | void);
|
|
144
|
+
export declare type RequestHandler = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void;
|
|
145
|
+
export declare type DevServerConfig = {
|
|
146
|
+
proxy?: BffProxyOptions;
|
|
147
|
+
headers?: Record<string, string>;
|
|
148
|
+
before?: RequestHandler[];
|
|
149
|
+
after?: RequestHandler[];
|
|
150
|
+
[propsName: string]: any;
|
|
151
|
+
};
|
|
152
|
+
export declare type WebpackConfig = WebpackConfiguration | ((config: WebpackConfiguration, utils?: any) => WebpackConfiguration | void);
|
|
153
|
+
export declare type BabelConfig = TransformOptions | ((config: TransformOptions, utils?: any) => TransformOptions | void);
|
|
154
|
+
export declare type AutoprefixerConfig = AutoprefixerOptions | ((config: AutoprefixerOptions) => AutoprefixerOptions | void);
|
|
155
|
+
export declare type TerserConfig = TerserOptions | ((config: TerserOptions) => TerserOptions | void);
|
|
156
|
+
export interface ToolsConfig {
|
|
157
|
+
webpack?: WebpackConfig;
|
|
158
|
+
babel?: BabelConfig;
|
|
159
|
+
autoprefixer?: AutoprefixerConfig;
|
|
160
|
+
postcss?: ConfigFunction;
|
|
161
|
+
styledComponents?: ConfigFunction;
|
|
162
|
+
lodash?: ConfigFunction;
|
|
163
|
+
devServer?: DevServerConfig;
|
|
164
|
+
tsLoader?: ConfigFunction;
|
|
165
|
+
terser?: TerserConfig;
|
|
166
|
+
minifyCss?: ConfigFunction;
|
|
167
|
+
esbuild?: Record<string, unknown>;
|
|
168
|
+
/**
|
|
169
|
+
* The configuration of `tools.tailwindcss` is provided by plugin `@modern-js/plugin-tailwindcss`.
|
|
170
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
171
|
+
* @requires `@modern-js/plugin-tailwindcss`
|
|
172
|
+
*/
|
|
173
|
+
|
|
174
|
+
tailwindcss?: Record<string, any> | ((options: Record<string, any>) => Record<string, any> | void);
|
|
175
|
+
/**
|
|
176
|
+
* The configuration of `tools.jest` is provided by plugin `@modern-js/plugin-testing`.
|
|
177
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
178
|
+
* @requires `@modern-js/plugin-testing`
|
|
179
|
+
*/
|
|
180
|
+
|
|
181
|
+
jest?: TestConfig['jest'];
|
|
182
|
+
/**
|
|
183
|
+
* The configuration of `tools.sass` is provided by plugin `@modern-js/plugin-sass`.
|
|
184
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
185
|
+
* @requires `@modern-js/plugin-sass`
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
sass?: SassConfig;
|
|
189
|
+
/**
|
|
190
|
+
* The configuration of `tools.less` is provided by plugin `@modern-js/plugin-less`.
|
|
191
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
192
|
+
* @requires `@modern-js/plugin-less`
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
less?: LessConfig;
|
|
196
|
+
}
|
|
197
|
+
export declare type RuntimeConfig = Record<string, any>;
|
|
198
|
+
export interface RuntimeByEntriesConfig {
|
|
199
|
+
[name: string]: RuntimeConfig;
|
|
200
|
+
}
|
|
201
|
+
export declare type BffConfig = Partial<{
|
|
202
|
+
prefix: string;
|
|
203
|
+
requestCreator: string;
|
|
204
|
+
fetcher: string;
|
|
205
|
+
proxy: Record<string, any>;
|
|
206
|
+
}>;
|
|
207
|
+
export interface UserConfig {
|
|
208
|
+
source?: SourceConfig;
|
|
209
|
+
output?: OutputConfig;
|
|
210
|
+
server?: ServerConfig;
|
|
211
|
+
dev?: DevConfig;
|
|
212
|
+
deploy?: DeployConfig;
|
|
213
|
+
tools?: ToolsConfig;
|
|
214
|
+
plugins?: PluginConfig;
|
|
215
|
+
runtime?: RuntimeConfig;
|
|
216
|
+
runtimeByEntries?: RuntimeByEntriesConfig;
|
|
217
|
+
/**
|
|
218
|
+
* The configuration of `bff` is provided by plugin `@modern-js/plugin-bff`.
|
|
219
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
220
|
+
* @requires `@modern-js/plugin-bff`
|
|
221
|
+
*/
|
|
222
|
+
|
|
223
|
+
bff?: BffConfig;
|
|
224
|
+
/**
|
|
225
|
+
* The configuration of `testing` is provided by plugin `@modern-js/plugin-testing`.
|
|
226
|
+
* Please use `yarn new` to enable the corresponding capability.
|
|
227
|
+
* @requires `@modern-js/plugin-testing`
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
testing?: TestConfig;
|
|
231
|
+
}
|
|
232
|
+
export declare type ConfigParam = UserConfig | Promise<UserConfig> | ((env: any) => UserConfig | Promise<UserConfig>);
|
|
233
|
+
export interface LoadedConfig {
|
|
234
|
+
config: UserConfig;
|
|
235
|
+
filePath: string | false;
|
|
236
|
+
dependencies: string[];
|
|
237
|
+
pkgConfig: UserConfig;
|
|
238
|
+
jsConfig: UserConfig;
|
|
239
|
+
}
|