@modern-js/app-tools 2.0.0-beta.3 → 2.0.0-beta.4
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 +305 -0
- package/bin/modern.js +1 -0
- package/dist/js/modern/analyze/Builder.js +39 -0
- package/dist/js/modern/analyze/constants.js +38 -18
- package/dist/js/modern/analyze/generateCode.js +262 -221
- package/dist/js/modern/analyze/getBundleEntry.js +34 -32
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +93 -49
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
- package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
- package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
- package/dist/js/modern/analyze/getFileSystemEntry.js +43 -22
- package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
- package/dist/js/modern/analyze/getServerRoutes.js +122 -126
- package/dist/js/modern/analyze/index.js +201 -160
- package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
- package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
- package/dist/js/modern/analyze/nestedRoutes.js +106 -60
- package/dist/js/modern/analyze/templates.js +163 -81
- package/dist/js/modern/analyze/utils.js +87 -66
- package/dist/js/modern/builder/builderPlugins/compatModern.js +122 -109
- package/dist/js/modern/builder/index.js +123 -86
- package/dist/js/modern/builder/loaders/routerLoader.js +9 -12
- package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -1
- package/dist/js/modern/builder/share.js +23 -21
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +100 -84
- package/dist/js/modern/commands/build.js +67 -42
- package/dist/js/modern/commands/deploy.js +27 -4
- package/dist/js/modern/commands/dev.js +77 -27
- package/dist/js/modern/commands/index.js +1 -1
- package/dist/js/modern/commands/inspect.js +30 -5
- package/dist/js/modern/commands/start.js +37 -15
- package/dist/js/modern/config/default.js +103 -113
- package/dist/js/modern/config/index.js +8 -2
- package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
- package/dist/js/modern/config/initial/createOutputConfig.js +9 -10
- package/dist/js/modern/config/initial/createSourceConfig.js +5 -2
- package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
- package/dist/js/modern/config/initial/index.js +9 -4
- package/dist/js/modern/config/initial/inits.js +109 -73
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +6 -3
- package/dist/js/modern/defineConfig.js +26 -11
- package/dist/js/modern/exports/server.js +4 -1
- package/dist/js/modern/hooks.js +15 -4
- package/dist/js/modern/index.js +178 -90
- package/dist/js/modern/initialize/index.js +98 -51
- package/dist/js/modern/locale/en.js +20 -21
- package/dist/js/modern/locale/index.js +6 -6
- package/dist/js/modern/locale/zh.js +21 -22
- package/dist/js/modern/schema/Schema.js +6 -5
- package/dist/js/modern/schema/index.js +51 -100
- package/dist/js/modern/schema/legacy.js +96 -231
- package/dist/js/modern/types/config/index.js +0 -1
- package/dist/js/modern/types/index.js +0 -1
- package/dist/js/modern/types/legacyConfig/output.js +0 -1
- package/dist/js/modern/utils/commands.js +5 -2
- package/dist/js/modern/utils/config.js +102 -41
- package/dist/js/modern/utils/createFileWatcher.js +84 -51
- package/dist/js/modern/utils/createServer.js +63 -17
- package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
- package/dist/js/modern/utils/language.js +6 -3
- package/dist/js/modern/utils/printInstructions.js +27 -8
- package/dist/js/modern/utils/restart.js +43 -16
- package/dist/js/modern/utils/routes.js +29 -12
- package/dist/js/node/analyze/Builder.js +58 -0
- package/dist/js/node/analyze/constants.js +54 -39
- package/dist/js/node/analyze/generateCode.js +282 -239
- package/dist/js/node/analyze/getBundleEntry.js +58 -44
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +132 -76
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +128 -74
- package/dist/js/node/analyze/getClientRoutes/index.js +23 -17
- package/dist/js/node/analyze/getClientRoutes/utils.js +44 -21
- package/dist/js/node/analyze/getFileSystemEntry.js +70 -39
- package/dist/js/node/analyze/getHtmlTemplate.js +116 -61
- package/dist/js/node/analyze/getServerRoutes.js +143 -137
- package/dist/js/node/analyze/index.js +247 -174
- package/dist/js/node/analyze/isDefaultExportFunction.js +55 -26
- package/dist/js/node/analyze/makeLegalIdentifier.js +27 -15
- package/dist/js/node/analyze/nestedRoutes.js +137 -75
- package/dist/js/node/analyze/templates.js +185 -90
- package/dist/js/node/analyze/utils.js +114 -81
- package/dist/js/node/builder/builderPlugins/compatModern.js +150 -122
- package/dist/js/node/builder/index.js +151 -95
- package/dist/js/node/builder/loaders/routerLoader.js +27 -18
- package/dist/js/node/builder/loaders/serverModuleLoader.js +22 -7
- package/dist/js/node/builder/share.js +46 -26
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +39 -26
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +47 -31
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +118 -90
- package/dist/js/node/commands/build.js +89 -52
- package/dist/js/node/commands/deploy.js +45 -10
- package/dist/js/node/commands/dev.js +99 -41
- package/dist/js/node/commands/index.js +19 -38
- package/dist/js/node/commands/inspect.js +48 -11
- package/dist/js/node/commands/start.js +65 -26
- package/dist/js/node/config/default.js +119 -117
- package/dist/js/node/config/index.js +25 -29
- package/dist/js/node/config/initial/createHtmlConfig.js +22 -6
- package/dist/js/node/config/initial/createOutputConfig.js +26 -14
- package/dist/js/node/config/initial/createSourceConfig.js +22 -6
- package/dist/js/node/config/initial/createToolsConfig.js +24 -10
- package/dist/js/node/config/initial/index.js +28 -17
- package/dist/js/node/config/initial/inits.js +126 -81
- package/dist/js/node/config/initial/transformNormalizedConfig.js +31 -15
- package/dist/js/node/defineConfig.js +43 -17
- package/dist/js/node/exports/server.js +21 -10
- package/dist/js/node/hooks.js +48 -29
- package/dist/js/node/index.js +225 -128
- package/dist/js/node/initialize/index.js +116 -61
- package/dist/js/node/locale/en.js +36 -25
- package/dist/js/node/locale/index.js +27 -15
- package/dist/js/node/locale/zh.js +37 -26
- package/dist/js/node/schema/Schema.js +23 -10
- package/dist/js/node/schema/index.js +77 -114
- package/dist/js/node/schema/legacy.js +117 -240
- package/dist/js/node/types/config/index.js +17 -16
- package/dist/js/node/types/index.js +19 -38
- package/dist/js/node/types/legacyConfig/output.js +0 -5
- package/dist/js/node/utils/commands.js +21 -6
- package/dist/js/node/utils/config.js +120 -51
- package/dist/js/node/utils/createFileWatcher.js +104 -61
- package/dist/js/node/utils/createServer.js +86 -25
- package/dist/js/node/utils/getSpecifiedEntries.js +64 -25
- package/dist/js/node/utils/language.js +24 -8
- package/dist/js/node/utils/printInstructions.js +47 -16
- package/dist/js/node/utils/restart.js +61 -21
- package/dist/js/node/utils/routes.js +53 -18
- package/dist/js/treeshaking/analyze/Builder.js +199 -0
- package/dist/js/treeshaking/analyze/constants.js +28 -18
- package/dist/js/treeshaking/analyze/generateCode.js +600 -406
- package/dist/js/treeshaking/analyze/getBundleEntry.js +55 -63
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +214 -168
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +89 -86
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
- package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -147
- package/dist/js/treeshaking/analyze/index.js +571 -304
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
- package/dist/js/treeshaking/analyze/nestedRoutes.js +411 -200
- package/dist/js/treeshaking/analyze/templates.js +433 -236
- package/dist/js/treeshaking/analyze/utils.js +358 -153
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +282 -200
- package/dist/js/treeshaking/builder/index.js +371 -165
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +11 -12
- package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +3 -2
- package/dist/js/treeshaking/builder/share.js +38 -44
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +334 -112
- package/dist/js/treeshaking/commands/build.js +286 -88
- package/dist/js/treeshaking/commands/deploy.js +153 -25
- package/dist/js/treeshaking/commands/dev.js +318 -131
- package/dist/js/treeshaking/commands/index.js +1 -1
- package/dist/js/treeshaking/commands/inspect.js +147 -32
- package/dist/js/treeshaking/commands/start.js +190 -67
- package/dist/js/treeshaking/config/default.js +210 -198
- package/dist/js/treeshaking/config/index.js +3 -2
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +43 -70
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +37 -40
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
- package/dist/js/treeshaking/config/initial/index.js +10 -9
- package/dist/js/treeshaking/config/initial/inits.js +205 -106
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +27 -34
- package/dist/js/treeshaking/defineConfig.js +60 -13
- package/dist/js/treeshaking/exports/server.js +2 -1
- package/dist/js/treeshaking/hooks.js +30 -25
- package/dist/js/treeshaking/index.js +681 -256
- package/dist/js/treeshaking/initialize/index.js +290 -112
- package/dist/js/treeshaking/locale/en.js +34 -33
- package/dist/js/treeshaking/locale/index.js +5 -5
- package/dist/js/treeshaking/locale/zh.js +34 -33
- package/dist/js/treeshaking/schema/Schema.js +267 -69
- package/dist/js/treeshaking/schema/index.js +165 -121
- package/dist/js/treeshaking/schema/legacy.js +323 -256
- package/dist/js/treeshaking/types/config/deploy.js +1 -0
- package/dist/js/treeshaking/types/config/dev.js +1 -0
- package/dist/js/treeshaking/types/config/experiments.js +1 -0
- package/dist/js/treeshaking/types/config/html.js +1 -0
- package/dist/js/treeshaking/types/config/index.js +0 -1
- package/dist/js/treeshaking/types/config/output.js +1 -0
- package/dist/js/treeshaking/types/config/performance.js +1 -0
- package/dist/js/treeshaking/types/config/security.js +1 -0
- package/dist/js/treeshaking/types/config/source.js +1 -0
- package/dist/js/treeshaking/types/config/tools.js +1 -0
- package/dist/js/treeshaking/types/hooks.js +1 -0
- package/dist/js/treeshaking/types/index.js +0 -1
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -1
- package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
- package/dist/js/treeshaking/utils/commands.js +6 -5
- package/dist/js/treeshaking/utils/config.js +295 -117
- package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
- package/dist/js/treeshaking/utils/createServer.js +252 -67
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
- package/dist/js/treeshaking/utils/language.js +6 -5
- package/dist/js/treeshaking/utils/printInstructions.js +151 -29
- package/dist/js/treeshaking/utils/restart.js +184 -42
- package/dist/js/treeshaking/utils/routes.js +151 -27
- package/dist/js/treeshaking/utils/types.js +1 -0
- package/dist/types/analyze/Builder.d.ts +8 -0
- package/dist/types/analyze/index.d.ts +2 -0
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
- package/dist/types/builder/index.d.ts +3 -3
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
- package/dist/types/defineConfig.d.ts +1 -0
- package/dist/types/index.d.ts +6 -1
- package/dist/types/initialize/index.d.ts +2 -0
- package/dist/types/types/config/dev.d.ts +2 -2
- package/dist/types/types/config/index.d.ts +1 -0
- package/dist/types/types/config/output.d.ts +0 -1
- package/dist/types/types/config/source.d.ts +1 -0
- package/dist/types/types/config/tools.d.ts +2 -0
- package/dist/types/types/hooks.d.ts +5 -0
- package/dist/types/types/legacyConfig/dev.d.ts +1 -0
- package/dist/types/types/legacyConfig/output.d.ts +1 -1
- package/dist/types/types/legacyConfig/source.d.ts +1 -0
- package/dist/types/types/legacyConfig/tools.d.ts +1 -0
- package/dist/types/utils/config.d.ts +1 -0
- package/dist/types/utils/createServer.d.ts +1 -0
- package/dist/types/utils/restart.d.ts +1 -1
- package/package.json +23 -22
|
@@ -1,218 +1,300 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
function _arrayLikeToArray(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
+
return arr2;
|
|
5
|
+
}
|
|
6
|
+
function _arrayWithoutHoles(arr) {
|
|
7
|
+
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
|
8
|
+
}
|
|
9
|
+
function _defineProperty(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
22
|
+
function _iterableToArray(iter) {
|
|
23
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
24
|
+
}
|
|
25
|
+
function _nonIterableSpread() {
|
|
26
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
27
|
+
}
|
|
28
|
+
function _objectSpread(target) {
|
|
29
|
+
for(var i = 1; i < arguments.length; i++){
|
|
30
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
31
|
+
var ownKeys = Object.keys(source);
|
|
32
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
33
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
34
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
37
|
+
ownKeys.forEach(function(key) {
|
|
38
|
+
_defineProperty(target, key, source[key]);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return target;
|
|
42
|
+
}
|
|
43
|
+
function ownKeys(object, enumerableOnly) {
|
|
44
|
+
var keys = Object.keys(object);
|
|
45
|
+
if (Object.getOwnPropertySymbols) {
|
|
46
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
47
|
+
if (enumerableOnly) {
|
|
48
|
+
symbols = symbols.filter(function(sym) {
|
|
49
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
keys.push.apply(keys, symbols);
|
|
53
|
+
}
|
|
54
|
+
return keys;
|
|
55
|
+
}
|
|
56
|
+
function _objectSpreadProps(target, source) {
|
|
57
|
+
source = source != null ? source : {};
|
|
58
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
59
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
60
|
+
} else {
|
|
61
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
62
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
function _toConsumableArray(arr) {
|
|
68
|
+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
|
69
|
+
}
|
|
70
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
71
|
+
if (!o) return;
|
|
72
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
73
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
74
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
75
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
76
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
77
|
+
}
|
|
78
|
+
import { join } from "path";
|
|
79
|
+
import { mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
80
|
+
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
81
|
+
import HtmlWebpackPlugin from "@modern-js/builder-webpack-provider/html-webpack-plugin";
|
|
82
|
+
import { getEntryOptions } from "@modern-js/utils";
|
|
9
83
|
import { BottomTemplatePlugin } from "../webpackPlugins/htmlBottomTemplate";
|
|
10
84
|
import { HtmlAsyncChunkPlugin } from "../webpackPlugins/htmlAsyncChunkPlugin";
|
|
11
85
|
import { createCopyPattern } from "../share";
|
|
12
86
|
import RouterPlugin from "../webpackPlugins/routerPlugin";
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
87
|
+
var PluginCompatModern = function(appContext, modernConfig, options) {
|
|
88
|
+
return {
|
|
89
|
+
name: "builder-plugin-compat-modern",
|
|
90
|
+
setup: function setup(api) {
|
|
91
|
+
api.modifyBuilderConfig(function(config) {
|
|
92
|
+
if (isStreamingSSR(modernConfig)) {
|
|
93
|
+
return mergeBuilderConfig(config, {
|
|
94
|
+
html: {
|
|
95
|
+
inject: "body"
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
return config;
|
|
100
|
+
});
|
|
101
|
+
api.modifyWebpackChain(function(chain, param) {
|
|
102
|
+
var target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd;
|
|
103
|
+
var isHtmlEnabled = function isHtmlEnabled(config, target2) {
|
|
104
|
+
var ref;
|
|
105
|
+
return ((ref = config.tools) === null || ref === void 0 ? void 0 : ref.htmlPlugin) !== false && target2 !== "node" && target2 !== "web-worker";
|
|
106
|
+
};
|
|
107
|
+
var ref, ref1;
|
|
108
|
+
var builderNormalizedConfig = api.getNormalizedConfig();
|
|
109
|
+
if (target === "node") {
|
|
110
|
+
chain.name("server");
|
|
111
|
+
} else if (target === "modern-web") {
|
|
112
|
+
chain.name("modern");
|
|
113
|
+
} else {
|
|
114
|
+
chain.name("client");
|
|
115
|
+
}
|
|
116
|
+
chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
|
|
117
|
+
if (target === "node") {
|
|
118
|
+
applyNodeCompat(chain, modernConfig, isProd);
|
|
119
|
+
}
|
|
120
|
+
if (isHtmlEnabled(builderNormalizedConfig, target)) {
|
|
121
|
+
applyBottomHtmlWebpackPlugin({
|
|
122
|
+
api: api,
|
|
123
|
+
chain: chain,
|
|
124
|
+
CHAIN_ID: CHAIN_ID,
|
|
125
|
+
appContext: appContext,
|
|
126
|
+
modernConfig: modernConfig
|
|
127
|
+
});
|
|
128
|
+
applyAsyncChunkHtmlPlugin({
|
|
129
|
+
chain: chain,
|
|
130
|
+
CHAIN_ID: CHAIN_ID,
|
|
131
|
+
modernConfig: modernConfig
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
135
|
+
var defaultCopyPattern = createCopyPattern(appContext, modernConfig, "public", chain);
|
|
136
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(function(args) {
|
|
137
|
+
var ref;
|
|
138
|
+
return [
|
|
139
|
+
{
|
|
140
|
+
patterns: _toConsumableArray(((ref = args[0]) === null || ref === void 0 ? void 0 : ref.patterns) || []).concat([
|
|
141
|
+
defaultCopyPattern
|
|
142
|
+
])
|
|
143
|
+
}
|
|
144
|
+
];
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
var entrypoints = appContext.entrypoints;
|
|
148
|
+
var existNestedRoutes = entrypoints.some(function(entrypoint) {
|
|
149
|
+
return entrypoint.nestedRoutesEntry;
|
|
150
|
+
});
|
|
151
|
+
var routerManifest = Boolean(modernConfig === null || modernConfig === void 0 ? void 0 : (ref = modernConfig.runtime) === null || ref === void 0 ? void 0 : (ref1 = ref.router) === null || ref1 === void 0 ? void 0 : ref1.manifest);
|
|
152
|
+
if (existNestedRoutes || routerManifest) {
|
|
153
|
+
chain.plugin("route-plugin").use(RouterPlugin);
|
|
154
|
+
}
|
|
155
|
+
if (target !== "node") {
|
|
156
|
+
var bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
157
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
158
|
+
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
if (options) {
|
|
162
|
+
applyCallbacks(api, options);
|
|
25
163
|
}
|
|
26
|
-
});
|
|
27
164
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (target === 'node') {
|
|
47
|
-
applyNodeCompat(chain, modernConfig, isProd);
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
function applyCallbacks(api, options) {
|
|
168
|
+
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
169
|
+
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
170
|
+
options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
|
|
171
|
+
options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
|
|
172
|
+
options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
|
|
173
|
+
options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
|
|
174
|
+
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
175
|
+
options.onExit && api.onExit(options.onExit);
|
|
176
|
+
}
|
|
177
|
+
function applyNodeCompat(chain, modernConfig, isProd) {
|
|
178
|
+
var filterEntriesBySSRConfig = function filterEntriesBySSRConfig(isProd2, chain2, serverConfig, outputConfig) {
|
|
179
|
+
var ref;
|
|
180
|
+
var entries = chain2.entryPoints.entries();
|
|
181
|
+
if (isProd2 && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof (outputConfig === null || outputConfig === void 0 ? void 0 : (ref = outputConfig.ssg) === null || ref === void 0 ? void 0 : ref[0]) === "function")) {
|
|
182
|
+
return;
|
|
48
183
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
});
|
|
184
|
+
var entryNames = Object.keys(entries);
|
|
185
|
+
if (isProd2 && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
|
186
|
+
return;
|
|
62
187
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}];
|
|
72
|
-
});
|
|
188
|
+
var ssgEntries = [];
|
|
189
|
+
if (isProd2 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
|
190
|
+
var ssg = outputConfig.ssg;
|
|
191
|
+
entryNames.forEach(function(name) {
|
|
192
|
+
if (ssg[name]) {
|
|
193
|
+
ssgEntries.push(name);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
73
196
|
}
|
|
74
|
-
var
|
|
75
|
-
|
|
76
|
-
|
|
197
|
+
var ref1 = serverConfig || {}, ssr = ref1.ssr, ssrByEntries = ref1.ssrByEntries;
|
|
198
|
+
entryNames.forEach(function(name) {
|
|
199
|
+
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]))) {
|
|
200
|
+
chain2.entryPoints.delete(name);
|
|
201
|
+
}
|
|
77
202
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (options) {
|
|
92
|
-
applyCallbacks(api, options);
|
|
93
|
-
}
|
|
203
|
+
};
|
|
204
|
+
for(var _i = 0, _iter = [
|
|
205
|
+
".node.js",
|
|
206
|
+
".node.jsx",
|
|
207
|
+
".node.ts",
|
|
208
|
+
".node.tsx",
|
|
209
|
+
".server.js",
|
|
210
|
+
".server.ts",
|
|
211
|
+
".server.ts",
|
|
212
|
+
".server.tsx"
|
|
213
|
+
]; _i < _iter.length; _i++){
|
|
214
|
+
var ext = _iter[_i];
|
|
215
|
+
chain.resolve.extensions.prepend(ext);
|
|
94
216
|
}
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* register builder hooks callback
|
|
100
|
-
*/
|
|
101
|
-
function applyCallbacks(api, options) {
|
|
102
|
-
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
103
|
-
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
104
|
-
options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
|
|
105
|
-
options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
|
|
106
|
-
options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
|
|
107
|
-
options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
|
|
108
|
-
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
109
|
-
options.onExit && api.onExit(options.onExit);
|
|
217
|
+
filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
|
|
110
218
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (ssg[name]) {
|
|
145
|
-
ssgEntries.push(name);
|
|
219
|
+
function applyBottomHtmlWebpackPlugin(param) {
|
|
220
|
+
var api = param.api, chain = param.chain, modernConfig = param.modernConfig, appContext = param.appContext, CHAIN_ID = param.CHAIN_ID;
|
|
221
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
222
|
+
try {
|
|
223
|
+
var _loop = function() {
|
|
224
|
+
var entryName = _step.value;
|
|
225
|
+
var baseTemplateParams = _objectSpread({
|
|
226
|
+
entryName: entryName,
|
|
227
|
+
title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
|
228
|
+
mountId: modernConfig.html.mountId
|
|
229
|
+
}, getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
|
|
230
|
+
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function(args) {
|
|
231
|
+
return [
|
|
232
|
+
_objectSpreadProps(_objectSpread({}, args[0] || {}), {
|
|
233
|
+
__internal__: true,
|
|
234
|
+
bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
|
|
235
|
+
})
|
|
236
|
+
];
|
|
237
|
+
});
|
|
238
|
+
};
|
|
239
|
+
for(var _iterator = Object.keys(api.context.entry)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
240
|
+
} catch (err) {
|
|
241
|
+
_didIteratorError = true;
|
|
242
|
+
_iteratorError = err;
|
|
243
|
+
} finally{
|
|
244
|
+
try {
|
|
245
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
246
|
+
_iterator.return();
|
|
247
|
+
}
|
|
248
|
+
} finally{
|
|
249
|
+
if (_didIteratorError) {
|
|
250
|
+
throw _iteratorError;
|
|
251
|
+
}
|
|
146
252
|
}
|
|
147
|
-
});
|
|
148
253
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
entryNames.forEach(function (name) {
|
|
153
|
-
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries !== null && ssrByEntries !== void 0 && ssrByEntries[name]))) {
|
|
154
|
-
chain.entryPoints["delete"](name);
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
}
|
|
254
|
+
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [
|
|
255
|
+
HtmlWebpackPlugin
|
|
256
|
+
]);
|
|
158
257
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
chain = _ref3.chain,
|
|
166
|
-
modernConfig = _ref3.modernConfig,
|
|
167
|
-
appContext = _ref3.appContext,
|
|
168
|
-
CHAIN_ID = _ref3.CHAIN_ID;
|
|
169
|
-
var _loop = function _loop() {
|
|
170
|
-
var entryName = _Object$keys[_i2];
|
|
171
|
-
// FIXME: the only need necessary
|
|
172
|
-
var baseTemplateParams = _objectSpread({
|
|
173
|
-
entryName: entryName,
|
|
174
|
-
title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
|
175
|
-
mountId: modernConfig.html.mountId
|
|
176
|
-
}, getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
|
|
177
|
-
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function (args) {
|
|
178
|
-
return [_objectSpread(_objectSpread({}, args[0] || {}), {}, {
|
|
179
|
-
__internal__: true,
|
|
180
|
-
bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
|
|
181
|
-
})];
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
// inject bottomTemplate into html-webpack-plugin
|
|
185
|
-
for (var _i2 = 0, _Object$keys = Object.keys(api.context.entry); _i2 < _Object$keys.length; _i2++) {
|
|
186
|
-
_loop();
|
|
187
|
-
}
|
|
188
|
-
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
|
|
189
|
-
}
|
|
190
|
-
var isStreamingSSR = function isStreamingSSR(userConfig) {
|
|
191
|
-
var isStreaming = function isStreaming(ssr) {
|
|
192
|
-
return ssr && _typeof(ssr) === 'object' && ssr.mode === 'stream';
|
|
193
|
-
};
|
|
194
|
-
var server = userConfig.server;
|
|
195
|
-
if (isStreaming(server.ssr)) {
|
|
196
|
-
return true;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Since we cannot apply different plugins for different entries,
|
|
200
|
-
// we regard the whole app as streaming ssr only if one entry meets the requirement.
|
|
201
|
-
if (server !== null && server !== void 0 && server.ssrByEntries && _typeof(server.ssrByEntries) === 'object') {
|
|
202
|
-
for (var _i3 = 0, _Object$keys2 = Object.keys(server.ssrByEntries); _i3 < _Object$keys2.length; _i3++) {
|
|
203
|
-
var name = _Object$keys2[_i3];
|
|
204
|
-
if (isStreaming(server.ssrByEntries[name])) {
|
|
258
|
+
var isStreamingSSR = function(userConfig) {
|
|
259
|
+
var isStreaming = function(ssr) {
|
|
260
|
+
return ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
261
|
+
};
|
|
262
|
+
var server = userConfig.server;
|
|
263
|
+
if (isStreaming(server.ssr)) {
|
|
205
264
|
return true;
|
|
206
|
-
}
|
|
207
265
|
}
|
|
208
|
-
|
|
209
|
-
|
|
266
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
267
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
268
|
+
try {
|
|
269
|
+
for(var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
270
|
+
var name = _step.value;
|
|
271
|
+
if (isStreaming(server.ssrByEntries[name])) {
|
|
272
|
+
return true;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} catch (err) {
|
|
276
|
+
_didIteratorError = true;
|
|
277
|
+
_iteratorError = err;
|
|
278
|
+
} finally{
|
|
279
|
+
try {
|
|
280
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
281
|
+
_iterator.return();
|
|
282
|
+
}
|
|
283
|
+
} finally{
|
|
284
|
+
if (_didIteratorError) {
|
|
285
|
+
throw _iteratorError;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return false;
|
|
210
291
|
};
|
|
211
|
-
function applyAsyncChunkHtmlPlugin(
|
|
212
|
-
|
|
213
|
-
modernConfig
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
292
|
+
function applyAsyncChunkHtmlPlugin(param) {
|
|
293
|
+
var chain = param.chain, modernConfig = param.modernConfig, CHAIN_ID = param.CHAIN_ID;
|
|
294
|
+
if (isStreamingSSR(modernConfig)) {
|
|
295
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [
|
|
296
|
+
HtmlWebpackPlugin
|
|
297
|
+
]);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
export { PluginCompatModern };
|