@modern-js/app-tools 2.7.0 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +53 -2
- package/README.md +2 -2
- package/dist/cjs/analyze/generateCode.js +16 -2
- package/dist/cjs/analyze/index.js +0 -32
- package/dist/cjs/analyze/templates.js +26 -2
- package/dist/cjs/analyze/utils.js +5 -0
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
- package/dist/cjs/builder/generator/index.js +10 -2
- package/dist/cjs/builder/index.js +1 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +101 -0
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +91 -0
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +164 -0
- package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/builderPlugins}/index.js +5 -3
- package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
- package/dist/cjs/builder/shared/bundlerPlugins/index.js +19 -0
- package/dist/cjs/builder/shared/index.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/locale/en.js +1 -0
- package/dist/cjs/locale/zh.js +1 -0
- package/dist/esm/analyze/generateCode.js +34 -19
- package/dist/esm/analyze/index.js +2 -25
- package/dist/esm/analyze/templates.js +16 -2
- package/dist/esm/analyze/utils.js +4 -1
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +0 -11
- package/dist/esm/builder/generator/index.js +6 -4
- package/dist/esm/builder/index.js +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +101 -0
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +120 -0
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +350 -0
- package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +10 -6
- package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm/builder/shared/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/locale/en.js +1 -0
- package/dist/esm/locale/zh.js +1 -0
- package/dist/esm-node/analyze/generateCode.js +29 -4
- package/dist/esm-node/analyze/index.js +1 -39
- package/dist/esm-node/analyze/templates.js +25 -2
- package/dist/esm-node/analyze/utils.js +4 -0
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
- package/dist/esm-node/builder/generator/index.js +10 -2
- package/dist/esm-node/builder/index.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +67 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +67 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +143 -0
- package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm-node/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
- package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/index.js +1 -1
- package/dist/esm-node/index.js +1 -1
- package/dist/esm-node/locale/en.js +1 -0
- package/dist/esm-node/locale/zh.js +1 -0
- package/dist/types/analyze/templates.d.ts +3 -2
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +7 -0
- package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +5 -0
- package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +4 -0
- package/dist/types/builder/shared/builderPlugins/index.d.ts +3 -0
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +5 -0
- package/dist/types/builder/shared/bundlerPlugins/index.d.ts +3 -0
- package/dist/types/builder/shared/index.d.ts +1 -1
- package/dist/types/builder/shared/types.d.ts +7 -4
- package/dist/types/locale/en.d.ts +1 -0
- package/dist/types/locale/index.d.ts +2 -0
- package/dist/types/locale/zh.d.ts +1 -0
- package/dist/types/types/config/output.d.ts +2 -15
- package/package.json +26 -26
- package/dist/cjs/builder/shared/builderPlugins/adapterModern.js +0 -234
- package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +0 -1
- package/dist/esm/builder/shared/builderPlugins/adapterModern.js +0 -300
- package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +0 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterModern.js +0 -202
- package/dist/types/builder/builder-webpack/webpackPlugins/RouterPlugin.d.ts +0 -4
- package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +0 -13
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
var adapterModern_exports = {};
|
|
29
|
-
__export(adapterModern_exports, {
|
|
30
|
-
applyCallbacks: () => applyCallbacks,
|
|
31
|
-
builderPluginAdapterModern: () => builderPluginAdapterModern
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(adapterModern_exports);
|
|
34
|
-
var import_builder_shared = require("@modern-js/builder-shared");
|
|
35
|
-
var import_utils = require("@modern-js/utils");
|
|
36
|
-
var import_html_webpack_plugin = __toESM(require("@modern-js/builder-webpack-provider/html-webpack-plugin"));
|
|
37
|
-
var import_lodash = require("@modern-js/utils/lodash");
|
|
38
|
-
var import_HtmlAsyncChunkPlugin = require("../bundlerPlugins/HtmlAsyncChunkPlugin");
|
|
39
|
-
var import_HtmlBottomTemplate = require("../bundlerPlugins/HtmlBottomTemplate");
|
|
40
|
-
const isStreamingSSR = (userConfig) => {
|
|
41
|
-
const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
42
|
-
const { server } = userConfig;
|
|
43
|
-
if (isStreaming(server.ssr)) {
|
|
44
|
-
return true;
|
|
45
|
-
}
|
|
46
|
-
if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
47
|
-
for (const name of Object.keys(server.ssrByEntries)) {
|
|
48
|
-
if (isStreaming(server.ssrByEntries[name])) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
};
|
|
55
|
-
const builderPluginAdapterModern = (options) => ({
|
|
56
|
-
name: "builder-plugin-adapter-modern",
|
|
57
|
-
setup(api) {
|
|
58
|
-
const { normalizedConfig, appContext } = options;
|
|
59
|
-
api.modifyBuilderConfig((config) => {
|
|
60
|
-
if (isStreamingSSR(normalizedConfig)) {
|
|
61
|
-
return (0, import_builder_shared.mergeBuilderConfig)(config, {
|
|
62
|
-
html: {
|
|
63
|
-
inject: "body"
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return config;
|
|
68
|
-
});
|
|
69
|
-
api.modifyBundlerChain((chain, { target, CHAIN_ID, isProd }) => {
|
|
70
|
-
const builderConfig = api.getNormalizedConfig();
|
|
71
|
-
if (target === "node") {
|
|
72
|
-
chain.name("server");
|
|
73
|
-
} else if (target === "service-worker") {
|
|
74
|
-
chain.name("service-worker");
|
|
75
|
-
} else if (target === "web-worker") {
|
|
76
|
-
chain.name("worker");
|
|
77
|
-
} else if (target === "modern-web") {
|
|
78
|
-
chain.name("modern");
|
|
79
|
-
} else {
|
|
80
|
-
chain.name("client");
|
|
81
|
-
}
|
|
82
|
-
if (target === "node" || target === "service-worker") {
|
|
83
|
-
applyNodeCompat(target, chain, normalizedConfig, isProd);
|
|
84
|
-
}
|
|
85
|
-
if (isHtmlEnabled(builderConfig, target)) {
|
|
86
|
-
applyBottomHtmlPlugin({
|
|
87
|
-
api,
|
|
88
|
-
chain,
|
|
89
|
-
modernConfig: normalizedConfig,
|
|
90
|
-
appContext,
|
|
91
|
-
CHAIN_ID
|
|
92
|
-
});
|
|
93
|
-
applyAsyncChunkHtmlPlugin({
|
|
94
|
-
chain,
|
|
95
|
-
modernConfig: normalizedConfig,
|
|
96
|
-
CHAIN_ID
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (target !== "node" && target !== "web-worker" && target !== "service-worker") {
|
|
100
|
-
const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
101
|
-
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
102
|
-
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
applyCallbacks(api, options);
|
|
106
|
-
function isHtmlEnabled(config, target) {
|
|
107
|
-
var _a;
|
|
108
|
-
return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
function applyCallbacks(api, options) {
|
|
113
|
-
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
114
|
-
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
115
|
-
options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
|
|
116
|
-
options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
|
|
117
|
-
options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
|
|
118
|
-
options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
|
|
119
|
-
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
120
|
-
options.onExit && api.onExit(options.onExit);
|
|
121
|
-
}
|
|
122
|
-
function applyBottomHtmlPlugin({
|
|
123
|
-
api,
|
|
124
|
-
chain,
|
|
125
|
-
modernConfig,
|
|
126
|
-
appContext,
|
|
127
|
-
CHAIN_ID
|
|
128
|
-
}) {
|
|
129
|
-
for (const entryName of Object.keys(api.context.entry)) {
|
|
130
|
-
const baseTemplateParams = {
|
|
131
|
-
entryName,
|
|
132
|
-
title: (0, import_utils.getEntryOptions)(
|
|
133
|
-
entryName,
|
|
134
|
-
modernConfig.html.title,
|
|
135
|
-
modernConfig.html.titleByEntries,
|
|
136
|
-
appContext.packageName
|
|
137
|
-
),
|
|
138
|
-
mountId: modernConfig.html.mountId,
|
|
139
|
-
...(0, import_utils.getEntryOptions)(
|
|
140
|
-
entryName,
|
|
141
|
-
modernConfig.html.templateParameters,
|
|
142
|
-
modernConfig.html.templateParametersByEntries,
|
|
143
|
-
appContext.packageName
|
|
144
|
-
)
|
|
145
|
-
};
|
|
146
|
-
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
|
|
147
|
-
{
|
|
148
|
-
...args[0] || {},
|
|
149
|
-
__internal__: true,
|
|
150
|
-
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && (0, import_lodash.template)(appContext.htmlTemplates[`__${entryName}-bottom__`])(
|
|
151
|
-
baseTemplateParams
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
]);
|
|
155
|
-
}
|
|
156
|
-
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(import_HtmlBottomTemplate.BottomTemplatePlugin, [import_html_webpack_plugin.default]);
|
|
157
|
-
}
|
|
158
|
-
function applyAsyncChunkHtmlPlugin({
|
|
159
|
-
chain,
|
|
160
|
-
modernConfig,
|
|
161
|
-
CHAIN_ID
|
|
162
|
-
}) {
|
|
163
|
-
if (isStreamingSSR(modernConfig)) {
|
|
164
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(import_HtmlAsyncChunkPlugin.HtmlAsyncChunkPlugin, [import_html_webpack_plugin.default]);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
function applyNodeCompat(target, chain, modernConfig, isProd) {
|
|
168
|
-
const nodeExts = [
|
|
169
|
-
".node.js",
|
|
170
|
-
".node.jsx",
|
|
171
|
-
".node.ts",
|
|
172
|
-
".node.tsx",
|
|
173
|
-
".server.js",
|
|
174
|
-
".server.ts",
|
|
175
|
-
".server.ts",
|
|
176
|
-
".server.tsx"
|
|
177
|
-
];
|
|
178
|
-
const webWorkerExts = [
|
|
179
|
-
".worker.js",
|
|
180
|
-
".worker.jsx",
|
|
181
|
-
".worker.ts",
|
|
182
|
-
".worker.tsx"
|
|
183
|
-
];
|
|
184
|
-
for (const ext of nodeExts) {
|
|
185
|
-
chain.resolve.extensions.prepend(ext);
|
|
186
|
-
}
|
|
187
|
-
if (target === "service-worker") {
|
|
188
|
-
for (const ext of webWorkerExts) {
|
|
189
|
-
chain.resolve.extensions.prepend(ext);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
filterEntriesBySSRConfig(
|
|
193
|
-
isProd,
|
|
194
|
-
chain,
|
|
195
|
-
modernConfig.server,
|
|
196
|
-
modernConfig.output
|
|
197
|
-
);
|
|
198
|
-
function filterEntriesBySSRConfig(isProd2, chain2, serverConfig, outputConfig) {
|
|
199
|
-
var _a;
|
|
200
|
-
const entries = chain2.entryPoints.entries();
|
|
201
|
-
if (isProd2 && ((outputConfig == null ? void 0 : outputConfig.ssg) === true || typeof ((_a = outputConfig == null ? void 0 : outputConfig.ssg) == null ? void 0 : _a[0]) === "function")) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
if (typeof entries === "undefined") {
|
|
205
|
-
throw new Error(
|
|
206
|
-
"No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required"
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
const entryNames = Object.keys(entries);
|
|
210
|
-
if (isProd2 && entryNames.length === 1 && (outputConfig == null ? void 0 : outputConfig.ssg)) {
|
|
211
|
-
return;
|
|
212
|
-
}
|
|
213
|
-
const ssgEntries = [];
|
|
214
|
-
if (isProd2 && (outputConfig == null ? void 0 : outputConfig.ssg)) {
|
|
215
|
-
const { ssg } = outputConfig;
|
|
216
|
-
entryNames.forEach((name) => {
|
|
217
|
-
if (ssg[name]) {
|
|
218
|
-
ssgEntries.push(name);
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
const { ssr, ssrByEntries } = serverConfig || {};
|
|
223
|
-
entryNames.forEach((name) => {
|
|
224
|
-
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries == null ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries == null ? void 0 : ssrByEntries[name]))) {
|
|
225
|
-
chain2.entryPoints.delete(name);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
231
|
-
0 && (module.exports = {
|
|
232
|
-
applyCallbacks,
|
|
233
|
-
builderPluginAdapterModern
|
|
234
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./RouterPlugin";
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
function _defineProperty(obj, key, value) {
|
|
2
|
-
if (key in obj) {
|
|
3
|
-
Object.defineProperty(obj, key, {
|
|
4
|
-
value: value,
|
|
5
|
-
enumerable: true,
|
|
6
|
-
configurable: true,
|
|
7
|
-
writable: true
|
|
8
|
-
});
|
|
9
|
-
} else {
|
|
10
|
-
obj[key] = value;
|
|
11
|
-
}
|
|
12
|
-
return obj;
|
|
13
|
-
}
|
|
14
|
-
function _objectSpread(target) {
|
|
15
|
-
for(var i = 1; i < arguments.length; i++){
|
|
16
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
-
var ownKeys = Object.keys(source);
|
|
18
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
ownKeys.forEach(function(key) {
|
|
24
|
-
_defineProperty(target, key, source[key]);
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
return target;
|
|
28
|
-
}
|
|
29
|
-
function ownKeys(object, enumerableOnly) {
|
|
30
|
-
var keys = Object.keys(object);
|
|
31
|
-
if (Object.getOwnPropertySymbols) {
|
|
32
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
33
|
-
if (enumerableOnly) {
|
|
34
|
-
symbols = symbols.filter(function(sym) {
|
|
35
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
keys.push.apply(keys, symbols);
|
|
39
|
-
}
|
|
40
|
-
return keys;
|
|
41
|
-
}
|
|
42
|
-
function _objectSpreadProps(target, source) {
|
|
43
|
-
source = source != null ? source : {};
|
|
44
|
-
if (Object.getOwnPropertyDescriptors) {
|
|
45
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
46
|
-
} else {
|
|
47
|
-
ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return target;
|
|
52
|
-
}
|
|
53
|
-
import { mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
54
|
-
import { getEntryOptions } from "@modern-js/utils";
|
|
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) {
|
|
94
|
-
return {
|
|
95
|
-
name: "builder-plugin-adapter-modern",
|
|
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;
|
|
102
|
-
api.modifyBuilderConfig(function(config) {
|
|
103
|
-
if (isStreamingSSR(normalizedConfig)) {
|
|
104
|
-
return mergeBuilderConfig(config, {
|
|
105
|
-
html: {
|
|
106
|
-
inject: "body"
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return config;
|
|
111
|
-
});
|
|
112
|
-
api.modifyBundlerChain(function(chain, param) {
|
|
113
|
-
var target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd;
|
|
114
|
-
var builderConfig = api.getNormalizedConfig();
|
|
115
|
-
if (target === "node") {
|
|
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");
|
|
121
|
-
} else if (target === "modern-web") {
|
|
122
|
-
chain.name("modern");
|
|
123
|
-
} else {
|
|
124
|
-
chain.name("client");
|
|
125
|
-
}
|
|
126
|
-
if (target === "node" || target === "service-worker") {
|
|
127
|
-
applyNodeCompat(target, chain, normalizedConfig, isProd);
|
|
128
|
-
}
|
|
129
|
-
if (isHtmlEnabled(builderConfig, target)) {
|
|
130
|
-
applyBottomHtmlPlugin({
|
|
131
|
-
api: api,
|
|
132
|
-
chain: chain,
|
|
133
|
-
modernConfig: normalizedConfig,
|
|
134
|
-
appContext: appContext,
|
|
135
|
-
CHAIN_ID: CHAIN_ID
|
|
136
|
-
});
|
|
137
|
-
applyAsyncChunkHtmlPlugin({
|
|
138
|
-
chain: chain,
|
|
139
|
-
modernConfig: normalizedConfig,
|
|
140
|
-
CHAIN_ID: CHAIN_ID
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
if (target !== "node" && target !== "web-worker" && target !== "service-worker") {
|
|
144
|
-
var bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
145
|
-
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
146
|
-
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
applyCallbacks(api, options);
|
|
150
|
-
}
|
|
151
|
-
};
|
|
152
|
-
};
|
|
153
|
-
function applyCallbacks(api, options) {
|
|
154
|
-
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
155
|
-
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
156
|
-
options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
|
|
157
|
-
options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
|
|
158
|
-
options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
|
|
159
|
-
options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
|
|
160
|
-
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
161
|
-
options.onExit && api.onExit(options.onExit);
|
|
162
|
-
}
|
|
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) {
|
|
211
|
-
var filterEntriesBySSRConfig = function filterEntriesBySSRConfig(isProd2, chain2, serverConfig, outputConfig) {
|
|
212
|
-
var _outputConfig_ssg;
|
|
213
|
-
var entries = chain2.entryPoints.entries();
|
|
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")) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
if (typeof entries === "undefined") {
|
|
218
|
-
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
|
219
|
-
}
|
|
220
|
-
var entryNames = Object.keys(entries);
|
|
221
|
-
if (isProd2 && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
var ssgEntries = [];
|
|
225
|
-
if (isProd2 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
|
226
|
-
var ssg = outputConfig.ssg;
|
|
227
|
-
entryNames.forEach(function(name) {
|
|
228
|
-
if (ssg[name]) {
|
|
229
|
-
ssgEntries.push(name);
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
|
|
234
|
-
entryNames.forEach(function(name) {
|
|
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]))) {
|
|
236
|
-
chain2.entryPoints.delete(name);
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
};
|
|
240
|
-
var nodeExts = [
|
|
241
|
-
".node.js",
|
|
242
|
-
".node.jsx",
|
|
243
|
-
".node.ts",
|
|
244
|
-
".node.tsx",
|
|
245
|
-
".server.js",
|
|
246
|
-
".server.ts",
|
|
247
|
-
".server.ts",
|
|
248
|
-
".server.tsx"
|
|
249
|
-
];
|
|
250
|
-
var webWorkerExts = [
|
|
251
|
-
".worker.js",
|
|
252
|
-
".worker.jsx",
|
|
253
|
-
".worker.ts",
|
|
254
|
-
".worker.tsx"
|
|
255
|
-
];
|
|
256
|
-
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
257
|
-
try {
|
|
258
|
-
for(var _iterator = nodeExts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
259
|
-
var ext = _step.value;
|
|
260
|
-
chain.resolve.extensions.prepend(ext);
|
|
261
|
-
}
|
|
262
|
-
} catch (err) {
|
|
263
|
-
_didIteratorError = true;
|
|
264
|
-
_iteratorError = err;
|
|
265
|
-
} finally{
|
|
266
|
-
try {
|
|
267
|
-
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
268
|
-
_iterator.return();
|
|
269
|
-
}
|
|
270
|
-
} finally{
|
|
271
|
-
if (_didIteratorError) {
|
|
272
|
-
throw _iteratorError;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
if (target === "service-worker") {
|
|
277
|
-
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
278
|
-
try {
|
|
279
|
-
for(var _iterator1 = webWorkerExts[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
280
|
-
var ext1 = _step1.value;
|
|
281
|
-
chain.resolve.extensions.prepend(ext1);
|
|
282
|
-
}
|
|
283
|
-
} catch (err) {
|
|
284
|
-
_didIteratorError1 = true;
|
|
285
|
-
_iteratorError1 = err;
|
|
286
|
-
} finally{
|
|
287
|
-
try {
|
|
288
|
-
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
289
|
-
_iterator1.return();
|
|
290
|
-
}
|
|
291
|
-
} finally{
|
|
292
|
-
if (_didIteratorError1) {
|
|
293
|
-
throw _iteratorError1;
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
|
|
299
|
-
}
|
|
300
|
-
export { applyCallbacks, builderPluginAdapterModern };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./RouterPlugin";
|