@modern-js/app-tools 2.58.2 → 2.59.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -1
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
- package/dist/cjs/builder/generator/index.js +2 -3
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +8 -13
- package/dist/cjs/builder/shared/builderPlugins/index.js +1 -3
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
- package/dist/cjs/commands/build.js +2 -2
- package/dist/cjs/commands/dev.js +6 -5
- package/dist/cjs/commands/index.js +1 -1
- package/dist/cjs/commands/serve.js +4 -3
- package/dist/cjs/config/legacy/index.js +3 -3
- package/dist/cjs/esm/register-esm.mjs +2 -3
- package/dist/cjs/esm/utils.mjs +2 -2
- package/dist/cjs/index.js +17 -10
- package/dist/cjs/locale/index.js +1 -1
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +50 -44
- package/dist/cjs/plugins/analyze/getServerRoutes.js +2 -2
- package/dist/cjs/plugins/analyze/index.js +6 -6
- package/dist/cjs/plugins/analyze/utils.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/utils.js +2 -2
- package/dist/cjs/plugins/deploy/index.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +2 -2
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/esm/builder/builder-rspack/adapterCopy.js +166 -0
- package/dist/esm/builder/builder-rspack/index.js +34 -0
- package/dist/esm/builder/builder-webpack/adapterModern.js +29 -0
- package/dist/esm/builder/builder-webpack/createCopyPattern.js +43 -0
- package/dist/esm/builder/builder-webpack/index.js +52 -0
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +37 -0
- package/dist/esm/builder/generator/getBuilderEnvironments.js +81 -0
- package/dist/esm/builder/generator/index.js +93 -0
- package/dist/esm/builder/index.js +45 -0
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +85 -0
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +126 -0
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +261 -0
- package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +51 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +37 -0
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +314 -0
- package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm/builder/shared/createCopyInfo.js +14 -0
- package/dist/esm/builder/shared/index.js +3 -0
- package/dist/esm/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/esm/builder/shared/types.js +0 -0
- package/dist/esm/commands/build.js +140 -0
- package/dist/esm/commands/deploy.js +48 -0
- package/dist/esm/commands/dev.js +193 -0
- package/dist/esm/commands/index.js +411 -0
- package/dist/esm/commands/inspect.js +28 -0
- package/dist/esm/commands/serve.js +94 -0
- package/dist/esm/config/default.js +190 -0
- package/dist/esm/config/index.js +3 -0
- package/dist/esm/config/initialize/index.js +9 -0
- package/dist/esm/config/initialize/inits.js +89 -0
- package/dist/esm/config/legacy/createHtmlConfig.js +21 -0
- package/dist/esm/config/legacy/createOutputConfig.js +45 -0
- package/dist/esm/config/legacy/createSourceConfig.js +46 -0
- package/dist/esm/config/legacy/createToolsConfig.js +28 -0
- package/dist/esm/config/legacy/index.js +43 -0
- package/dist/esm/defineConfig.js +16 -0
- package/dist/esm/esm/esbuild-loader.mjs +20 -0
- package/dist/esm/esm/register-esm.mjs +66 -0
- package/dist/esm/esm/ts-node-loader.mjs +21 -0
- package/dist/esm/esm/utils.mjs +43 -0
- package/dist/esm/exports/server.js +4 -0
- package/dist/esm/hooks.js +34 -0
- package/dist/esm/index.js +246 -0
- package/dist/esm/locale/en.js +43 -0
- package/dist/esm/locale/index.js +12 -0
- package/dist/esm/locale/zh.js +43 -0
- package/dist/esm/plugins/analyze/constants.js +14 -0
- package/dist/esm/plugins/analyze/getBundleEntry.js +102 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +266 -0
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +178 -0
- package/dist/esm/plugins/analyze/getServerRoutes.js +132 -0
- package/dist/esm/plugins/analyze/index.js +380 -0
- package/dist/esm/plugins/analyze/isDefaultExportFunction.js +49 -0
- package/dist/esm/plugins/analyze/templates.js +6 -0
- package/dist/esm/plugins/analyze/utils.js +101 -0
- package/dist/esm/plugins/deploy/dependencies/index.js +615 -0
- package/dist/esm/plugins/deploy/dependencies/utils.js +421 -0
- package/dist/esm/plugins/deploy/exports.js +4 -0
- package/dist/esm/plugins/deploy/index.js +135 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.js +11 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/esm/plugins/deploy/platforms/netlify-handler.js +205 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +327 -0
- package/dist/esm/plugins/deploy/platforms/node-entry.js +108 -0
- package/dist/esm/plugins/deploy/platforms/node.js +161 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel-entry.js +11 -0
- package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/esm/plugins/deploy/platforms/vercel-handler.js +206 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +261 -0
- package/dist/esm/plugins/deploy/utils.js +47 -0
- package/dist/esm/plugins/initialize/index.js +119 -0
- package/dist/esm/plugins/serverBuild.js +87 -0
- package/dist/esm/types/config/deploy.js +0 -0
- package/dist/esm/types/config/dev.js +0 -0
- package/dist/esm/types/config/experiments.js +0 -0
- package/dist/esm/types/config/html.js +0 -0
- package/dist/esm/types/config/index.js +1 -0
- package/dist/esm/types/config/output.js +0 -0
- package/dist/esm/types/config/performance.js +0 -0
- package/dist/esm/types/config/security.js +0 -0
- package/dist/esm/types/config/source.js +0 -0
- package/dist/esm/types/config/testing.js +0 -0
- package/dist/esm/types/config/tools.js +0 -0
- package/dist/esm/types/hooks.js +0 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/legacyConfig/deploy.js +0 -0
- package/dist/esm/types/legacyConfig/dev.js +0 -0
- package/dist/esm/types/legacyConfig/index.js +0 -0
- package/dist/esm/types/legacyConfig/output.js +0 -0
- package/dist/esm/types/legacyConfig/source.js +0 -0
- package/dist/esm/types/legacyConfig/testing.js +0 -0
- package/dist/esm/types/legacyConfig/tools.js +0 -0
- package/dist/esm/types/utils.js +0 -0
- package/dist/esm/utils/config.js +122 -0
- package/dist/esm/utils/createServer.js +58 -0
- package/dist/esm/utils/env.js +16 -0
- package/dist/esm/utils/generateWatchFiles.js +71 -0
- package/dist/esm/utils/getSelectedEntries.js +67 -0
- package/dist/esm/utils/loadPlugins.js +74 -0
- package/dist/esm/utils/printInstructions.js +32 -0
- package/dist/esm/utils/register.js +188 -0
- package/dist/esm/utils/restart.js +67 -0
- package/dist/esm/utils/routes.js +42 -0
- package/dist/esm/utils/types.js +0 -0
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +67 -0
- package/dist/esm-node/builder/builder-rspack/index.js +12 -0
- package/dist/esm-node/builder/builder-webpack/adapterModern.js +26 -0
- package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +41 -0
- package/dist/esm-node/builder/builder-webpack/index.js +20 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +44 -0
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
- package/dist/esm-node/builder/generator/index.js +36 -0
- package/dist/esm-node/builder/index.js +11 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +48 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +60 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +151 -0
- package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +31 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +228 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/createCopyInfo.js +14 -0
- package/dist/esm-node/builder/shared/index.js +3 -0
- package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/esm-node/builder/shared/types.js +0 -0
- package/dist/esm-node/commands/build.js +64 -0
- package/dist/esm-node/commands/deploy.js +12 -0
- package/dist/esm-node/commands/dev.js +105 -0
- package/dist/esm-node/commands/index.js +92 -0
- package/dist/esm-node/commands/inspect.js +15 -0
- package/dist/esm-node/commands/serve.js +52 -0
- package/dist/esm-node/config/default.js +197 -0
- package/dist/esm-node/config/index.js +3 -0
- package/dist/esm-node/config/initialize/index.js +9 -0
- package/dist/esm-node/config/initialize/inits.js +79 -0
- package/dist/esm-node/config/legacy/createHtmlConfig.js +21 -0
- package/dist/esm-node/config/legacy/createOutputConfig.js +45 -0
- package/dist/esm-node/config/legacy/createSourceConfig.js +29 -0
- package/dist/esm-node/config/legacy/createToolsConfig.js +28 -0
- package/dist/esm-node/config/legacy/index.js +43 -0
- package/dist/esm-node/defineConfig.js +13 -0
- package/dist/esm-node/esm/esbuild-loader.mjs +20 -0
- package/dist/esm-node/esm/register-esm.mjs +66 -0
- package/dist/esm-node/esm/ts-node-loader.mjs +21 -0
- package/dist/esm-node/esm/utils.mjs +43 -0
- package/dist/esm-node/exports/server.js +4 -0
- package/dist/esm-node/hooks.js +34 -0
- package/dist/esm-node/index.js +131 -0
- package/dist/esm-node/locale/en.js +43 -0
- package/dist/esm-node/locale/index.js +12 -0
- package/dist/esm-node/locale/zh.js +43 -0
- package/dist/esm-node/plugins/analyze/constants.js +14 -0
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +61 -0
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +106 -0
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +74 -0
- package/dist/esm-node/plugins/analyze/getServerRoutes.js +132 -0
- package/dist/esm-node/plugins/analyze/index.js +166 -0
- package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +47 -0
- package/dist/esm-node/plugins/analyze/templates.js +24 -0
- package/dist/esm-node/plugins/analyze/utils.js +68 -0
- package/dist/esm-node/plugins/deploy/dependencies/index.js +202 -0
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +137 -0
- package/dist/esm-node/plugins/deploy/exports.js +4 -0
- package/dist/esm-node/plugins/deploy/index.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +11 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +71 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +117 -0
- package/dist/esm-node/plugins/deploy/platforms/node-entry.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +72 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +11 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +72 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +129 -0
- package/dist/esm-node/plugins/deploy/utils.js +44 -0
- package/dist/esm-node/plugins/initialize/index.js +84 -0
- package/dist/esm-node/plugins/serverBuild.js +58 -0
- package/dist/esm-node/types/config/deploy.js +0 -0
- package/dist/esm-node/types/config/dev.js +0 -0
- package/dist/esm-node/types/config/experiments.js +0 -0
- package/dist/esm-node/types/config/html.js +0 -0
- package/dist/esm-node/types/config/index.js +1 -0
- package/dist/esm-node/types/config/output.js +0 -0
- package/dist/esm-node/types/config/performance.js +0 -0
- package/dist/esm-node/types/config/security.js +0 -0
- package/dist/esm-node/types/config/source.js +0 -0
- package/dist/esm-node/types/config/testing.js +0 -0
- package/dist/esm-node/types/config/tools.js +0 -0
- package/dist/esm-node/types/hooks.js +0 -0
- package/dist/esm-node/types/index.js +3 -0
- package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
- package/dist/esm-node/types/legacyConfig/dev.js +0 -0
- package/dist/esm-node/types/legacyConfig/index.js +0 -0
- package/dist/esm-node/types/legacyConfig/output.js +0 -0
- package/dist/esm-node/types/legacyConfig/source.js +0 -0
- package/dist/esm-node/types/legacyConfig/testing.js +0 -0
- package/dist/esm-node/types/legacyConfig/tools.js +0 -0
- package/dist/esm-node/types/utils.js +0 -0
- package/dist/esm-node/utils/config.js +49 -0
- package/dist/esm-node/utils/createServer.js +26 -0
- package/dist/esm-node/utils/env.js +16 -0
- package/dist/esm-node/utils/generateWatchFiles.js +30 -0
- package/dist/esm-node/utils/getSelectedEntries.js +34 -0
- package/dist/esm-node/utils/loadPlugins.js +22 -0
- package/dist/esm-node/utils/printInstructions.js +11 -0
- package/dist/esm-node/utils/register.js +96 -0
- package/dist/esm-node/utils/restart.js +22 -0
- package/dist/esm-node/utils/routes.js +21 -0
- package/dist/esm-node/utils/types.js +0 -0
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
- package/dist/types/builder/generator/index.d.ts +2 -2
- package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
- package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
- package/dist/types/builder/shared/types.d.ts +1 -1
- package/dist/types/commands/build.d.ts +1 -1
- package/dist/types/commands/dev.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +1 -1
- package/dist/types/config/default.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -1
- package/dist/types/plugins/initialize/index.d.ts +1 -1
- package/dist/types/plugins/serverBuild.d.ts +1 -1
- package/dist/types/types/config/index.d.ts +8 -8
- package/dist/types/types/config/output.d.ts +1 -1
- package/dist/types/types/config/tools.d.ts +3 -3
- package/dist/types/types/hooks.d.ts +2 -2
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/types/legacyConfig/index.d.ts +3 -3
- package/dist/types/types/legacyConfig/tools.d.ts +1 -1
- package/dist/types/utils/printInstructions.d.ts +1 -1
- package/package.json +20 -20
- package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +0 -51
- package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +0 -2
@@ -0,0 +1,126 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
+
import { isHtmlDisabled } from "@modern-js/uni-builder";
|
6
|
+
import { MAIN_ENTRY_NAME, getEntryOptions, removeTailSlash } from "@modern-js/utils";
|
7
|
+
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
8
|
+
import { BottomTemplatePlugin } from "../bundlerPlugins";
|
9
|
+
var createVirtualModule = function(content) {
|
10
|
+
return "data:text/javascript,".concat(content);
|
11
|
+
};
|
12
|
+
var builderPluginAdapterHtml = function(options) {
|
13
|
+
return {
|
14
|
+
name: "builder-plugin-adapter-modern-html",
|
15
|
+
setup: function setup(api) {
|
16
|
+
api.modifyBundlerChain(function() {
|
17
|
+
var _ref = _async_to_generator(function(chain, param) {
|
18
|
+
var CHAIN_ID, target, HtmlBundlerPlugin, environment, builderConfig;
|
19
|
+
return _ts_generator(this, function(_state) {
|
20
|
+
switch (_state.label) {
|
21
|
+
case 0:
|
22
|
+
CHAIN_ID = param.CHAIN_ID, target = param.target, HtmlBundlerPlugin = param.HtmlPlugin, environment = param.environment;
|
23
|
+
builderConfig = environment.config;
|
24
|
+
if (!!isHtmlDisabled(builderConfig, target))
|
25
|
+
return [
|
26
|
+
3,
|
27
|
+
2
|
28
|
+
];
|
29
|
+
applyBottomHtmlPlugin({
|
30
|
+
options,
|
31
|
+
chain,
|
32
|
+
CHAIN_ID,
|
33
|
+
HtmlBundlerPlugin,
|
34
|
+
htmlPaths: environment.htmlPaths
|
35
|
+
});
|
36
|
+
return [
|
37
|
+
4,
|
38
|
+
injectAssetPrefix({
|
39
|
+
chain
|
40
|
+
})
|
41
|
+
];
|
42
|
+
case 1:
|
43
|
+
_state.sent();
|
44
|
+
_state.label = 2;
|
45
|
+
case 2:
|
46
|
+
return [
|
47
|
+
2
|
48
|
+
];
|
49
|
+
}
|
50
|
+
});
|
51
|
+
});
|
52
|
+
return function(chain, _) {
|
53
|
+
return _ref.apply(this, arguments);
|
54
|
+
};
|
55
|
+
}());
|
56
|
+
}
|
57
|
+
};
|
58
|
+
};
|
59
|
+
function injectAssetPrefix(_) {
|
60
|
+
return _injectAssetPrefix.apply(this, arguments);
|
61
|
+
}
|
62
|
+
function _injectAssetPrefix() {
|
63
|
+
_injectAssetPrefix = _async_to_generator(function(param) {
|
64
|
+
var chain, entries, entryNames, assetPrefix, code;
|
65
|
+
return _ts_generator(this, function(_state) {
|
66
|
+
chain = param.chain;
|
67
|
+
entries = chain.entryPoints.entries() || {};
|
68
|
+
entryNames = Object.keys(entries);
|
69
|
+
assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
|
70
|
+
code = "window.__assetPrefix__ = '".concat(assetPrefix, "';");
|
71
|
+
entryNames.forEach(function(entryName) {
|
72
|
+
entries[entryName].prepend(createVirtualModule(code));
|
73
|
+
});
|
74
|
+
return [
|
75
|
+
2
|
76
|
+
];
|
77
|
+
});
|
78
|
+
});
|
79
|
+
return _injectAssetPrefix.apply(this, arguments);
|
80
|
+
}
|
81
|
+
function applyBottomHtmlPlugin(param) {
|
82
|
+
var chain = param.chain, options = param.options, CHAIN_ID = param.CHAIN_ID, HtmlBundlerPlugin = param.HtmlBundlerPlugin, htmlPaths = param.htmlPaths;
|
83
|
+
var modernConfig = options.normalizedConfig, appContext = options.appContext;
|
84
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
85
|
+
try {
|
86
|
+
var _loop = function() {
|
87
|
+
var entryName = _step.value;
|
88
|
+
var mainEntryName = modernConfig.source.mainEntryName;
|
89
|
+
var isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
|
90
|
+
var baseTemplateParams = _object_spread({
|
91
|
+
entryName,
|
92
|
+
title: getEntryOptions(entryName, isMainEntry, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
93
|
+
mountId: modernConfig.html.mountId
|
94
|
+
}, getEntryOptions(entryName, isMainEntry, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
|
95
|
+
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function(args) {
|
96
|
+
return [
|
97
|
+
_object_spread_props(_object_spread({}, args[0] || {}), {
|
98
|
+
__internal__: true,
|
99
|
+
bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
|
100
|
+
})
|
101
|
+
];
|
102
|
+
});
|
103
|
+
};
|
104
|
+
for (var _iterator = Object.keys(htmlPaths)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)
|
105
|
+
_loop();
|
106
|
+
} catch (err) {
|
107
|
+
_didIteratorError = true;
|
108
|
+
_iteratorError = err;
|
109
|
+
} finally {
|
110
|
+
try {
|
111
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
112
|
+
_iterator.return();
|
113
|
+
}
|
114
|
+
} finally {
|
115
|
+
if (_didIteratorError) {
|
116
|
+
throw _iteratorError;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
chain.plugin("bottom-template").use(BottomTemplatePlugin, [
|
121
|
+
HtmlBundlerPlugin
|
122
|
+
]);
|
123
|
+
}
|
124
|
+
export {
|
125
|
+
builderPluginAdapterHtml
|
126
|
+
};
|
@@ -0,0 +1,261 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import * as path from "path";
|
4
|
+
import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/uni-builder";
|
5
|
+
import { fs, isUseSSRBundle } from "@modern-js/utils";
|
6
|
+
import { mergeRsbuildConfig } from "@rsbuild/core";
|
7
|
+
import { getServerCombinedModueFile } from "../../../plugins/analyze/utils";
|
8
|
+
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
9
|
+
var builderPluginAdapterSSR = function(options) {
|
10
|
+
return {
|
11
|
+
name: "builder-plugin-adapter-modern-ssr",
|
12
|
+
setup: function setup(api) {
|
13
|
+
var normalizedConfig = options.normalizedConfig;
|
14
|
+
api.modifyRsbuildConfig(function(config) {
|
15
|
+
return mergeRsbuildConfig(config, {
|
16
|
+
html: {
|
17
|
+
inject: isStreamingSSR(normalizedConfig) ? "body" : void 0
|
18
|
+
},
|
19
|
+
server: {
|
20
|
+
// the http-compression can't handler stream http.
|
21
|
+
// so we disable compress when user use stream ssr temporarily.
|
22
|
+
compress: isStreamingSSR(normalizedConfig) ? false : void 0
|
23
|
+
}
|
24
|
+
});
|
25
|
+
});
|
26
|
+
api.modifyBundlerChain(function() {
|
27
|
+
var _ref = _async_to_generator(function(chain, param) {
|
28
|
+
var target, isProd, HtmlBundlerPlugin, isServer, environment, builderConfig, normalizedConfig2, isServiceWorker;
|
29
|
+
return _ts_generator(this, function(_state) {
|
30
|
+
switch (_state.label) {
|
31
|
+
case 0:
|
32
|
+
target = param.target, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer, environment = param.environment;
|
33
|
+
builderConfig = environment.config;
|
34
|
+
normalizedConfig2 = options.normalizedConfig;
|
35
|
+
applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
|
36
|
+
isServiceWorker = environment.name === SERVICE_WORKER_ENVIRONMENT_NAME;
|
37
|
+
if (target === "node" || isServiceWorker) {
|
38
|
+
applyFilterEntriesBySSRConfig({
|
39
|
+
isProd,
|
40
|
+
chain,
|
41
|
+
appNormalizedConfig: normalizedConfig2
|
42
|
+
});
|
43
|
+
}
|
44
|
+
if (!isUseSSRBundle(normalizedConfig2))
|
45
|
+
return [
|
46
|
+
3,
|
47
|
+
2
|
48
|
+
];
|
49
|
+
return [
|
50
|
+
4,
|
51
|
+
applySSRLoaderEntry(chain, options, isServer)
|
52
|
+
];
|
53
|
+
case 1:
|
54
|
+
_state.sent();
|
55
|
+
applySSRDataLoader(chain, options);
|
56
|
+
_state.label = 2;
|
57
|
+
case 2:
|
58
|
+
if (!isHtmlDisabled(builderConfig, target)) {
|
59
|
+
applyAsyncChunkHtmlPlugin({
|
60
|
+
chain,
|
61
|
+
modernConfig: options.normalizedConfig,
|
62
|
+
HtmlBundlerPlugin
|
63
|
+
});
|
64
|
+
}
|
65
|
+
return [
|
66
|
+
2
|
67
|
+
];
|
68
|
+
}
|
69
|
+
});
|
70
|
+
});
|
71
|
+
return function(chain, _) {
|
72
|
+
return _ref.apply(this, arguments);
|
73
|
+
};
|
74
|
+
}());
|
75
|
+
}
|
76
|
+
};
|
77
|
+
};
|
78
|
+
var isStreamingSSR = function(userConfig) {
|
79
|
+
var isStreaming = function(ssr) {
|
80
|
+
return ssr && typeof ssr === "object" && ssr.mode === "stream";
|
81
|
+
};
|
82
|
+
var server = userConfig.server;
|
83
|
+
if (isStreaming(server.ssr)) {
|
84
|
+
return true;
|
85
|
+
}
|
86
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
87
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
88
|
+
try {
|
89
|
+
for (var _iterator = Object.keys(server.ssrByEntries)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
90
|
+
var name = _step.value;
|
91
|
+
if (isStreaming(server.ssrByEntries[name])) {
|
92
|
+
return true;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
} catch (err) {
|
96
|
+
_didIteratorError = true;
|
97
|
+
_iteratorError = err;
|
98
|
+
} finally {
|
99
|
+
try {
|
100
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
101
|
+
_iterator.return();
|
102
|
+
}
|
103
|
+
} finally {
|
104
|
+
if (_didIteratorError) {
|
105
|
+
throw _iteratorError;
|
106
|
+
}
|
107
|
+
}
|
108
|
+
}
|
109
|
+
}
|
110
|
+
return false;
|
111
|
+
};
|
112
|
+
function applyAsyncChunkHtmlPlugin(param) {
|
113
|
+
var chain = param.chain, modernConfig = param.modernConfig, HtmlBundlerPlugin = param.HtmlBundlerPlugin;
|
114
|
+
if (isStreamingSSR(modernConfig)) {
|
115
|
+
chain.plugin("html-async-chunk").use(HtmlAsyncChunkPlugin, [
|
116
|
+
HtmlBundlerPlugin
|
117
|
+
]);
|
118
|
+
}
|
119
|
+
}
|
120
|
+
function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
|
121
|
+
var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
|
122
|
+
var appContext = options.appContext, normalizedConfig = options.normalizedConfig;
|
123
|
+
var entrypoints = appContext.entrypoints;
|
124
|
+
var existNestedRoutes = entrypoints.some(function(entrypoint) {
|
125
|
+
return entrypoint.nestedRoutesEntry;
|
126
|
+
});
|
127
|
+
var routerConfig = normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
128
|
+
var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
129
|
+
var workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
130
|
+
var _normalizedConfig_output = normalizedConfig.output, enableInlineRouteManifests = _normalizedConfig_output.enableInlineRouteManifests, disableInlineRouteManifests = _normalizedConfig_output.disableInlineRouteManifests;
|
131
|
+
var inlineRouteManifests = disableInlineRouteManifests ? !disableInlineRouteManifests : enableInlineRouteManifests;
|
132
|
+
if (existNestedRoutes || routerManifest || workerSSR) {
|
133
|
+
var _normalizedConfig_output_distPath, _normalizedConfig_output1, _normalizedConfig_output2, _normalizedConfig_html, _normalizedConfig_security;
|
134
|
+
chain.plugin(pluginName).use(RouterPlugin, [
|
135
|
+
{
|
136
|
+
HtmlBundlerPlugin,
|
137
|
+
enableInlineRouteManifests: inlineRouteManifests,
|
138
|
+
staticJsDir: (_normalizedConfig_output1 = normalizedConfig.output) === null || _normalizedConfig_output1 === void 0 ? void 0 : (_normalizedConfig_output_distPath = _normalizedConfig_output1.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.js,
|
139
|
+
disableFilenameHash: (_normalizedConfig_output2 = normalizedConfig.output) === null || _normalizedConfig_output2 === void 0 ? void 0 : _normalizedConfig_output2.disableFilenameHash,
|
140
|
+
scriptLoading: (_normalizedConfig_html = normalizedConfig.html) === null || _normalizedConfig_html === void 0 ? void 0 : _normalizedConfig_html.scriptLoading,
|
141
|
+
nonce: (_normalizedConfig_security = normalizedConfig.security) === null || _normalizedConfig_security === void 0 ? void 0 : _normalizedConfig_security.nonce
|
142
|
+
}
|
143
|
+
]);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
function applyFilterEntriesBySSRConfig(param) {
|
147
|
+
var isProd = param.isProd, chain = param.chain, appNormalizedConfig = param.appNormalizedConfig;
|
148
|
+
var _this;
|
149
|
+
var serverConfig = appNormalizedConfig.server, outputConfig = appNormalizedConfig.output;
|
150
|
+
var entries = chain.entryPoints.entries();
|
151
|
+
if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof ((_this = outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
|
152
|
+
return;
|
153
|
+
}
|
154
|
+
if (typeof entries === "undefined") {
|
155
|
+
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
156
|
+
}
|
157
|
+
var entryNames = Object.keys(entries);
|
158
|
+
if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
159
|
+
return;
|
160
|
+
}
|
161
|
+
var ssgEntries = [];
|
162
|
+
if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
163
|
+
var ssg = outputConfig.ssg;
|
164
|
+
entryNames.forEach(function(name) {
|
165
|
+
if (ssg[name]) {
|
166
|
+
ssgEntries.push(name);
|
167
|
+
}
|
168
|
+
});
|
169
|
+
}
|
170
|
+
var _ref = serverConfig || {}, ssr = _ref.ssr, ssrByEntries = _ref.ssrByEntries;
|
171
|
+
entryNames.forEach(function(name) {
|
172
|
+
if (!ssgEntries.includes(name) && !name.includes("server-loaders") && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
|
173
|
+
chain.entryPoints.delete(name);
|
174
|
+
}
|
175
|
+
});
|
176
|
+
}
|
177
|
+
function applySSRLoaderEntry(chain, optinos, isServer) {
|
178
|
+
return _applySSRLoaderEntry.apply(this, arguments);
|
179
|
+
}
|
180
|
+
function _applySSRLoaderEntry() {
|
181
|
+
_applySSRLoaderEntry = _async_to_generator(function(chain, optinos, isServer) {
|
182
|
+
var appContext, internalDirectory, entrypoints;
|
183
|
+
return _ts_generator(this, function(_state) {
|
184
|
+
switch (_state.label) {
|
185
|
+
case 0:
|
186
|
+
appContext = optinos.appContext;
|
187
|
+
internalDirectory = appContext.internalDirectory;
|
188
|
+
entrypoints = appContext.entrypoints;
|
189
|
+
return [
|
190
|
+
4,
|
191
|
+
Promise.all(entrypoints.map(function() {
|
192
|
+
var _ref = _async_to_generator(function(entrypoint) {
|
193
|
+
var entryName, serverLoadersFile, err;
|
194
|
+
return _ts_generator(this, function(_state2) {
|
195
|
+
switch (_state2.label) {
|
196
|
+
case 0:
|
197
|
+
entryName = entrypoint.entryName;
|
198
|
+
serverLoadersFile = getServerCombinedModueFile(internalDirectory, entryName);
|
199
|
+
if (!isServer)
|
200
|
+
return [
|
201
|
+
3,
|
202
|
+
4
|
203
|
+
];
|
204
|
+
_state2.label = 1;
|
205
|
+
case 1:
|
206
|
+
_state2.trys.push([
|
207
|
+
1,
|
208
|
+
3,
|
209
|
+
,
|
210
|
+
4
|
211
|
+
]);
|
212
|
+
return [
|
213
|
+
4,
|
214
|
+
fs.access(serverLoadersFile, fs.constants.F_OK)
|
215
|
+
];
|
216
|
+
case 2:
|
217
|
+
_state2.sent();
|
218
|
+
chain.entry("".concat(entryName, "-server-loaders")).add(serverLoadersFile);
|
219
|
+
return [
|
220
|
+
3,
|
221
|
+
4
|
222
|
+
];
|
223
|
+
case 3:
|
224
|
+
err = _state2.sent();
|
225
|
+
return [
|
226
|
+
3,
|
227
|
+
4
|
228
|
+
];
|
229
|
+
case 4:
|
230
|
+
return [
|
231
|
+
2
|
232
|
+
];
|
233
|
+
}
|
234
|
+
});
|
235
|
+
});
|
236
|
+
return function(entrypoint) {
|
237
|
+
return _ref.apply(this, arguments);
|
238
|
+
};
|
239
|
+
}()))
|
240
|
+
];
|
241
|
+
case 1:
|
242
|
+
_state.sent();
|
243
|
+
return [
|
244
|
+
2
|
245
|
+
];
|
246
|
+
}
|
247
|
+
});
|
248
|
+
});
|
249
|
+
return _applySSRLoaderEntry.apply(this, arguments);
|
250
|
+
}
|
251
|
+
function applySSRDataLoader(chain, options) {
|
252
|
+
var normalizedConfig = options.normalizedConfig, appContext = options.appContext;
|
253
|
+
var appDirectory = appContext.appDirectory;
|
254
|
+
var _normalizedConfig_source = normalizedConfig.source, _normalizedConfig_source_entriesDir = _normalizedConfig_source.entriesDir, entriesDir = _normalizedConfig_source_entriesDir === void 0 ? "./src" : _normalizedConfig_source_entriesDir;
|
255
|
+
var absolutePath = path.resolve(appDirectory, entriesDir).split(path.sep).join("(\\\\|/)");
|
256
|
+
var reg = new RegExp("".concat(absolutePath, ".*\\.(loader|data|data.client)\\.[t|j]sx?$"));
|
257
|
+
chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
|
258
|
+
}
|
259
|
+
export {
|
260
|
+
builderPluginAdapterSSR
|
261
|
+
};
|
@@ -0,0 +1,51 @@
|
|
1
|
+
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
2
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
3
|
+
var HtmlAsyncChunkPlugin = /* @__PURE__ */ function() {
|
4
|
+
"use strict";
|
5
|
+
function HtmlAsyncChunkPlugin2(htmlWebpackPlugin) {
|
6
|
+
_class_call_check(this, HtmlAsyncChunkPlugin2);
|
7
|
+
this.name = "HtmlAsyncChunkPlugin";
|
8
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
9
|
+
}
|
10
|
+
var _proto = HtmlAsyncChunkPlugin2.prototype;
|
11
|
+
_proto.apply = function apply(compiler) {
|
12
|
+
var _this = this;
|
13
|
+
compiler.hooks.compilation.tap(this.name, function(compilation) {
|
14
|
+
var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
|
15
|
+
hooks.alterAssetTagGroups.tap(_this.name, function(assets) {
|
16
|
+
var tags = _to_consumable_array(assets.headTags).concat(_to_consumable_array(assets.bodyTags));
|
17
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
18
|
+
try {
|
19
|
+
for (var _iterator = tags[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
20
|
+
var tag = _step.value;
|
21
|
+
if (tag.tagName === "script") {
|
22
|
+
var attributes = tag.attributes;
|
23
|
+
if (attributes && attributes.defer === true) {
|
24
|
+
attributes.async = true;
|
25
|
+
delete attributes.defer;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
}
|
29
|
+
} catch (err) {
|
30
|
+
_didIteratorError = true;
|
31
|
+
_iteratorError = err;
|
32
|
+
} finally {
|
33
|
+
try {
|
34
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
35
|
+
_iterator.return();
|
36
|
+
}
|
37
|
+
} finally {
|
38
|
+
if (_didIteratorError) {
|
39
|
+
throw _iteratorError;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return assets;
|
44
|
+
});
|
45
|
+
});
|
46
|
+
};
|
47
|
+
return HtmlAsyncChunkPlugin2;
|
48
|
+
}();
|
49
|
+
export {
|
50
|
+
HtmlAsyncChunkPlugin
|
51
|
+
};
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
2
|
+
var BottomTemplatePlugin = /* @__PURE__ */ function() {
|
3
|
+
"use strict";
|
4
|
+
function BottomTemplatePlugin2(htmlWebpackPlugin) {
|
5
|
+
_class_call_check(this, BottomTemplatePlugin2);
|
6
|
+
this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
|
7
|
+
this.bodyRegExp = /(<\/\s*body\s*>)/i;
|
8
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
9
|
+
this.name = "bottom-template";
|
10
|
+
}
|
11
|
+
var _proto = BottomTemplatePlugin2.prototype;
|
12
|
+
_proto.apply = function apply(compiler) {
|
13
|
+
var _this = this;
|
14
|
+
compiler.hooks.compilation.tap(this.name, function(compilation) {
|
15
|
+
_this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function(data) {
|
16
|
+
var _data_plugin_options;
|
17
|
+
if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
|
18
|
+
return data;
|
19
|
+
}
|
20
|
+
if (_this.bottomTemplateReg.test(data.html)) {
|
21
|
+
data.html = data.html.replace(_this.bottomTemplateReg, "");
|
22
|
+
var bottomTemplate = data.plugin.options.bottomTemplate;
|
23
|
+
if (bottomTemplate) {
|
24
|
+
data.html = data.html.replace(_this.bodyRegExp, function(match) {
|
25
|
+
return "\n".concat(bottomTemplate, "\n").concat(match);
|
26
|
+
});
|
27
|
+
}
|
28
|
+
}
|
29
|
+
return data;
|
30
|
+
});
|
31
|
+
});
|
32
|
+
};
|
33
|
+
return BottomTemplatePlugin2;
|
34
|
+
}();
|
35
|
+
export {
|
36
|
+
BottomTemplatePlugin
|
37
|
+
};
|