@modern-js/app-tools 2.5.1-alpha.0 → 2.5.1-alpha.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/dist/cjs/analyze/generateCode.js +19 -13
- package/dist/cjs/analyze/getBundleEntry.js +1 -1
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +3 -3
- package/dist/cjs/builder/builder-webpack/index.js +11 -5
- package/dist/cjs/builder/generator/getBuilderTargets.js +1 -1
- package/dist/cjs/commands/dev.js +12 -14
- package/dist/cjs/commands/serve.js +17 -0
- package/dist/cjs/config/legacy/createToolsConfig.js +1 -4
- package/dist/esm/analyze/generateCode.js +37 -26
- package/dist/esm/analyze/getBundleEntry.js +2 -2
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
- package/dist/esm/builder/builder-webpack/index.js +11 -7
- package/dist/esm/builder/generator/getBuilderTargets.js +1 -1
- package/dist/esm/commands/dev.js +9 -8
- package/dist/esm/commands/serve.js +6 -1
- package/dist/esm/config/legacy/createToolsConfig.js +1 -4
- package/dist/esm-node/analyze/generateCode.js +20 -14
- package/dist/esm-node/analyze/getBundleEntry.js +2 -3
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
- package/dist/esm-node/builder/builder-webpack/index.js +12 -6
- package/dist/esm-node/builder/generator/getBuilderTargets.js +1 -1
- package/dist/esm-node/commands/dev.js +12 -14
- package/dist/esm-node/commands/serve.js +18 -1
- package/dist/esm-node/config/legacy/createToolsConfig.js +1 -4
- package/dist/js/modern/analyze/constants.js +3 -1
- package/dist/js/modern/analyze/getServerRoutes.js +5 -2
- package/dist/js/modern/analyze/index.js +47 -46
- package/dist/js/modern/analyze/nestedRoutes.js +32 -3
- package/dist/js/modern/analyze/templates.js +4 -10
- package/dist/js/modern/builder/builder-rspack/index.js +8 -0
- package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
- package/dist/js/modern/builder/builder-webpack/index.js +93 -0
- package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
- package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
- package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
- package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
- package/dist/js/modern/builder/generator/index.js +53 -0
- package/dist/js/modern/builder/index.js +13 -133
- package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
- package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
- package/dist/js/modern/builder/shared/index.js +3 -0
- package/dist/js/modern/builder/shared/types.js +0 -0
- package/dist/js/modern/config/default.js +2 -2
- package/dist/js/modern/config/index.js +3 -8
- package/dist/js/modern/config/initialize/index.js +12 -0
- package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
- package/dist/js/modern/index.js +18 -8
- package/dist/js/modern/initialize/index.js +36 -28
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/types/utils.js +0 -0
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/getServerRoutes.js +3 -1
- package/dist/js/node/analyze/index.js +48 -47
- package/dist/js/node/analyze/nestedRoutes.js +32 -3
- package/dist/js/node/analyze/templates.js +4 -10
- package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
- package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/node/builder/builder-webpack/index.js +118 -0
- package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
- package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
- package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
- package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
- package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
- package/dist/js/node/builder/generator/index.js +82 -0
- package/dist/js/node/builder/index.js +14 -123
- package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
- package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
- package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
- package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
- package/dist/js/node/builder/shared/index.js +19 -0
- package/dist/js/node/builder/shared/types.js +15 -0
- package/dist/js/node/config/default.js +2 -2
- package/dist/js/node/config/index.js +4 -19
- package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
- package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
- package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
- package/dist/js/node/index.js +18 -8
- package/dist/js/node/initialize/index.js +35 -28
- package/dist/js/node/locale/zh.js +1 -1
- package/dist/js/node/types/utils.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +3 -1
- 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 +142 -137
- package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
- package/dist/js/treeshaking/analyze/templates.js +10 -13
- package/dist/js/treeshaking/analyze/utils.js +3 -3
- package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
- package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
- package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
- package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
- package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
- package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
- package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
- package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
- package/dist/js/treeshaking/builder/generator/index.js +199 -0
- package/dist/js/treeshaking/builder/index.js +29 -228
- package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
- package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
- package/dist/js/treeshaking/builder/shared/index.js +3 -0
- package/dist/js/treeshaking/builder/shared/types.js +1 -0
- package/dist/js/treeshaking/commands/dev.js +2 -2
- package/dist/js/treeshaking/commands/serve.js +2 -2
- package/dist/js/treeshaking/config/default.js +2 -2
- package/dist/js/treeshaking/config/index.js +3 -3
- package/dist/js/treeshaking/config/initialize/index.js +10 -0
- package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
- package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
- package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
- package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
- package/dist/js/treeshaking/index.js +19 -12
- package/dist/js/treeshaking/initialize/index.js +36 -28
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/types/utils.js +1 -0
- package/dist/js/treeshaking/utils/config.js +2 -2
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
- package/dist/types/builder/builder-webpack/builderPlugins/compatModern.d.ts +7 -1
- package/package.json +6 -6
- package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
- package/dist/js/modern/config/initial/index.js +0 -16
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
- package/dist/js/treeshaking/config/initial/index.js +0 -12
- /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
- /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
- /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
- /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
- /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
|
@@ -1,11 +1,3 @@
|
|
|
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
1
|
function _defineProperty(obj, key, value) {
|
|
10
2
|
if (key in obj) {
|
|
11
3
|
Object.defineProperty(obj, key, {
|
|
@@ -19,12 +11,6 @@ function _defineProperty(obj, key, value) {
|
|
|
19
11
|
}
|
|
20
12
|
return obj;
|
|
21
13
|
}
|
|
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
14
|
function _objectSpread(target) {
|
|
29
15
|
for(var i = 1; i < arguments.length; i++){
|
|
30
16
|
var source = arguments[i] != null ? arguments[i] : {};
|
|
@@ -64,32 +50,57 @@ function _objectSpreadProps(target, source) {
|
|
|
64
50
|
}
|
|
65
51
|
return target;
|
|
66
52
|
}
|
|
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
53
|
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
54
|
import { getEntryOptions } from "@modern-js/utils";
|
|
83
|
-
import
|
|
84
|
-
import {
|
|
85
|
-
import {
|
|
86
|
-
import
|
|
87
|
-
var
|
|
55
|
+
import HtmlWebpackPlugin from "@modern-js/builder-webpack-provider/html-webpack-plugin";
|
|
56
|
+
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
57
|
+
import { HtmlAsyncChunkPlugin } from "../bundlerPlugins/HtmlAsyncChunkPlugin";
|
|
58
|
+
import { BottomTemplatePlugin } from "../bundlerPlugins/HtmlBottomTemplate";
|
|
59
|
+
var isStreamingSSR = function(userConfig) {
|
|
60
|
+
var isStreaming = function(ssr) {
|
|
61
|
+
return ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
62
|
+
};
|
|
63
|
+
var server = userConfig.server;
|
|
64
|
+
if (isStreaming(server.ssr)) {
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
68
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
69
|
+
try {
|
|
70
|
+
for(var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
71
|
+
var name = _step.value;
|
|
72
|
+
if (isStreaming(server.ssrByEntries[name])) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} catch (err) {
|
|
77
|
+
_didIteratorError = true;
|
|
78
|
+
_iteratorError = err;
|
|
79
|
+
} finally{
|
|
80
|
+
try {
|
|
81
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
82
|
+
_iterator.return();
|
|
83
|
+
}
|
|
84
|
+
} finally{
|
|
85
|
+
if (_didIteratorError) {
|
|
86
|
+
throw _iteratorError;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return false;
|
|
92
|
+
};
|
|
93
|
+
var builderPluginAdapterModern = function(options) {
|
|
88
94
|
return {
|
|
89
|
-
name: "builder-plugin-
|
|
95
|
+
name: "builder-plugin-adapter-modern",
|
|
90
96
|
setup: function setup(api) {
|
|
97
|
+
var isHtmlEnabled = function isHtmlEnabled(config, target) {
|
|
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
|
+
};
|
|
101
|
+
var normalizedConfig = options.normalizedConfig, appContext = options.appContext;
|
|
91
102
|
api.modifyBuilderConfig(function(config) {
|
|
92
|
-
if (isStreamingSSR(
|
|
103
|
+
if (isStreamingSSR(normalizedConfig)) {
|
|
93
104
|
return mergeBuilderConfig(config, {
|
|
94
105
|
html: {
|
|
95
106
|
inject: "body"
|
|
@@ -98,70 +109,44 @@ var PluginCompatModern = function(appContext, modernConfig, options) {
|
|
|
98
109
|
}
|
|
99
110
|
return config;
|
|
100
111
|
});
|
|
101
|
-
api.
|
|
112
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
102
113
|
var target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd;
|
|
103
|
-
var
|
|
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;
|
|
108
|
-
var builderNormalizedConfig = api.getNormalizedConfig();
|
|
114
|
+
var builderConfig = api.getNormalizedConfig();
|
|
109
115
|
if (target === "node") {
|
|
110
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");
|
|
111
121
|
} else if (target === "modern-web") {
|
|
112
122
|
chain.name("modern");
|
|
113
123
|
} else {
|
|
114
124
|
chain.name("client");
|
|
115
125
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
applyNodeCompat(chain, modernConfig, isProd);
|
|
126
|
+
if (target === "node" || target === "service-worker") {
|
|
127
|
+
applyNodeCompat(target, chain, normalizedConfig, isProd);
|
|
119
128
|
}
|
|
120
|
-
if (isHtmlEnabled(
|
|
121
|
-
|
|
129
|
+
if (isHtmlEnabled(builderConfig, target)) {
|
|
130
|
+
applyBottomHtmlPlugin({
|
|
122
131
|
api: api,
|
|
123
132
|
chain: chain,
|
|
124
|
-
|
|
133
|
+
modernConfig: normalizedConfig,
|
|
125
134
|
appContext: appContext,
|
|
126
|
-
|
|
135
|
+
CHAIN_ID: CHAIN_ID
|
|
127
136
|
});
|
|
128
137
|
applyAsyncChunkHtmlPlugin({
|
|
129
138
|
chain: chain,
|
|
130
|
-
|
|
131
|
-
|
|
139
|
+
modernConfig: normalizedConfig,
|
|
140
|
+
CHAIN_ID: CHAIN_ID
|
|
132
141
|
});
|
|
133
142
|
}
|
|
134
|
-
if (
|
|
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 routerConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (ref = modernConfig.runtime) === null || ref === void 0 ? void 0 : ref.router;
|
|
152
|
-
var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
|
153
|
-
if (existNestedRoutes || routerManifest) {
|
|
154
|
-
chain.plugin("route-plugin").use(RouterPlugin);
|
|
155
|
-
}
|
|
156
|
-
if (target !== "node") {
|
|
143
|
+
if (target !== "node" && target !== "web-worker" && target !== "service-worker") {
|
|
157
144
|
var bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
158
145
|
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
159
146
|
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
160
147
|
}
|
|
161
148
|
});
|
|
162
|
-
|
|
163
|
-
applyCallbacks(api, options);
|
|
164
|
-
}
|
|
149
|
+
applyCallbacks(api, options);
|
|
165
150
|
}
|
|
166
151
|
};
|
|
167
152
|
};
|
|
@@ -175,11 +160,58 @@ function applyCallbacks(api, options) {
|
|
|
175
160
|
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
176
161
|
options.onExit && api.onExit(options.onExit);
|
|
177
162
|
}
|
|
178
|
-
function
|
|
163
|
+
function applyBottomHtmlPlugin(param) {
|
|
164
|
+
var api = param.api, chain = param.chain, modernConfig = param.modernConfig, appContext = param.appContext, CHAIN_ID = param.CHAIN_ID;
|
|
165
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
166
|
+
try {
|
|
167
|
+
var _loop = function() {
|
|
168
|
+
var entryName = _step.value;
|
|
169
|
+
var baseTemplateParams = _objectSpread({
|
|
170
|
+
entryName: entryName,
|
|
171
|
+
title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
|
172
|
+
mountId: modernConfig.html.mountId
|
|
173
|
+
}, getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
|
|
174
|
+
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function(args) {
|
|
175
|
+
return [
|
|
176
|
+
_objectSpreadProps(_objectSpread({}, args[0] || {}), {
|
|
177
|
+
__internal__: true,
|
|
178
|
+
bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
|
|
179
|
+
})
|
|
180
|
+
];
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
for(var _iterator = Object.keys(api.context.entry)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
184
|
+
} catch (err) {
|
|
185
|
+
_didIteratorError = true;
|
|
186
|
+
_iteratorError = err;
|
|
187
|
+
} finally{
|
|
188
|
+
try {
|
|
189
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
190
|
+
_iterator.return();
|
|
191
|
+
}
|
|
192
|
+
} finally{
|
|
193
|
+
if (_didIteratorError) {
|
|
194
|
+
throw _iteratorError;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [
|
|
199
|
+
HtmlWebpackPlugin
|
|
200
|
+
]);
|
|
201
|
+
}
|
|
202
|
+
function applyAsyncChunkHtmlPlugin(param) {
|
|
203
|
+
var chain = param.chain, modernConfig = param.modernConfig, CHAIN_ID = param.CHAIN_ID;
|
|
204
|
+
if (isStreamingSSR(modernConfig)) {
|
|
205
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [
|
|
206
|
+
HtmlWebpackPlugin
|
|
207
|
+
]);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
function applyNodeCompat(target, chain, modernConfig, isProd) {
|
|
179
211
|
var filterEntriesBySSRConfig = function filterEntriesBySSRConfig(isProd2, chain2, serverConfig, outputConfig) {
|
|
180
|
-
var
|
|
212
|
+
var _outputConfig_ssg;
|
|
181
213
|
var entries = chain2.entryPoints.entries();
|
|
182
|
-
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")) {
|
|
183
215
|
return;
|
|
184
216
|
}
|
|
185
217
|
if (typeof entries === "undefined") {
|
|
@@ -198,14 +230,14 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
198
230
|
}
|
|
199
231
|
});
|
|
200
232
|
}
|
|
201
|
-
var
|
|
233
|
+
var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
|
|
202
234
|
entryNames.forEach(function(name) {
|
|
203
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]))) {
|
|
204
236
|
chain2.entryPoints.delete(name);
|
|
205
237
|
}
|
|
206
238
|
});
|
|
207
239
|
};
|
|
208
|
-
|
|
240
|
+
var nodeExts = [
|
|
209
241
|
".node.js",
|
|
210
242
|
".node.jsx",
|
|
211
243
|
".node.ts",
|
|
@@ -214,33 +246,19 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
214
246
|
".server.ts",
|
|
215
247
|
".server.ts",
|
|
216
248
|
".server.tsx"
|
|
217
|
-
];
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
var api = param.api, chain = param.chain, modernConfig = param.modernConfig, appContext = param.appContext, CHAIN_ID = param.CHAIN_ID;
|
|
249
|
+
];
|
|
250
|
+
var webWorkerExts = [
|
|
251
|
+
".worker.js",
|
|
252
|
+
".worker.jsx",
|
|
253
|
+
".worker.ts",
|
|
254
|
+
".worker.tsx"
|
|
255
|
+
];
|
|
225
256
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
226
257
|
try {
|
|
227
|
-
var
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
|
232
|
-
mountId: modernConfig.html.mountId
|
|
233
|
-
}, getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
|
|
234
|
-
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function(args) {
|
|
235
|
-
return [
|
|
236
|
-
_objectSpreadProps(_objectSpread({}, args[0] || {}), {
|
|
237
|
-
__internal__: true,
|
|
238
|
-
bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
|
|
239
|
-
})
|
|
240
|
-
];
|
|
241
|
-
});
|
|
242
|
-
};
|
|
243
|
-
for(var _iterator = Object.keys(api.context.entry)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
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
|
+
}
|
|
244
262
|
} catch (err) {
|
|
245
263
|
_didIteratorError = true;
|
|
246
264
|
_iteratorError = err;
|
|
@@ -255,50 +273,28 @@ function applyBottomHtmlWebpackPlugin(param) {
|
|
|
255
273
|
}
|
|
256
274
|
}
|
|
257
275
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
]);
|
|
261
|
-
}
|
|
262
|
-
var isStreamingSSR = function(userConfig) {
|
|
263
|
-
var isStreaming = function(ssr) {
|
|
264
|
-
return ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
265
|
-
};
|
|
266
|
-
var server = userConfig.server;
|
|
267
|
-
if (isStreaming(server.ssr)) {
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
271
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
276
|
+
if (target === "service-worker") {
|
|
277
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
272
278
|
try {
|
|
273
|
-
for(var
|
|
274
|
-
var
|
|
275
|
-
|
|
276
|
-
return true;
|
|
277
|
-
}
|
|
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);
|
|
278
282
|
}
|
|
279
283
|
} catch (err) {
|
|
280
|
-
|
|
281
|
-
|
|
284
|
+
_didIteratorError1 = true;
|
|
285
|
+
_iteratorError1 = err;
|
|
282
286
|
} finally{
|
|
283
287
|
try {
|
|
284
|
-
if (!
|
|
285
|
-
|
|
288
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
289
|
+
_iterator1.return();
|
|
286
290
|
}
|
|
287
291
|
} finally{
|
|
288
|
-
if (
|
|
289
|
-
throw
|
|
292
|
+
if (_didIteratorError1) {
|
|
293
|
+
throw _iteratorError1;
|
|
290
294
|
}
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
297
|
}
|
|
294
|
-
|
|
295
|
-
};
|
|
296
|
-
function applyAsyncChunkHtmlPlugin(param) {
|
|
297
|
-
var chain = param.chain, modernConfig = param.modernConfig, CHAIN_ID = param.CHAIN_ID;
|
|
298
|
-
if (isStreamingSSR(modernConfig)) {
|
|
299
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [
|
|
300
|
-
HtmlWebpackPlugin
|
|
301
|
-
]);
|
|
302
|
-
}
|
|
298
|
+
filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
|
|
303
299
|
}
|
|
304
|
-
export {
|
|
300
|
+
export { applyCallbacks, builderPluginAdapterModern };
|
|
@@ -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)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -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();
|
|
@@ -51,12 +51,11 @@ function _objectSpreadProps(target, source) {
|
|
|
51
51
|
return target;
|
|
52
52
|
}
|
|
53
53
|
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
54
|
-
function createDefaultConfig(appContext) {
|
|
54
|
+
function createDefaultConfig(appContext, bundler) {
|
|
55
55
|
var defaultBuilderConfig = createDefaultBuilderConfig();
|
|
56
56
|
var dev = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.dev), {
|
|
57
57
|
port: void 0
|
|
58
58
|
});
|
|
59
|
-
var tools = _objectSpread({}, defaultBuilderConfig.tools);
|
|
60
59
|
var output = _objectSpreadProps(_objectSpread({}, defaultBuilderConfig.output), {
|
|
61
60
|
disableNodePolyfill: true
|
|
62
61
|
});
|
|
@@ -95,6 +94,7 @@ function createDefaultConfig(appContext) {
|
|
|
95
94
|
baseUrl: "/",
|
|
96
95
|
port: 8080
|
|
97
96
|
};
|
|
97
|
+
var tools = bundler === "webpack" ? _objectSpread({}, defaultBuilderConfig.tools) : void 0;
|
|
98
98
|
return {
|
|
99
99
|
source: source,
|
|
100
100
|
output: output,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
export * from "./legacy";
|
|
2
|
+
export * from "./initialize";
|
|
3
|
+
export * from "./default";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { initHtmlConfig, initSourceConfig, initToolsConfig } from "./inits";
|
|
2
|
+
function initialNormalizedConfig(config, appContext, bundler) {
|
|
3
|
+
initHtmlConfig(config, appContext);
|
|
4
|
+
initSourceConfig(config, appContext, bundler);
|
|
5
|
+
if (bundler === "webpack") {
|
|
6
|
+
initToolsConfig(config);
|
|
7
|
+
}
|
|
8
|
+
return config;
|
|
9
|
+
}
|
|
10
|
+
export { initialNormalizedConfig };
|
|
@@ -105,9 +105,9 @@ function initHtmlConfig(config, appContext) {
|
|
|
105
105
|
config.html.favicon = createBuilderFavicon(config, appContext);
|
|
106
106
|
return config.html;
|
|
107
107
|
}
|
|
108
|
-
function initSourceConfig(config, appContext) {
|
|
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
|
};
|
|
@@ -176,8 +176,10 @@ function initSourceConfig(config, appContext) {
|
|
|
176
176
|
}
|
|
177
177
|
};
|
|
178
178
|
config.source.include = createBuilderInclude(config, appContext);
|
|
179
|
-
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
180
179
|
config.source.globalVars = createBuilderGlobalVars(config, appContext);
|
|
180
|
+
if (bundler === "webpack") {
|
|
181
|
+
config.source.moduleScopes = createBuilderModuleScope(config);
|
|
182
|
+
}
|
|
181
183
|
}
|
|
182
184
|
function initToolsConfig(config) {
|
|
183
185
|
var defaultTsChecker = {
|
|
@@ -197,7 +199,7 @@ function initToolsConfig(config) {
|
|
|
197
199
|
]
|
|
198
200
|
}
|
|
199
201
|
};
|
|
200
|
-
var
|
|
202
|
+
var _config_tools = config.tools, tsChecker = _config_tools.tsChecker, tsLoader = _config_tools.tsLoader;
|
|
201
203
|
config.tools.tsChecker = applyOptionsChain(defaultTsChecker, tsChecker);
|
|
202
204
|
tsLoader && (config.tools.tsLoader = function(tsLoaderConfig, utils) {
|
|
203
205
|
applyOptionsChain(_objectSpreadProps(_objectSpread({}, tsLoaderConfig), {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function createHtmlConfig(config) {
|
|
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
|
+
return {
|
|
4
|
+
disableHtmlFolder: disableHtmlFolder,
|
|
5
|
+
favicon: favicon,
|
|
6
|
+
faviconByEntries: faviconByEntries,
|
|
7
|
+
inject: inject,
|
|
8
|
+
injectByEntries: injectByEntries,
|
|
9
|
+
meta: meta,
|
|
10
|
+
metaByEntries: metaByEntries,
|
|
11
|
+
mountId: mountId,
|
|
12
|
+
title: title,
|
|
13
|
+
titleByEntries: titleByEntries,
|
|
14
|
+
crossorigin: crossorigin,
|
|
15
|
+
templateParameters: templateParameters,
|
|
16
|
+
templateParametersByEntries: templateParametersByEntries
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export { createHtmlConfig };
|
|
@@ -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,
|