@modern-js/app-tools 1.21.5 → 2.0.0-beta.1
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/CHANGELOG.md +319 -51
- package/dist/js/modern/analyze/constants.js +1 -0
- package/dist/js/modern/analyze/generateCode.js +126 -32
- package/dist/js/modern/analyze/getBundleEntry.js +7 -14
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +173 -0
- package/dist/js/modern/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +13 -58
- package/dist/js/modern/analyze/getClientRoutes/index.js +2 -0
- package/dist/js/modern/analyze/getClientRoutes/utils.js +18 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +27 -21
- package/dist/js/modern/analyze/getHtmlTemplate.js +2 -9
- package/dist/js/modern/analyze/getServerRoutes.js +15 -32
- package/dist/js/modern/analyze/index.js +81 -23
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/modern/analyze/nestedRoutes.js +102 -0
- package/dist/js/modern/analyze/templates.js +151 -12
- package/dist/js/modern/analyze/utils.js +2 -8
- package/dist/js/modern/builder/builderPlugins/compatModern.js +208 -0
- package/dist/js/modern/builder/createHtmlConfig.js +58 -0
- package/dist/js/modern/builder/createOutputConfig.js +70 -0
- package/dist/js/modern/builder/createSourceConfig.js +74 -0
- package/dist/js/modern/builder/createToolsConfig.js +87 -0
- package/dist/js/modern/builder/index.js +108 -0
- package/dist/js/modern/builder/share.js +44 -0
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +29 -0
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +33 -0
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
- package/dist/js/modern/commands/build.js +16 -110
- package/dist/js/modern/commands/dev.js +12 -28
- package/dist/js/modern/commands/inspect.js +8 -66
- package/dist/js/modern/commands/start.js +2 -3
- package/dist/js/modern/index.js +17 -16
- package/dist/js/modern/locale/en.js +0 -1
- package/dist/js/modern/locale/zh.js +0 -1
- package/dist/js/modern/utils/commands.js +5 -0
- package/dist/js/modern/utils/config.js +1 -12
- package/dist/js/modern/utils/createServer.js +12 -1
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
- package/dist/js/modern/utils/printInstructions.js +3 -2
- package/dist/js/modern/utils/routes.js +0 -2
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/generateCode.js +123 -47
- package/dist/js/node/analyze/getBundleEntry.js +7 -20
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +181 -0
- package/dist/js/node/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +19 -78
- package/dist/js/node/analyze/getClientRoutes/index.js +19 -0
- package/dist/js/node/analyze/getClientRoutes/utils.js +28 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +26 -28
- package/dist/js/node/analyze/getHtmlTemplate.js +2 -23
- package/dist/js/node/analyze/getServerRoutes.js +14 -40
- package/dist/js/node/analyze/index.js +81 -33
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
- package/dist/js/node/analyze/nestedRoutes.js +111 -0
- package/dist/js/node/analyze/templates.js +153 -21
- package/dist/js/node/analyze/utils.js +4 -20
- package/dist/js/node/builder/builderPlugins/compatModern.js +216 -0
- package/dist/js/node/builder/createHtmlConfig.js +68 -0
- package/dist/js/node/builder/createOutputConfig.js +76 -0
- package/dist/js/node/builder/createSourceConfig.js +82 -0
- package/dist/js/node/builder/createToolsConfig.js +94 -0
- package/dist/js/node/builder/index.js +117 -0
- package/dist/js/node/builder/share.js +51 -0
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +36 -0
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +40 -0
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
- package/dist/js/node/commands/build.js +14 -121
- package/dist/js/node/commands/deploy.js +0 -2
- package/dist/js/node/commands/dev.js +10 -44
- package/dist/js/node/commands/index.js +0 -6
- package/dist/js/node/commands/inspect.js +10 -90
- package/dist/js/node/commands/start.js +2 -11
- package/dist/js/node/exports/server.js +0 -1
- package/dist/js/node/hooks.js +0 -2
- package/dist/js/node/index.js +22 -32
- package/dist/js/node/locale/en.js +0 -1
- package/dist/js/node/locale/index.js +0 -4
- package/dist/js/node/locale/zh.js +0 -1
- package/dist/js/node/utils/commands.js +12 -0
- package/dist/js/node/utils/config.js +1 -25
- package/dist/js/node/utils/createServer.js +15 -11
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
- package/dist/js/node/utils/language.js +0 -2
- package/dist/js/node/utils/printInstructions.js +3 -6
- package/dist/js/node/utils/routes.js +0 -5
- package/dist/js/treeshaking/analyze/constants.js +16 -0
- package/dist/js/treeshaking/analyze/generateCode.js +369 -0
- package/dist/js/treeshaking/analyze/getBundleEntry.js +69 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +184 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +185 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +2 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +24 -0
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +96 -0
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +129 -0
- package/dist/js/treeshaking/analyze/getServerRoutes.js +157 -0
- package/dist/js/treeshaking/analyze/index.js +334 -0
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +28 -0
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +16 -0
- package/dist/js/treeshaking/analyze/nestedRoutes.js +165 -0
- package/dist/js/treeshaking/analyze/templates.js +170 -0
- package/dist/js/treeshaking/analyze/utils.js +88 -0
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +212 -0
- package/dist/js/treeshaking/builder/createHtmlConfig.js +59 -0
- package/dist/js/treeshaking/builder/createOutputConfig.js +70 -0
- package/dist/js/treeshaking/builder/createSourceConfig.js +88 -0
- package/dist/js/treeshaking/builder/createToolsConfig.js +85 -0
- package/dist/js/treeshaking/builder/index.js +161 -0
- package/dist/js/treeshaking/builder/share.js +46 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +46 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +41 -0
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
- package/dist/js/treeshaking/commands/build.js +83 -0
- package/dist/js/treeshaking/commands/deploy.js +26 -0
- package/dist/js/treeshaking/commands/dev.js +124 -0
- package/dist/js/treeshaking/commands/index.js +3 -0
- package/dist/js/treeshaking/commands/inspect.js +29 -0
- package/dist/js/treeshaking/commands/start.js +69 -0
- package/dist/js/treeshaking/exports/server.js +1 -0
- package/dist/js/treeshaking/hooks.js +21 -0
- package/dist/js/treeshaking/index.js +267 -0
- package/dist/js/treeshaking/locale/en.js +34 -0
- package/dist/js/treeshaking/locale/index.js +9 -0
- package/dist/js/treeshaking/locale/zh.js +34 -0
- package/dist/js/treeshaking/utils/commands.js +5 -0
- package/dist/js/treeshaking/utils/config.js +124 -0
- package/dist/js/treeshaking/utils/createServer.js +73 -0
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +58 -0
- package/dist/js/treeshaking/utils/language.js +5 -0
- package/dist/js/treeshaking/utils/printInstructions.js +30 -0
- package/dist/js/treeshaking/utils/routes.js +29 -0
- package/dist/js/treeshaking/utils/types.js +0 -0
- package/dist/types/analyze/constants.d.ts +1 -0
- package/dist/types/analyze/generateCode.d.ts +1 -1
- package/dist/types/analyze/{getClientRoutes.d.ts → getClientRoutes/getRoutes.d.ts} +2 -7
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +15 -0
- package/dist/types/analyze/getClientRoutes/index.d.ts +2 -0
- package/dist/types/analyze/getClientRoutes/utils.d.ts +5 -0
- package/dist/types/analyze/index.d.ts +4 -5
- package/dist/types/analyze/nestedRoutes.d.ts +5 -0
- package/dist/types/analyze/templates.d.ts +19 -3
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +13 -0
- package/dist/types/builder/createHtmlConfig.d.ts +6 -0
- package/dist/types/builder/createOutputConfig.d.ts +3 -0
- package/dist/types/builder/createSourceConfig.d.ts +5 -0
- package/dist/types/builder/createToolsConfig.d.ts +13 -0
- package/dist/types/builder/index.d.ts +15 -0
- package/dist/types/builder/share.d.ts +26 -0
- package/dist/types/builder/webpackPlugins/htmlAsyncChunkPlugin.d.ts +8 -0
- package/dist/types/builder/webpackPlugins/htmlBottomTemplate.d.ts +10 -0
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
- package/dist/types/commands/build.d.ts +2 -1
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/commands/inspect.d.ts +2 -6
- package/dist/types/commands/start.d.ts +2 -1
- package/dist/types/hooks.d.ts +15 -10
- package/dist/types/index.d.ts +4 -4
- package/dist/types/locale/en.d.ts +0 -1
- package/dist/types/locale/index.d.ts +0 -2
- package/dist/types/locale/zh.d.ts +0 -1
- package/dist/types/utils/commands.d.ts +1 -0
- package/dist/types/utils/config.d.ts +0 -1
- package/dist/types/utils/createServer.d.ts +8 -1
- package/dist/types/utils/printInstructions.d.ts +3 -2
- package/dist/types/utils/types.d.ts +2 -3
- package/package.json +25 -42
- package/dist/js/modern/utils/createCompiler.js +0 -61
- package/dist/js/node/utils/createCompiler.js +0 -81
- package/dist/types/utils/createCompiler.d.ts +0 -13
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { fs, getRouteId } from '@modern-js/utils';
|
|
7
|
+
import { JS_EXTENSIONS } from "./constants";
|
|
8
|
+
import { replaceWithAlias } from "./utils";
|
|
9
|
+
var LAYOUT_FILE = 'layout';
|
|
10
|
+
var PAGE_FILE = 'page';
|
|
11
|
+
var LOADING_FILE = 'loading';
|
|
12
|
+
var ERROR_FILE = 'error';
|
|
13
|
+
var LOADER_FILE = 'loader';
|
|
14
|
+
var conventionNames = [LAYOUT_FILE, PAGE_FILE, LOADING_FILE, ERROR_FILE, LOADER_FILE];
|
|
15
|
+
var replaceDynamicPath = function replaceDynamicPath(routePath) {
|
|
16
|
+
return routePath.replace(/\[(.*?)\]/g, ':$1');
|
|
17
|
+
};
|
|
18
|
+
var createIndexRoute = function createIndexRoute(routeInfo, rootDir, filename, entryName) {
|
|
19
|
+
return createRoute(_objectSpread(_objectSpread({}, routeInfo), {}, {
|
|
20
|
+
index: true,
|
|
21
|
+
children: undefined
|
|
22
|
+
}), rootDir, filename, entryName);
|
|
23
|
+
};
|
|
24
|
+
var createRoute = function createRoute(routeInfo, rootDir, filename, entryName) {
|
|
25
|
+
var id = getRouteId(filename, rootDir, entryName);
|
|
26
|
+
return _objectSpread(_objectSpread({}, routeInfo), {}, {
|
|
27
|
+
id: id,
|
|
28
|
+
type: 'nested'
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
export var walk = /*#__PURE__*/function () {
|
|
32
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(dirname, rootDir, alias, entryName) {
|
|
33
|
+
var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, items, _iterator, _step, item, itemPath, extname, itemWithoutExt, _isDirectory, childRoute, _route$children, _route$children2, _childRoute, finalRoute;
|
|
34
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
35
|
+
while (1) {
|
|
36
|
+
switch (_context.prev = _context.next) {
|
|
37
|
+
case 0:
|
|
38
|
+
_context.next = 2;
|
|
39
|
+
return fs.pathExists(dirname);
|
|
40
|
+
case 2:
|
|
41
|
+
if (_context.sent) {
|
|
42
|
+
_context.next = 4;
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
return _context.abrupt("return", null);
|
|
46
|
+
case 4:
|
|
47
|
+
_context.next = 6;
|
|
48
|
+
return fs.stat(dirname);
|
|
49
|
+
case 6:
|
|
50
|
+
isDirectory = _context.sent.isDirectory();
|
|
51
|
+
if (isDirectory) {
|
|
52
|
+
_context.next = 9;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
return _context.abrupt("return", null);
|
|
56
|
+
case 9:
|
|
57
|
+
relativeDir = path.relative(rootDir, dirname);
|
|
58
|
+
pathSegments = relativeDir.split(path.sep);
|
|
59
|
+
lastSegment = pathSegments[pathSegments.length - 1];
|
|
60
|
+
isRoot = lastSegment === '';
|
|
61
|
+
isPathlessLayout = lastSegment.startsWith('__');
|
|
62
|
+
isWithoutLayoutPath = lastSegment.includes('.');
|
|
63
|
+
routePath = isRoot || isPathlessLayout ? '/' : "".concat(lastSegment);
|
|
64
|
+
if (isWithoutLayoutPath) {
|
|
65
|
+
routePath = lastSegment.split('.').join('/');
|
|
66
|
+
}
|
|
67
|
+
routePath = replaceDynamicPath(routePath);
|
|
68
|
+
route = {
|
|
69
|
+
path: routePath,
|
|
70
|
+
children: []
|
|
71
|
+
};
|
|
72
|
+
_context.next = 21;
|
|
73
|
+
return fs.readdir(dirname);
|
|
74
|
+
case 21:
|
|
75
|
+
items = _context.sent;
|
|
76
|
+
_iterator = _createForOfIteratorHelper(items);
|
|
77
|
+
_context.prev = 23;
|
|
78
|
+
_iterator.s();
|
|
79
|
+
case 25:
|
|
80
|
+
if ((_step = _iterator.n()).done) {
|
|
81
|
+
_context.next = 47;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
item = _step.value;
|
|
85
|
+
itemPath = path.join(dirname, item);
|
|
86
|
+
extname = path.extname(item);
|
|
87
|
+
itemWithoutExt = item.slice(0, -extname.length);
|
|
88
|
+
_context.next = 32;
|
|
89
|
+
return fs.stat(itemPath);
|
|
90
|
+
case 32:
|
|
91
|
+
_isDirectory = _context.sent.isDirectory();
|
|
92
|
+
if (!_isDirectory) {
|
|
93
|
+
_context.next = 38;
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
_context.next = 36;
|
|
97
|
+
return walk(itemPath, rootDir, alias, entryName);
|
|
98
|
+
case 36:
|
|
99
|
+
childRoute = _context.sent;
|
|
100
|
+
if (childRoute) {
|
|
101
|
+
(_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.push(childRoute);
|
|
102
|
+
}
|
|
103
|
+
case 38:
|
|
104
|
+
if (!(extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt)))) {
|
|
105
|
+
_context.next = 40;
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return _context.abrupt("continue", 45);
|
|
109
|
+
case 40:
|
|
110
|
+
if (itemWithoutExt === LAYOUT_FILE) {
|
|
111
|
+
route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
112
|
+
}
|
|
113
|
+
if (itemWithoutExt === PAGE_FILE) {
|
|
114
|
+
_childRoute = createIndexRoute({
|
|
115
|
+
_component: replaceWithAlias(alias.basename, itemPath, alias.name)
|
|
116
|
+
}, rootDir, itemPath, entryName);
|
|
117
|
+
(_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.push(_childRoute);
|
|
118
|
+
}
|
|
119
|
+
if (itemWithoutExt === LOADER_FILE) {
|
|
120
|
+
route.loader = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
121
|
+
}
|
|
122
|
+
if (itemWithoutExt === LOADING_FILE) {
|
|
123
|
+
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
124
|
+
}
|
|
125
|
+
if (itemWithoutExt === ERROR_FILE) {
|
|
126
|
+
route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
127
|
+
}
|
|
128
|
+
case 45:
|
|
129
|
+
_context.next = 25;
|
|
130
|
+
break;
|
|
131
|
+
case 47:
|
|
132
|
+
_context.next = 52;
|
|
133
|
+
break;
|
|
134
|
+
case 49:
|
|
135
|
+
_context.prev = 49;
|
|
136
|
+
_context.t0 = _context["catch"](23);
|
|
137
|
+
_iterator.e(_context.t0);
|
|
138
|
+
case 52:
|
|
139
|
+
_context.prev = 52;
|
|
140
|
+
_iterator.f();
|
|
141
|
+
return _context.finish(52);
|
|
142
|
+
case 55:
|
|
143
|
+
finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(LAYOUT_FILE, ".ts")), entryName);
|
|
144
|
+
/**
|
|
145
|
+
* when the url is /, the __auth/layout.tsx component should not be rendered
|
|
146
|
+
* - routes
|
|
147
|
+
* - __auth
|
|
148
|
+
* - layout.tsx
|
|
149
|
+
* - layout.tsx
|
|
150
|
+
*/
|
|
151
|
+
if (isPathlessLayout) {
|
|
152
|
+
delete finalRoute.path;
|
|
153
|
+
}
|
|
154
|
+
return _context.abrupt("return", finalRoute);
|
|
155
|
+
case 58:
|
|
156
|
+
case "end":
|
|
157
|
+
return _context.stop();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}, _callee, null, [[23, 49, 52, 55]]);
|
|
161
|
+
}));
|
|
162
|
+
return function walk(_x, _x2, _x3, _x4) {
|
|
163
|
+
return _ref.apply(this, arguments);
|
|
164
|
+
};
|
|
165
|
+
}();
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
export var index = function index(_ref) {
|
|
4
|
+
var mountId = _ref.mountId,
|
|
5
|
+
imports = _ref.imports,
|
|
6
|
+
renderFunction = _ref.renderFunction,
|
|
7
|
+
exportStatement = _ref.exportStatement;
|
|
8
|
+
return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
|
|
9
|
+
};
|
|
10
|
+
export var renderFunction = function renderFunction(_ref2) {
|
|
11
|
+
var plugins = _ref2.plugins,
|
|
12
|
+
customBootstrap = _ref2.customBootstrap,
|
|
13
|
+
fileSystemRoutes = _ref2.fileSystemRoutes;
|
|
14
|
+
return "\n AppWrapper = createApp({\n plugins: [\n ".concat(plugins.map(function (_ref3) {
|
|
15
|
+
var name = _ref3.name,
|
|
16
|
+
options = _ref3.options,
|
|
17
|
+
args = _ref3.args;
|
|
18
|
+
return "".concat(name, "({...").concat(options, ", ...App?.config?.").concat(args || name, "}),");
|
|
19
|
+
}).join('\n'), "\n ]\n })(").concat(fileSystemRoutes ? '' : "App", ")\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper);" : "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);", "\n }\n\n return AppWrapper\n");
|
|
20
|
+
};
|
|
21
|
+
export var html = function html(partials) {
|
|
22
|
+
return "\n<!DOCTYPE html>\n<html>\n<head>\n <%= meta %>\n <title><%= title %></title>\n\n ".concat(partials.top.join('\n'), "\n\n <script>\n window.__assetPrefix__ = '<%= assetPrefix %>';\n </script>\n ").concat(partials.head.join('\n'), "\n\n <!--<?- chunksMap.css ?>-->\n</head>\n\n<body>\n <noscript>\n We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.\n </noscript>\n <div id=\"<%= mountId %>\"><!--<?- html ?>--></div>\n ").concat(partials.body.join('\n'), "\n <!--<?- chunksMap.js ?>-->\n <!--<?- SSRDataScript ?>-->\n <!--<?- bottomTemplate ?>-->\n</body>\n\n</html>\n");
|
|
23
|
+
};
|
|
24
|
+
export var routesForServer = function routesForServer(_ref4) {
|
|
25
|
+
var routes = _ref4.routes,
|
|
26
|
+
alias = _ref4.alias;
|
|
27
|
+
var name = alias.name,
|
|
28
|
+
basename = alias.basename;
|
|
29
|
+
var loaders = [];
|
|
30
|
+
var traverseRouteTree = function traverseRouteTree(route) {
|
|
31
|
+
var children;
|
|
32
|
+
if ('children' in route && route.children) {
|
|
33
|
+
var _route$children;
|
|
34
|
+
children = route === null || route === void 0 ? void 0 : (_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.map(traverseRouteTree);
|
|
35
|
+
}
|
|
36
|
+
var loader;
|
|
37
|
+
if (route.type === 'nested') {
|
|
38
|
+
if (route.loader) {
|
|
39
|
+
loaders.push(route.loader);
|
|
40
|
+
loader = "loader_".concat(loaders.length - 1);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
44
|
+
loader: loader,
|
|
45
|
+
children: children
|
|
46
|
+
});
|
|
47
|
+
return finalRoute;
|
|
48
|
+
};
|
|
49
|
+
var routesCode = "\n export const routes = [\n ";
|
|
50
|
+
var _iterator = _createForOfIteratorHelper(routes),
|
|
51
|
+
_step;
|
|
52
|
+
try {
|
|
53
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
54
|
+
var route = _step.value;
|
|
55
|
+
if ('type' in route) {
|
|
56
|
+
var newRoute = traverseRouteTree(route);
|
|
57
|
+
routesCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loader_[^"])"/g, '$1'), ",");
|
|
58
|
+
} else {
|
|
59
|
+
routesCode += "".concat(JSON.stringify(route, null, 2));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
} catch (err) {
|
|
63
|
+
_iterator.e(err);
|
|
64
|
+
} finally {
|
|
65
|
+
_iterator.f();
|
|
66
|
+
}
|
|
67
|
+
routesCode += "\n];";
|
|
68
|
+
var importLoadersCode = loaders.map(function (loader, index) {
|
|
69
|
+
var realLoaderPath = loader.replace(name, basename);
|
|
70
|
+
return "import loader_".concat(index, " from '").concat(realLoaderPath, "';\n");
|
|
71
|
+
}).join('');
|
|
72
|
+
return "\n ".concat(importLoadersCode, "\n ").concat(routesCode, "\n ");
|
|
73
|
+
};
|
|
74
|
+
export var fileSystemRoutes = function fileSystemRoutes(_ref5) {
|
|
75
|
+
var routes = _ref5.routes,
|
|
76
|
+
ssrMode = _ref5.ssrMode,
|
|
77
|
+
nestedRoutesEntry = _ref5.nestedRoutesEntry,
|
|
78
|
+
entryName = _ref5.entryName;
|
|
79
|
+
// The legacy mode and pages dir routes should use loadable
|
|
80
|
+
// nested routes + renderTostring should use loadable.lazy
|
|
81
|
+
// nested routes + renderToStream should use react.lazy
|
|
82
|
+
var importLazyCode = "\n import { lazy } from \"react\";\n import loadable, { lazy as loadableLazy } from \"@modern-js/runtime/loadable\"\n ";
|
|
83
|
+
var dataLoaderPath = '';
|
|
84
|
+
if (ssrMode) {
|
|
85
|
+
dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
86
|
+
if (nestedRoutesEntry) {
|
|
87
|
+
dataLoaderPath = "".concat(dataLoaderPath, "?routesDir=").concat(nestedRoutesEntry, "&entryName=").concat(entryName, "!");
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
var loadings = [];
|
|
91
|
+
var errors = [];
|
|
92
|
+
var loaders = [];
|
|
93
|
+
var traverseRouteTree = function traverseRouteTree(route) {
|
|
94
|
+
var children;
|
|
95
|
+
if ('children' in route && route.children) {
|
|
96
|
+
var _route$children2;
|
|
97
|
+
children = route === null || route === void 0 ? void 0 : (_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.map(traverseRouteTree);
|
|
98
|
+
}
|
|
99
|
+
var loading;
|
|
100
|
+
var error;
|
|
101
|
+
var loader;
|
|
102
|
+
var component = '';
|
|
103
|
+
if (route.type === 'nested') {
|
|
104
|
+
if (route.loading) {
|
|
105
|
+
loadings.push(route.loading);
|
|
106
|
+
loading = "loading_".concat(loadings.length - 1);
|
|
107
|
+
}
|
|
108
|
+
if (route.error) {
|
|
109
|
+
errors.push(route.error);
|
|
110
|
+
error = "error_".concat(errors.length - 1);
|
|
111
|
+
}
|
|
112
|
+
if (route.loader) {
|
|
113
|
+
loaders.push(route.loader);
|
|
114
|
+
loader = "loader_".concat(loaders.length - 1);
|
|
115
|
+
}
|
|
116
|
+
if (route._component) {
|
|
117
|
+
if (ssrMode === 'stream') {
|
|
118
|
+
component = "lazy(() => import(/* webpackChunkName: \"".concat(route.id, "\" */ /* webpackMode: \"lazy-once\" */ '").concat(route._component, "'))");
|
|
119
|
+
} else {
|
|
120
|
+
component = "loadable(() => import(/* webpackChunkName: \"".concat(route.id, "\" */ /* webpackMode: \"lazy-once\" */ '").concat(route._component, "'))");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else if (route._component) {
|
|
124
|
+
component = "loadable(() => import('".concat(route._component, "'))");
|
|
125
|
+
}
|
|
126
|
+
var finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
127
|
+
loading: loading,
|
|
128
|
+
loader: loader,
|
|
129
|
+
error: error,
|
|
130
|
+
children: children
|
|
131
|
+
});
|
|
132
|
+
if (route._component) {
|
|
133
|
+
finalRoute.component = component;
|
|
134
|
+
}
|
|
135
|
+
return finalRoute;
|
|
136
|
+
};
|
|
137
|
+
var routeComponentsCode = "\n export const routes = [\n ";
|
|
138
|
+
var _iterator2 = _createForOfIteratorHelper(routes),
|
|
139
|
+
_step2;
|
|
140
|
+
try {
|
|
141
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
142
|
+
var route = _step2.value;
|
|
143
|
+
if ('type' in route) {
|
|
144
|
+
var newRoute = traverseRouteTree(route);
|
|
145
|
+
routeComponentsCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, '$1').replace(/"(loadableLazy.*\))"/g, '$1').replace(/"(lazy.*\))"/g, '$1').replace(/"(loading_[^"])"/g, '$1').replace(/"(loader_[^"])"/g, '$1').replace(/"(error_[^"])"/g, '$1').replace(/\\"/g, '"'), ",");
|
|
146
|
+
} else {
|
|
147
|
+
var component = "loadable(() => import('".concat(route._component, "'))");
|
|
148
|
+
var finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
149
|
+
component: component
|
|
150
|
+
});
|
|
151
|
+
routeComponentsCode += "".concat(JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, '$1').replace(/"(lazy[^"]*)"/g, '$1'), ",");
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
} catch (err) {
|
|
155
|
+
_iterator2.e(err);
|
|
156
|
+
} finally {
|
|
157
|
+
_iterator2.f();
|
|
158
|
+
}
|
|
159
|
+
routeComponentsCode += "\n];";
|
|
160
|
+
var importLoadingCode = loadings.map(function (loading, index) {
|
|
161
|
+
return "import loading_".concat(index, " from '").concat(loading, "';\n");
|
|
162
|
+
}).join('');
|
|
163
|
+
var importErrorComponentsCode = errors.map(function (error, index) {
|
|
164
|
+
return "import error_".concat(index, " from '").concat(error, "';\n");
|
|
165
|
+
}).join('');
|
|
166
|
+
var importLoaderComponentsCode = loaders.map(function (loader, index) {
|
|
167
|
+
return "import loader_".concat(index, " from '").concat(dataLoaderPath).concat(loader, "';\n");
|
|
168
|
+
}).join('');
|
|
169
|
+
return "\n ".concat(importLazyCode, "\n ").concat(importLoadingCode, "\n ").concat(importErrorComponentsCode, "\n ").concat(importLoaderComponentsCode, "\n ").concat(routeComponentsCode, "\n ");
|
|
170
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import { isReact18, normalizeToPosixPath } from '@modern-js/utils';
|
|
5
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
|
|
6
|
+
export var walkDirectory = function walkDirectory(dir) {
|
|
7
|
+
return fs.readdirSync(dir).reduce(function (previous, filename) {
|
|
8
|
+
var filePath = path.join(dir, filename);
|
|
9
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
10
|
+
return [].concat(_toConsumableArray(previous), _toConsumableArray(walkDirectory(filePath)));
|
|
11
|
+
} else {
|
|
12
|
+
return [].concat(_toConsumableArray(previous), [filePath]);
|
|
13
|
+
}
|
|
14
|
+
}, []);
|
|
15
|
+
};
|
|
16
|
+
export var getDefaultImports = function getDefaultImports(_ref) {
|
|
17
|
+
var entrypoint = _ref.entrypoint,
|
|
18
|
+
srcDirectory = _ref.srcDirectory,
|
|
19
|
+
internalSrcAlias = _ref.internalSrcAlias,
|
|
20
|
+
internalDirAlias = _ref.internalDirAlias,
|
|
21
|
+
internalDirectory = _ref.internalDirectory;
|
|
22
|
+
var entryName = entrypoint.entryName,
|
|
23
|
+
fileSystemRoutes = entrypoint.fileSystemRoutes,
|
|
24
|
+
customBootstrap = entrypoint.customBootstrap,
|
|
25
|
+
entry = entrypoint.entry;
|
|
26
|
+
var imports = [{
|
|
27
|
+
specifiers: [{
|
|
28
|
+
local: 'React'
|
|
29
|
+
}],
|
|
30
|
+
value: 'react'
|
|
31
|
+
}, {
|
|
32
|
+
specifiers: [{
|
|
33
|
+
local: 'ReactDOM'
|
|
34
|
+
}],
|
|
35
|
+
value: isReact18(path.join(internalDirectory, '../../')) ? 'react-dom/client' : 'react-dom'
|
|
36
|
+
}, {
|
|
37
|
+
specifiers: [{
|
|
38
|
+
imported: 'createApp'
|
|
39
|
+
}, {
|
|
40
|
+
imported: 'bootstrap'
|
|
41
|
+
}],
|
|
42
|
+
value: '@modern-js/runtime'
|
|
43
|
+
}, customBootstrap && {
|
|
44
|
+
specifiers: [{
|
|
45
|
+
local: 'customBootstrap'
|
|
46
|
+
}],
|
|
47
|
+
value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
|
48
|
+
}].filter(Boolean);
|
|
49
|
+
if (fileSystemRoutes) {
|
|
50
|
+
var route = {
|
|
51
|
+
specifiers: [{
|
|
52
|
+
imported: 'routes'
|
|
53
|
+
}],
|
|
54
|
+
value: normalizeToPosixPath("".concat(internalDirAlias, "/").concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME))
|
|
55
|
+
};
|
|
56
|
+
if (fileSystemRoutes.globalApp) {
|
|
57
|
+
imports.push({
|
|
58
|
+
specifiers: [{
|
|
59
|
+
local: 'App'
|
|
60
|
+
}],
|
|
61
|
+
value: normalizeToPosixPath(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
route.initialize = 'const App = false;';
|
|
65
|
+
}
|
|
66
|
+
imports.push(route);
|
|
67
|
+
} else {
|
|
68
|
+
imports.push({
|
|
69
|
+
specifiers: [{
|
|
70
|
+
local: 'App'
|
|
71
|
+
}],
|
|
72
|
+
value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return imports;
|
|
76
|
+
};
|
|
77
|
+
export var isRouteComponentFile = function isRouteComponentFile(filePath) {
|
|
78
|
+
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
if (['.js', '.jsx', '.ts', '.tsx'].includes(path.extname(filePath))) {
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
};
|
|
86
|
+
export var replaceWithAlias = function replaceWithAlias(base, filePath, alias) {
|
|
87
|
+
return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
88
|
+
};
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { mergeBuilderConfig } from '@modern-js/builder-shared';
|
|
6
|
+
import { template as lodashTemplate } from '@modern-js/utils/lodash';
|
|
7
|
+
import HtmlWebpackPlugin from '@modern-js/builder-webpack-provider/html-webpack-plugin';
|
|
8
|
+
import { getEntryOptions } from '@modern-js/utils';
|
|
9
|
+
import { BottomTemplatePlugin } from "../webpackPlugins/htmlBottomTemplate";
|
|
10
|
+
import { HtmlAsyncChunkPlugin } from "../webpackPlugins/htmlAsyncChunkPlugin";
|
|
11
|
+
import { createCopyPattern } from "../share";
|
|
12
|
+
import RouterPlugin from "../webpackPlugins/routerPlugin";
|
|
13
|
+
/**
|
|
14
|
+
* Provides default configuration consistent with `@modern-js/webpack`
|
|
15
|
+
*/
|
|
16
|
+
export var PluginCompatModern = function PluginCompatModern(appContext, modernConfig, options) {
|
|
17
|
+
return {
|
|
18
|
+
name: 'builder-plugin-compat-modern',
|
|
19
|
+
setup: function setup(api) {
|
|
20
|
+
api.modifyBuilderConfig(function (config) {
|
|
21
|
+
if (isStreamingSSR(modernConfig)) {
|
|
22
|
+
return mergeBuilderConfig(config, {
|
|
23
|
+
html: {
|
|
24
|
+
inject: 'body'
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return config;
|
|
29
|
+
});
|
|
30
|
+
api.modifyWebpackChain(function (chain, _ref) {
|
|
31
|
+
var target = _ref.target,
|
|
32
|
+
CHAIN_ID = _ref.CHAIN_ID,
|
|
33
|
+
isProd = _ref.isProd;
|
|
34
|
+
var builderNormalizedConfig = api.getNormalizedConfig();
|
|
35
|
+
// set webpack config name
|
|
36
|
+
if (target === 'node') {
|
|
37
|
+
chain.name('server');
|
|
38
|
+
} else if (target === 'modern-web') {
|
|
39
|
+
chain.name('modern');
|
|
40
|
+
} else {
|
|
41
|
+
chain.name('client');
|
|
42
|
+
}
|
|
43
|
+
chain.resolve.modules.add('node_modules').add(join(api.context.rootPath, 'node_modules'));
|
|
44
|
+
|
|
45
|
+
// apply node compat
|
|
46
|
+
if (target === 'node') {
|
|
47
|
+
applyNodeCompat(chain, modernConfig, isProd);
|
|
48
|
+
}
|
|
49
|
+
if (isHtmlEnabled(builderNormalizedConfig, target)) {
|
|
50
|
+
applyBottomHtmlWebpackPlugin({
|
|
51
|
+
api: api,
|
|
52
|
+
chain: chain,
|
|
53
|
+
CHAIN_ID: CHAIN_ID,
|
|
54
|
+
appContext: appContext,
|
|
55
|
+
modernConfig: modernConfig
|
|
56
|
+
});
|
|
57
|
+
applyAsyncChunkHtmlPlugin({
|
|
58
|
+
chain: chain,
|
|
59
|
+
CHAIN_ID: CHAIN_ID,
|
|
60
|
+
modernConfig: modernConfig
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// apply copy plugin
|
|
65
|
+
// const copyPatterns = createCopyPatterns(chain, appContext, modernConfig);
|
|
66
|
+
var defaultCopyPattern = createCopyPattern(appContext, modernConfig, 'public', chain);
|
|
67
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(function (args) {
|
|
68
|
+
var _args$;
|
|
69
|
+
return [{
|
|
70
|
+
patterns: [].concat(_toConsumableArray(((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.patterns) || []), [defaultCopyPattern])
|
|
71
|
+
}];
|
|
72
|
+
});
|
|
73
|
+
var entrypoints = appContext.entrypoints;
|
|
74
|
+
var existNestedRoutes = entrypoints.some(function (entrypoint) {
|
|
75
|
+
return entrypoint.nestedRoutesEntry;
|
|
76
|
+
});
|
|
77
|
+
chain.plugin('route-plugin').use(RouterPlugin, [{
|
|
78
|
+
existNestedRoutes: existNestedRoutes
|
|
79
|
+
}]);
|
|
80
|
+
function isHtmlEnabled(config, target) {
|
|
81
|
+
var _config$tools;
|
|
82
|
+
return ((_config$tools = config.tools) === null || _config$tools === void 0 ? void 0 : _config$tools.htmlPlugin) !== false && target !== 'node' && target !== 'web-worker';
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
if (options) {
|
|
86
|
+
applyCallbacks(api, options);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* register builder hooks callback
|
|
94
|
+
*/
|
|
95
|
+
function applyCallbacks(api, options) {
|
|
96
|
+
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
97
|
+
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
98
|
+
options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
|
|
99
|
+
options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
|
|
100
|
+
options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
|
|
101
|
+
options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
|
|
102
|
+
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
103
|
+
options.onExit && api.onExit(options.onExit);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* compat some config, if target is `node`
|
|
108
|
+
*/
|
|
109
|
+
function applyNodeCompat(chain, modernConfig, isProd) {
|
|
110
|
+
// apply node resolve extensions
|
|
111
|
+
for (var _i = 0, _arr = ['.node.js', '.node.jsx', '.node.ts', '.node.tsx']; _i < _arr.length; _i++) {
|
|
112
|
+
var ext = _arr[_i];
|
|
113
|
+
chain.resolve.extensions.prepend(ext);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// apply filterEntriesBySSRConfig
|
|
117
|
+
filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
|
|
118
|
+
function filterEntriesBySSRConfig(isProd, chain, serverConfig, outputConfig) {
|
|
119
|
+
var _outputConfig$ssg;
|
|
120
|
+
var entries = chain.entryPoints.entries();
|
|
121
|
+
// if prod and ssg config is true or function
|
|
122
|
+
if (isProd && ((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')) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// if single entry has ssg config
|
|
127
|
+
// `ssg: {}` is not allowed if multi entry
|
|
128
|
+
var entryNames = Object.keys(entries);
|
|
129
|
+
if (isProd && entryNames.length === 1 && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// collect all ssg entries
|
|
134
|
+
var ssgEntries = [];
|
|
135
|
+
if (isProd && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
|
|
136
|
+
var ssg = outputConfig.ssg;
|
|
137
|
+
entryNames.forEach(function (name) {
|
|
138
|
+
if (ssg[name]) {
|
|
139
|
+
ssgEntries.push(name);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
var _ref2 = serverConfig || {},
|
|
144
|
+
ssr = _ref2.ssr,
|
|
145
|
+
ssrByEntries = _ref2.ssrByEntries;
|
|
146
|
+
entryNames.forEach(function (name) {
|
|
147
|
+
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries !== null && ssrByEntries !== void 0 && ssrByEntries[name]))) {
|
|
148
|
+
chain.entryPoints["delete"](name);
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* inject bottom template
|
|
156
|
+
*/
|
|
157
|
+
function applyBottomHtmlWebpackPlugin(_ref3) {
|
|
158
|
+
var api = _ref3.api,
|
|
159
|
+
chain = _ref3.chain,
|
|
160
|
+
modernConfig = _ref3.modernConfig,
|
|
161
|
+
appContext = _ref3.appContext,
|
|
162
|
+
CHAIN_ID = _ref3.CHAIN_ID;
|
|
163
|
+
var _loop = function _loop() {
|
|
164
|
+
var entryName = _Object$keys[_i2];
|
|
165
|
+
// FIXME: the only need necessary
|
|
166
|
+
var baseTemplateParams = _objectSpread({
|
|
167
|
+
entryName: entryName,
|
|
168
|
+
title: getEntryOptions(entryName, modernConfig.output.title, modernConfig.output.titleByEntries, appContext.packageName),
|
|
169
|
+
mountId: modernConfig.output.mountId
|
|
170
|
+
}, getEntryOptions(entryName, modernConfig.output.templateParameters, modernConfig.output.templateParametersByEntries, appContext.packageName));
|
|
171
|
+
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function (args) {
|
|
172
|
+
return [_objectSpread(_objectSpread({}, args[0] || {}), {}, {
|
|
173
|
+
__internal__: true,
|
|
174
|
+
bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
|
|
175
|
+
})];
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
// inject bottomTemplate into html-webpack-plugin
|
|
179
|
+
for (var _i2 = 0, _Object$keys = Object.keys(api.context.entry); _i2 < _Object$keys.length; _i2++) {
|
|
180
|
+
_loop();
|
|
181
|
+
}
|
|
182
|
+
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
|
|
183
|
+
}
|
|
184
|
+
var isStreamingSSR = function isStreamingSSR(userConfig) {
|
|
185
|
+
var isStreaming = function isStreaming(ssr) {
|
|
186
|
+
return ssr && _typeof(ssr) === 'object' && ssr.mode === 'stream';
|
|
187
|
+
};
|
|
188
|
+
var server = userConfig.server;
|
|
189
|
+
if (isStreaming(server.ssr)) {
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Since we cannot apply different plugins for different entries,
|
|
194
|
+
// we regard the whole app as streaming ssr only if one entry meets the requirement.
|
|
195
|
+
if (server !== null && server !== void 0 && server.ssrByEntries && _typeof(server.ssrByEntries) === 'object') {
|
|
196
|
+
for (var _i3 = 0, _Object$keys2 = Object.keys(server.ssrByEntries); _i3 < _Object$keys2.length; _i3++) {
|
|
197
|
+
var name = _Object$keys2[_i3];
|
|
198
|
+
if (isStreaming(server.ssrByEntries[name])) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return false;
|
|
204
|
+
};
|
|
205
|
+
function applyAsyncChunkHtmlPlugin(_ref4) {
|
|
206
|
+
var chain = _ref4.chain,
|
|
207
|
+
modernConfig = _ref4.modernConfig,
|
|
208
|
+
CHAIN_ID = _ref4.CHAIN_ID;
|
|
209
|
+
if (isStreamingSSR(modernConfig)) {
|
|
210
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
|
|
211
|
+
}
|
|
212
|
+
}
|