@modern-js/app-tools 2.4.0 → 3.0.0-beta.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +31 -0
- package/dist/js/modern/analyze/getServerRoutes.js +5 -2
- package/dist/js/modern/analyze/index.js +6 -2
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/RouterPlugin.js +3 -0
- package/dist/js/modern/builder/generator/getBuilderTargets.js +10 -1
- package/dist/js/modern/builder/shared/builderPlugins/adapterModern.js +23 -7
- package/dist/js/node/analyze/getServerRoutes.js +3 -1
- package/dist/js/node/analyze/index.js +6 -2
- package/dist/js/node/builder/builder-webpack/webpackPlugins/RouterPlugin.js +3 -0
- package/dist/js/node/builder/generator/getBuilderTargets.js +4 -0
- package/dist/js/node/builder/shared/builderPlugins/adapterModern.js +23 -7
- package/dist/js/treeshaking/analyze/generateCode.js +14 -14
- package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
- package/dist/js/treeshaking/analyze/index.js +8 -8
- package/dist/js/treeshaking/analyze/nestedRoutes.js +5 -5
- package/dist/js/treeshaking/analyze/templates.js +6 -6
- package/dist/js/treeshaking/analyze/utils.js +3 -3
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +4 -4
- package/dist/js/treeshaking/builder/builder-webpack/index.js +2 -2
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/RouterPlugin.js +5 -2
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +2 -2
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +5 -1
- package/dist/js/treeshaking/builder/generator/index.js +2 -2
- package/dist/js/treeshaking/builder/shared/builderPlugins/adapterModern.js +62 -13
- package/dist/js/treeshaking/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +2 -2
- package/dist/js/treeshaking/commands/dev.js +2 -2
- package/dist/js/treeshaking/commands/serve.js +2 -2
- package/dist/js/treeshaking/config/initialize/inits.js +2 -2
- package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +1 -1
- package/dist/js/treeshaking/config/legacy/createOutputConfig.js +1 -1
- package/dist/js/treeshaking/config/legacy/createSourceConfig.js +1 -1
- package/dist/js/treeshaking/config/legacy/createToolsConfig.js +1 -1
- package/dist/js/treeshaking/initialize/index.js +2 -2
- package/dist/js/treeshaking/utils/config.js +2 -2
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
- package/dist/types/types/hooks.d.ts +5 -4
- package/dist/types/types/index.d.ts +3 -1
- package/package.json +20 -20
@@ -197,7 +197,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
|
|
197
197
|
};
|
198
198
|
var walk = function() {
|
199
199
|
var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
|
200
|
-
var
|
200
|
+
var _route_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, _route_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, path2;
|
201
201
|
return __generator(this, function(_state) {
|
202
202
|
switch(_state.label){
|
203
203
|
case 0:
|
@@ -288,7 +288,7 @@ var walk = function() {
|
|
288
288
|
childRoute = _state.sent();
|
289
289
|
if (childRoute) {
|
290
290
|
;
|
291
|
-
(
|
291
|
+
(_route_children1 = route.children) === null || _route_children1 === void 0 ? void 0 : _route_children1.push(childRoute);
|
292
292
|
}
|
293
293
|
_state.label = 8;
|
294
294
|
case 8:
|
@@ -317,7 +317,7 @@ var walk = function() {
|
|
317
317
|
if (pageLoaderFile) {
|
318
318
|
pageRoute.loader = pageLoaderFile;
|
319
319
|
}
|
320
|
-
(
|
320
|
+
(_route_children2 = route.children) === null || _route_children2 === void 0 ? void 0 : _route_children2.push(pageRoute);
|
321
321
|
}
|
322
322
|
if (itemWithoutExt === NESTED_ROUTE.SPLATE_LOADER_FILE) {
|
323
323
|
splatLoaderFile = itemPath;
|
@@ -331,7 +331,7 @@ var walk = function() {
|
|
331
331
|
if (splatLoaderFile) {
|
332
332
|
splatRoute.loader = splatLoaderFile;
|
333
333
|
}
|
334
|
-
(
|
334
|
+
(_route_children3 = route.children) === null || _route_children3 === void 0 ? void 0 : _route_children3.push(splatRoute);
|
335
335
|
}
|
336
336
|
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
337
337
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
@@ -377,7 +377,7 @@ var walk = function() {
|
|
377
377
|
if (isPathlessLayout) {
|
378
378
|
delete finalRoute.path;
|
379
379
|
}
|
380
|
-
route.children = (
|
380
|
+
route.children = (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.filter(function(childRoute) {
|
381
381
|
return childRoute;
|
382
382
|
});
|
383
383
|
if (route.children && route.children.length === 0 && !route.index) {
|
@@ -243,8 +243,8 @@ var routesForServer = function(param) {
|
|
243
243
|
var traverseRouteTree = function(route) {
|
244
244
|
var children;
|
245
245
|
if ("children" in route && route.children) {
|
246
|
-
var
|
247
|
-
children = route === null || route === void 0 ? void 0 : (
|
246
|
+
var _route_children;
|
247
|
+
children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
248
248
|
}
|
249
249
|
var loader;
|
250
250
|
if (route.type === "nested") {
|
@@ -296,7 +296,7 @@ var routesForServer = function(param) {
|
|
296
296
|
};
|
297
297
|
var fileSystemRoutes = function() {
|
298
298
|
var _ref = _asyncToGenerator(function(param) {
|
299
|
-
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1,
|
299
|
+
var routes, ssrMode, nestedRoutesEntry, entryName, internalDirectory, loadings, errors, loaders, loadersMap, loadersMapFile, importLazyCode, rootLayoutCode, getDataLoaderPath, traverseRouteTree, routeComponentsCode, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, route, newRoute, component, finalRoute, importLoadingCode, importErrorComponentsCode, importLoadersCode, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, _step_value, key, loaderInfo;
|
300
300
|
return __generator(this, function(_state) {
|
301
301
|
switch(_state.label){
|
302
302
|
case 0:
|
@@ -321,8 +321,8 @@ var fileSystemRoutes = function() {
|
|
321
321
|
traverseRouteTree = function(route) {
|
322
322
|
var children;
|
323
323
|
if ("children" in route && route.children) {
|
324
|
-
var
|
325
|
-
children = route === null || route === void 0 ? void 0 : (
|
324
|
+
var _route_children;
|
325
|
+
children = route === null || route === void 0 ? void 0 : (_route_children = route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
326
326
|
}
|
327
327
|
var loading;
|
328
328
|
var error;
|
@@ -417,7 +417,7 @@ var fileSystemRoutes = function() {
|
|
417
417
|
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
418
418
|
try {
|
419
419
|
for(_iterator1 = Object.entries(loadersMap)[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
420
|
-
|
420
|
+
_step_value = _slicedToArray(_step1.value, 2), key = _step_value[0], loaderInfo = _step_value[1];
|
421
421
|
if (loaderInfo.inline) {
|
422
422
|
importLoadersCode += "import { loader as ".concat(key, ' } from "').concat(getDataLoaderPath(key)).concat(slash(loaderInfo.filePath), '";\n');
|
423
423
|
} else {
|
@@ -333,7 +333,7 @@ var parseModule = function() {
|
|
333
333
|
}();
|
334
334
|
var hasLoader = function() {
|
335
335
|
var _ref = _asyncToGenerator(function(filename) {
|
336
|
-
var source,
|
336
|
+
var source, _ref, moduleExports;
|
337
337
|
return __generator(this, function(_state) {
|
338
338
|
switch(_state.label){
|
339
339
|
case 0:
|
@@ -351,10 +351,10 @@ var hasLoader = function() {
|
|
351
351
|
})
|
352
352
|
];
|
353
353
|
case 2:
|
354
|
-
|
354
|
+
_ref = _slicedToArray.apply(void 0, [
|
355
355
|
_state.sent(),
|
356
356
|
2
|
357
|
-
]), moduleExports =
|
357
|
+
]), moduleExports = _ref[1];
|
358
358
|
return [
|
359
359
|
2,
|
360
360
|
moduleExports.some(function(e) {
|
@@ -33,15 +33,15 @@ var PluginCompatModern = function(options) {
|
|
33
33
|
var modernConfig = options.normalizedConfig, appContext = options.appContext;
|
34
34
|
api.modifyWebpackChain(function(chain, param) {
|
35
35
|
var CHAIN_ID = param.CHAIN_ID;
|
36
|
-
var
|
36
|
+
var _modernConfig_runtime;
|
37
37
|
chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
|
38
38
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
39
39
|
var defaultCopyPattern = createCopyPattern(appContext, modernConfig, "public", chain);
|
40
40
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(function(args) {
|
41
|
-
var
|
41
|
+
var _args_;
|
42
42
|
return [
|
43
43
|
{
|
44
|
-
patterns: _toConsumableArray(((
|
44
|
+
patterns: _toConsumableArray(((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || []).concat([
|
45
45
|
defaultCopyPattern
|
46
46
|
])
|
47
47
|
}
|
@@ -52,7 +52,7 @@ var PluginCompatModern = function(options) {
|
|
52
52
|
var existNestedRoutes = entrypoints.some(function(entrypoint) {
|
53
53
|
return entrypoint.nestedRoutesEntry;
|
54
54
|
});
|
55
|
-
var routerConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (
|
55
|
+
var routerConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_runtime = modernConfig.runtime) === null || _modernConfig_runtime === void 0 ? void 0 : _modernConfig_runtime.router;
|
56
56
|
var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
57
57
|
if (existNestedRoutes || routerManifest) {
|
58
58
|
chain.plugin("route-plugin").use(RouterPlugin);
|
@@ -248,7 +248,7 @@ function applyBuilderPlugins(builder, options) {
|
|
248
248
|
}
|
249
249
|
function _applyBuilderPlugins() {
|
250
250
|
_applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
|
251
|
-
var normalizedConfig, PluginNodePolyfill,
|
251
|
+
var normalizedConfig, PluginNodePolyfill, _normalizedConfig_tools, esbuildOptions, PluginEsbuild;
|
252
252
|
return __generator(this, function(_state) {
|
253
253
|
switch(_state.label){
|
254
254
|
case 0:
|
@@ -272,7 +272,7 @@ function _applyBuilderPlugins() {
|
|
272
272
|
3,
|
273
273
|
4
|
274
274
|
];
|
275
|
-
|
275
|
+
_normalizedConfig_tools = normalizedConfig.tools, esbuildOptions = _normalizedConfig_tools.esbuild;
|
276
276
|
return [
|
277
277
|
4,
|
278
278
|
import("@modern-js/builder-plugin-esbuild")
|
@@ -215,6 +215,9 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
215
215
|
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
216
216
|
return;
|
217
217
|
}
|
218
|
+
if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
|
219
|
+
return;
|
220
|
+
}
|
218
221
|
var webpack = compiler.webpack;
|
219
222
|
var Compilation = webpack.Compilation, sources = webpack.sources;
|
220
223
|
var RawSource = sources.RawSource;
|
@@ -232,7 +235,7 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
232
235
|
name: PLUGIN_NAME,
|
233
236
|
stage: PROCESS_ASSETS_STAGE_REPORT
|
234
237
|
}, /*#__PURE__*/ _asyncToGenerator(function() {
|
235
|
-
var stats, publicPath, routeAssets, namedChunkGroups, assetsByChunkName, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step,
|
238
|
+
var stats, publicPath, routeAssets, namedChunkGroups, assetsByChunkName, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, manifest, injectedContent, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, file, asset, newContent, filename;
|
236
239
|
return __generator(this, function(_state) {
|
237
240
|
switch(_state.label){
|
238
241
|
case 0:
|
@@ -252,7 +255,7 @@ var RouterPlugin = /*#__PURE__*/ function() {
|
|
252
255
|
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
253
256
|
try {
|
254
257
|
for(_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
255
|
-
|
258
|
+
_step_value = _slicedToArray(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
|
256
259
|
if (assetsByChunkName[name]) {
|
257
260
|
routeAssets[name] = {
|
258
261
|
chunkIds: chunkGroup.chunks,
|
@@ -1,10 +1,10 @@
|
|
1
1
|
function createBuilderOptions(target, appContext) {
|
2
2
|
var entries = {};
|
3
|
-
var
|
3
|
+
var _appContext_entrypoints = appContext.entrypoints, entrypoints = _appContext_entrypoints === void 0 ? [] : _appContext_entrypoints, checkedEntries = appContext.checkedEntries;
|
4
4
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
5
5
|
try {
|
6
6
|
for(var _iterator = entrypoints[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
7
|
-
var
|
7
|
+
var _step_value = _step.value, entryName = _step_value.entryName, entry = _step_value.entry;
|
8
8
|
if (checkedEntries && !checkedEntries.includes(entryName)) {
|
9
9
|
continue;
|
10
10
|
}
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { isProd, isSSR, isUseSSRBundle } from "@modern-js/utils";
|
1
|
+
import { isProd, isServiceWorker, isSSR, isUseSSRBundle } from "@modern-js/utils";
|
2
2
|
function getBuilderTargets(normalizedConfig) {
|
3
3
|
var targets = [
|
4
4
|
"web"
|
@@ -7,6 +7,10 @@ function getBuilderTargets(normalizedConfig) {
|
|
7
7
|
if (useNodeTarget) {
|
8
8
|
targets.push("node");
|
9
9
|
}
|
10
|
+
var useWorkerTarget = isProd() ? isServiceWorker(normalizedConfig) : false;
|
11
|
+
if (useWorkerTarget) {
|
12
|
+
targets.push("service-worker");
|
13
|
+
}
|
10
14
|
return targets;
|
11
15
|
}
|
12
16
|
export { getBuilderTargets };
|
@@ -131,12 +131,12 @@ function generateBuilder(options, generateProvider, utils) {
|
|
131
131
|
}
|
132
132
|
function _generateBuilder() {
|
133
133
|
_generateBuilder = _asyncToGenerator(function(options, generateProvider, utils) {
|
134
|
-
var normalizedConfig, appContext,
|
134
|
+
var normalizedConfig, appContext, _ref, modifyBuilderConfig, modifyBuilderInstance, builderConfig, provider, target, builderOptions, builder;
|
135
135
|
return __generator(this, function(_state) {
|
136
136
|
switch(_state.label){
|
137
137
|
case 0:
|
138
138
|
normalizedConfig = options.normalizedConfig, appContext = options.appContext;
|
139
|
-
|
139
|
+
_ref = utils || {}, modifyBuilderConfig = _ref.modifyBuilderConfig, modifyBuilderInstance = _ref.modifyBuilderInstance;
|
140
140
|
builderConfig = createBuilderProviderConfig(normalizedConfig, appContext, modifyBuilderConfig);
|
141
141
|
provider = generateProvider({
|
142
142
|
builderConfig: builderConfig
|
@@ -95,8 +95,8 @@ var builderPluginAdapterModern = function(options) {
|
|
95
95
|
name: "builder-plugin-adapter-modern",
|
96
96
|
setup: function setup(api) {
|
97
97
|
var isHtmlEnabled = function isHtmlEnabled(config, target) {
|
98
|
-
var
|
99
|
-
return ((
|
98
|
+
var _config_tools;
|
99
|
+
return ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
|
100
100
|
};
|
101
101
|
var normalizedConfig = options.normalizedConfig, appContext = options.appContext;
|
102
102
|
api.modifyBuilderConfig(function(config) {
|
@@ -114,13 +114,17 @@ var builderPluginAdapterModern = function(options) {
|
|
114
114
|
var builderConfig = api.getNormalizedConfig();
|
115
115
|
if (target === "node") {
|
116
116
|
chain.name("server");
|
117
|
+
} else if (target === "service-worker") {
|
118
|
+
chain.name("service-worker");
|
119
|
+
} else if (target === "web-worker") {
|
120
|
+
chain.name("worker");
|
117
121
|
} else if (target === "modern-web") {
|
118
122
|
chain.name("modern");
|
119
123
|
} else {
|
120
124
|
chain.name("client");
|
121
125
|
}
|
122
|
-
if (target === "node") {
|
123
|
-
applyNodeCompat(chain, normalizedConfig, isProd);
|
126
|
+
if (target === "node" || target === "service-worker") {
|
127
|
+
applyNodeCompat(target, chain, normalizedConfig, isProd);
|
124
128
|
}
|
125
129
|
if (isHtmlEnabled(builderConfig, target)) {
|
126
130
|
applyBottomHtmlPlugin({
|
@@ -136,7 +140,7 @@ var builderPluginAdapterModern = function(options) {
|
|
136
140
|
CHAIN_ID: CHAIN_ID
|
137
141
|
});
|
138
142
|
}
|
139
|
-
if (target !== "node") {
|
143
|
+
if (target !== "node" && target !== "web-worker" && target !== "service-worker") {
|
140
144
|
var bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
141
145
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
142
146
|
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
@@ -203,11 +207,11 @@ function applyAsyncChunkHtmlPlugin(param) {
|
|
203
207
|
]);
|
204
208
|
}
|
205
209
|
}
|
206
|
-
function applyNodeCompat(chain, modernConfig, isProd) {
|
210
|
+
function applyNodeCompat(target, chain, modernConfig, isProd) {
|
207
211
|
var filterEntriesBySSRConfig = function filterEntriesBySSRConfig(isProd2, chain2, serverConfig, outputConfig) {
|
208
|
-
var
|
212
|
+
var _outputConfig_ssg;
|
209
213
|
var entries = chain2.entryPoints.entries();
|
210
|
-
if (isProd2 && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof (outputConfig === null || outputConfig === void 0 ? void 0 : (
|
214
|
+
if (isProd2 && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof (outputConfig === null || outputConfig === void 0 ? void 0 : (_outputConfig_ssg = outputConfig.ssg) === null || _outputConfig_ssg === void 0 ? void 0 : _outputConfig_ssg[0]) === "function")) {
|
211
215
|
return;
|
212
216
|
}
|
213
217
|
if (typeof entries === "undefined") {
|
@@ -226,14 +230,14 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
226
230
|
}
|
227
231
|
});
|
228
232
|
}
|
229
|
-
var
|
233
|
+
var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
|
230
234
|
entryNames.forEach(function(name) {
|
231
235
|
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
|
232
236
|
chain2.entryPoints.delete(name);
|
233
237
|
}
|
234
238
|
});
|
235
239
|
};
|
236
|
-
|
240
|
+
var nodeExts = [
|
237
241
|
".node.js",
|
238
242
|
".node.jsx",
|
239
243
|
".node.ts",
|
@@ -242,9 +246,54 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
242
246
|
".server.ts",
|
243
247
|
".server.ts",
|
244
248
|
".server.tsx"
|
245
|
-
];
|
246
|
-
|
247
|
-
|
249
|
+
];
|
250
|
+
var webWorkerExts = [
|
251
|
+
".worker.js",
|
252
|
+
".worker.jsx",
|
253
|
+
".worker.ts",
|
254
|
+
".worker.tsx"
|
255
|
+
];
|
256
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
257
|
+
try {
|
258
|
+
for(var _iterator = nodeExts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
259
|
+
var ext = _step.value;
|
260
|
+
chain.resolve.extensions.prepend(ext);
|
261
|
+
}
|
262
|
+
} catch (err) {
|
263
|
+
_didIteratorError = true;
|
264
|
+
_iteratorError = err;
|
265
|
+
} finally{
|
266
|
+
try {
|
267
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
268
|
+
_iterator.return();
|
269
|
+
}
|
270
|
+
} finally{
|
271
|
+
if (_didIteratorError) {
|
272
|
+
throw _iteratorError;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}
|
276
|
+
if (target === "service-worker") {
|
277
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
278
|
+
try {
|
279
|
+
for(var _iterator1 = webWorkerExts[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
280
|
+
var ext1 = _step1.value;
|
281
|
+
chain.resolve.extensions.prepend(ext1);
|
282
|
+
}
|
283
|
+
} catch (err) {
|
284
|
+
_didIteratorError1 = true;
|
285
|
+
_iteratorError1 = err;
|
286
|
+
} finally{
|
287
|
+
try {
|
288
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
289
|
+
_iterator1.return();
|
290
|
+
}
|
291
|
+
} finally{
|
292
|
+
if (_didIteratorError1) {
|
293
|
+
throw _iteratorError1;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
}
|
248
297
|
}
|
249
298
|
filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
|
250
299
|
}
|
@@ -48,8 +48,8 @@ var BottomTemplatePlugin = /*#__PURE__*/ function() {
|
|
48
48
|
var _this = this;
|
49
49
|
compiler.hooks.compilation.tap(this.name, function(compilation) {
|
50
50
|
_this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function(data) {
|
51
|
-
var
|
52
|
-
if (!((
|
51
|
+
var _data_plugin_options;
|
52
|
+
if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
|
53
53
|
return data;
|
54
54
|
}
|
55
55
|
if (_this.bottomTemplateReg.test(data.html)) {
|
@@ -182,7 +182,7 @@ import { buildServerConfig } from "../utils/config";
|
|
182
182
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
183
183
|
var dev = function() {
|
184
184
|
var _ref = _asyncToGenerator(function(api, options) {
|
185
|
-
var
|
185
|
+
var _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions, app, server;
|
186
186
|
return __generator(this, function(_state) {
|
187
187
|
switch(_state.label){
|
188
188
|
case 0:
|
@@ -237,7 +237,7 @@ var dev = function() {
|
|
237
237
|
dev: _objectSpread({
|
238
238
|
port: port,
|
239
239
|
https: normalizedConfig.dev.https
|
240
|
-
}, (
|
240
|
+
}, (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer),
|
241
241
|
pwd: appDirectory,
|
242
242
|
config: normalizedConfig,
|
243
243
|
serverConfigFile: serverConfigFile,
|
@@ -129,7 +129,7 @@ import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
129
129
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
130
130
|
var start = function() {
|
131
131
|
var _ref = _asyncToGenerator(function(api) {
|
132
|
-
var
|
132
|
+
var _userConfig_source, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, serverInternalPlugins, app;
|
133
133
|
return __generator(this, function(_state) {
|
134
134
|
switch(_state.label){
|
135
135
|
case 0:
|
@@ -140,7 +140,7 @@ var start = function() {
|
|
140
140
|
logger.log(chalk.cyan("Starting the modern server..."));
|
141
141
|
return [
|
142
142
|
4,
|
143
|
-
isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (
|
143
|
+
isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir)
|
144
144
|
];
|
145
145
|
case 1:
|
146
146
|
apiOnly = _state.sent();
|
@@ -107,7 +107,7 @@ function initHtmlConfig(config, appContext) {
|
|
107
107
|
}
|
108
108
|
function initSourceConfig(config, appContext, bundler) {
|
109
109
|
var createBuilderGlobalVars = function createBuilderGlobalVars(config2, appContext2) {
|
110
|
-
var
|
110
|
+
var _config2_source = config2.source, _config2_source_globalVars = _config2_source.globalVars, globalVars = _config2_source_globalVars === void 0 ? {} : _config2_source_globalVars;
|
111
111
|
var publicEnv = getAutoInjectEnv(appContext2);
|
112
112
|
return _objectSpread({}, globalVars, publicEnv);
|
113
113
|
};
|
@@ -199,7 +199,7 @@ function initToolsConfig(config) {
|
|
199
199
|
]
|
200
200
|
}
|
201
201
|
};
|
202
|
-
var
|
202
|
+
var _config_tools = config.tools, tsChecker = _config_tools.tsChecker, tsLoader = _config_tools.tsLoader;
|
203
203
|
config.tools.tsChecker = applyOptionsChain(defaultTsChecker, tsChecker);
|
204
204
|
tsLoader && (config.tools.tsLoader = function(tsLoaderConfig, utils) {
|
205
205
|
applyOptionsChain(_objectSpreadProps(_objectSpread({}, tsLoaderConfig), {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
function createHtmlConfig(config) {
|
2
|
-
var
|
2
|
+
var _config_output = config.output, disableHtmlFolder = _config_output.disableHtmlFolder, favicon = _config_output.favicon, faviconByEntries = _config_output.faviconByEntries, inject = _config_output.inject, injectByEntries = _config_output.injectByEntries, meta = _config_output.meta, metaByEntries = _config_output.metaByEntries, mountId = _config_output.mountId, title = _config_output.title, titleByEntries = _config_output.titleByEntries, templateParameters = _config_output.templateParameters, templateParametersByEntries = _config_output.templateParametersByEntries, crossorigin = _config_output.crossorigin;
|
3
3
|
return {
|
4
4
|
disableHtmlFolder: disableHtmlFolder,
|
5
5
|
favicon: favicon,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
function createOutputConfig(config) {
|
2
|
-
var
|
2
|
+
var _config_output = config.output, assetPrefix = _config_output.assetPrefix, copy = _config_output.copy, cssModuleLocalIdentName = _config_output.cssModuleLocalIdentName, cssPath = _config_output.cssPath, jsPath = _config_output.jsPath, htmlPath = _config_output.htmlPath, mediaPath = _config_output.mediaPath, enableTsLoader = _config_output.enableTsLoader, path = _config_output.path, disableInlineRuntimeChunk = _config_output.disableInlineRuntimeChunk, disableCssExtract = _config_output.disableCssExtract, disableMinimize = _config_output.disableMinimize, disableSourceMap = _config_output.disableSourceMap, disableTsChecker = _config_output.disableTsChecker, enableCssModuleTSDeclaration = _config_output.enableCssModuleTSDeclaration, enableInlineScripts = _config_output.enableInlineScripts, enableInlineStyles = _config_output.enableInlineStyles, polyfill = _config_output.polyfill, dataUriLimit = _config_output.dataUriLimit, disableAssetsCache = _config_output.disableAssetsCache, enableLatestDecorators = _config_output.enableLatestDecorators, disableCssModuleExtension = _config_output.disableCssModuleExtension, ssg = _config_output.ssg, disableNodePolyfill = _config_output.disableNodePolyfill;
|
3
3
|
return {
|
4
4
|
assetPrefix: assetPrefix,
|
5
5
|
copy: copy,
|
@@ -1,5 +1,5 @@
|
|
1
1
|
function createSourceConfig(config) {
|
2
|
-
var
|
2
|
+
var _config_source = config.source, alias = _config_source.alias, envVars = _config_source.envVars, globalVars = _config_source.globalVars, include = _config_source.include, moduleScopes = _config_source.moduleScopes, preEntry = _config_source.preEntry, entries = _config_source.entries, enableAsyncEntry = _config_source.enableAsyncEntry, disableDefaultEntries = _config_source.disableDefaultEntries, entriesDir = _config_source.entriesDir, configDir = _config_source.configDir;
|
3
3
|
var builderGlobalVars = globalVars || {};
|
4
4
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
5
5
|
try {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
function createToolsConfig(config) {
|
2
|
-
var
|
2
|
+
var _config_tools = config.tools, autoprefixer = _config_tools.autoprefixer, babel = _config_tools.babel, minifyCss = _config_tools.minifyCss, terser = _config_tools.terser, webpack = _config_tools.webpack, webpackChain = _config_tools.webpackChain, tsLoader = _config_tools.tsLoader, styledComponents = _config_tools.styledComponents, sass = _config_tools.sass, postcss = _config_tools.postcss, less = _config_tools.less, htmlPlugin = _config_tools.htmlPlugin, devServer = _config_tools.devServer, tailwindcss = _config_tools.tailwindcss, jest = _config_tools.jest, esbuild = _config_tools.esbuild;
|
3
3
|
var enableTsLoader = config.output.enableTsLoader;
|
4
4
|
return {
|
5
5
|
tsLoader: enableTsLoader ? tsLoader : void 0,
|
@@ -198,7 +198,7 @@ var initialize_default = function(param) {
|
|
198
198
|
resolvedConfig: function resolvedConfig(param) {
|
199
199
|
var resolved = param.resolved;
|
200
200
|
return _asyncToGenerator(function() {
|
201
|
-
var
|
201
|
+
var _resolved_output_distPath, appContext, userConfig, port, normalizedConfig;
|
202
202
|
return __generator(this, function(_state) {
|
203
203
|
switch(_state.label){
|
204
204
|
case 0:
|
@@ -212,7 +212,7 @@ var initialize_default = function(param) {
|
|
212
212
|
port = _state.sent();
|
213
213
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
214
214
|
port: port,
|
215
|
-
distDirectory: ensureAbsolutePath(appContext.distDirectory, ((
|
215
|
+
distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
216
216
|
});
|
217
217
|
api.setAppContext(appContext);
|
218
218
|
normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
@@ -275,11 +275,11 @@ var safeReplacer = function() {
|
|
275
275
|
};
|
276
276
|
var emitResolvedConfig = function() {
|
277
277
|
var _ref = _asyncToGenerator(function(appDirectory, resolvedConfig) {
|
278
|
-
var
|
278
|
+
var _resolvedConfig_output_distPath, outputPath;
|
279
279
|
return __generator(this, function(_state) {
|
280
280
|
switch(_state.label){
|
281
281
|
case 0:
|
282
|
-
outputPath = path.join(appDirectory, ((
|
282
|
+
outputPath = path.join(appDirectory, ((_resolvedConfig_output_distPath = resolvedConfig.output.distPath) === null || _resolvedConfig_output_distPath === void 0 ? void 0 : _resolvedConfig_output_distPath.root) || "./dist", OUTPUT_CONFIG_FILE);
|
283
283
|
return [
|
284
284
|
4,
|
285
285
|
fs.writeJSON(outputPath, resolvedConfig, {
|
@@ -179,7 +179,7 @@ function getServerInternalPlugins(api) {
|
|
179
179
|
}
|
180
180
|
function _getServerInternalPlugins() {
|
181
181
|
_getServerInternalPlugins = _asyncToGenerator(function(api) {
|
182
|
-
var hookRunners,
|
182
|
+
var hookRunners, _ref, serverPlugins, serverInternalPlugins;
|
183
183
|
return __generator(this, function(_state) {
|
184
184
|
switch(_state.label){
|
185
185
|
case 0:
|
@@ -191,7 +191,7 @@ function _getServerInternalPlugins() {
|
|
191
191
|
})
|
192
192
|
];
|
193
193
|
case 1:
|
194
|
-
|
194
|
+
_ref = _state.sent(), serverPlugins = _ref.plugins;
|
195
195
|
serverInternalPlugins = serverPlugins.reduce(function(result, plugin) {
|
196
196
|
return Object.assign(result, plugin);
|
197
197
|
}, {});
|
@@ -4,6 +4,7 @@ import type { Entrypoint, HtmlPartials, NestedRoute, PageRoute, RouteLegacy, Ser
|
|
4
4
|
import type { RegisterBuildPlatformResult, DevToolData } from '@modern-js/core';
|
5
5
|
import type { Stats, MultiStats } from '@modern-js/builder-shared';
|
6
6
|
import type { Rspack } from '@modern-js/builder-rspack-provider';
|
7
|
+
import { Bundler } from './utils';
|
7
8
|
export interface ImportSpecifier {
|
8
9
|
local?: string;
|
9
10
|
imported?: string;
|
@@ -18,7 +19,7 @@ export interface RuntimePlugin {
|
|
18
19
|
options: string;
|
19
20
|
args?: string;
|
20
21
|
}
|
21
|
-
export type AppToolsHooks = {
|
22
|
+
export type AppToolsHooks<B extends Bundler = 'webpack'> = {
|
22
23
|
modifyEntryExport: AsyncWaterfall<{
|
23
24
|
entrypoint: Entrypoint;
|
24
25
|
exportStatement: string;
|
@@ -61,16 +62,16 @@ export type AppToolsHooks = {
|
|
61
62
|
beforeDev: AsyncWorkflow<void, unknown>;
|
62
63
|
afterDev: AsyncWorkflow<void, unknown>;
|
63
64
|
beforeCreateCompiler: AsyncWorkflow<{
|
64
|
-
bundlerConfigs
|
65
|
+
bundlerConfigs?: B extends 'rspack' ? Rspack.Configuration[] : webpack.Configuration[];
|
65
66
|
}, unknown>;
|
66
67
|
afterCreateCompiler: AsyncWorkflow<{
|
67
|
-
compiler?:
|
68
|
+
compiler?: B extends 'rspack' ? Rspack.Compiler : webpack.Compiler | webpack.MultiCompiler;
|
68
69
|
}, unknown>;
|
69
70
|
beforePrintInstructions: AsyncWaterfall<{
|
70
71
|
instructions: string;
|
71
72
|
}>;
|
72
73
|
beforeBuild: AsyncWorkflow<{
|
73
|
-
bundlerConfigs?:
|
74
|
+
bundlerConfigs?: B extends 'rspack' ? Rspack.Configuration[] : webpack.Configuration[];
|
74
75
|
}, unknown>;
|
75
76
|
afterBuild: AsyncWorkflow<{
|
76
77
|
stats?: Stats | MultiStats;
|
@@ -6,11 +6,13 @@ import { Bundler, FromConfig } from './utils';
|
|
6
6
|
export * from './hooks';
|
7
7
|
export * from './config';
|
8
8
|
export * from './legacyConfig';
|
9
|
+
export type { webpack } from '@modern-js/builder-webpack-provider';
|
10
|
+
export type { Rspack } from '@modern-js/builder-rspack-provider';
|
9
11
|
export type { Bundler } from './utils';
|
10
12
|
export type { ServerUserConfig, ServerNormalizedConfig, BffUserConfig, BffNormalizedConfig, SSR, SSRByEntries } from '@modern-js/server-core';
|
11
13
|
export type { IAppContext, PluginAPI, CliPlugin, NormalizedConfig, UserConfig } from '@modern-js/core';
|
12
14
|
export type AppTools<B extends Bundler = 'webpack'> = {
|
13
|
-
hooks: AppToolsHooks
|
15
|
+
hooks: AppToolsHooks<B>;
|
14
16
|
userConfig: FromConfig<B, {
|
15
17
|
rspack: RsAppToolsUserConfig;
|
16
18
|
webpack: AppToolsUserConfig;
|