@modern-js/app-tools 3.2.1 → 3.3.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/dist/cjs/builder/builder-rspack/index.js +9 -5
- package/dist/cjs/builder/generator/adapterCopy.js +9 -5
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +9 -5
- package/dist/cjs/builder/generator/createCopyPattern.js +9 -5
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +9 -5
- package/dist/cjs/builder/generator/index.js +9 -5
- package/dist/cjs/builder/index.js +9 -5
- package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +9 -5
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +10 -6
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +37 -8
- package/dist/cjs/builder/shared/builderPlugins/builderHooks.js +12 -8
- package/dist/cjs/builder/shared/builderPlugins/index.js +9 -5
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +9 -5
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +12 -8
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +9 -5
- package/dist/cjs/builder/shared/bundlerPlugins/index.js +9 -5
- package/dist/cjs/builder/shared/createCopyInfo.js +9 -5
- package/dist/cjs/builder/shared/index.js +9 -5
- package/dist/cjs/builder/shared/lazyCompilation.js +94 -0
- package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +12 -8
- package/dist/cjs/commands/build.js +9 -5
- package/dist/cjs/commands/deploy.js +9 -5
- package/dist/cjs/commands/dev.js +9 -5
- package/dist/cjs/commands/index.js +9 -5
- package/dist/cjs/commands/info.js +9 -5
- package/dist/cjs/commands/inspect.js +12 -8
- package/dist/cjs/commands/serve.js +9 -5
- package/dist/cjs/compat/hooks.js +9 -5
- package/dist/cjs/compat/index.js +9 -5
- package/dist/cjs/compat/utils.js +9 -5
- package/dist/cjs/config/default.js +27 -7
- package/dist/cjs/config/index.js +9 -5
- package/dist/cjs/config/initialize/index.js +9 -5
- package/dist/cjs/config/initialize/inits.js +9 -5
- package/dist/cjs/constants.js +13 -9
- package/dist/cjs/defineConfig.js +12 -8
- package/dist/cjs/esm/register-esm.js +9 -5
- package/dist/cjs/esm/ts-node-loader.js +9 -5
- package/dist/cjs/esm/ts-paths-loader.js +9 -5
- package/dist/cjs/index.js +21 -16
- package/dist/cjs/locale/en.js +12 -8
- package/dist/cjs/locale/index.js +9 -5
- package/dist/cjs/locale/zh.js +12 -8
- package/dist/cjs/plugins/analyze/constants.js +14 -10
- package/dist/cjs/plugins/analyze/getBundleEntry.js +9 -5
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +9 -5
- package/dist/cjs/plugins/analyze/getHtmlTemplate.js +9 -5
- package/dist/cjs/plugins/analyze/getServerRoutes.js +9 -5
- package/dist/cjs/plugins/analyze/index.js +12 -6
- package/dist/cjs/plugins/analyze/isDefaultExportFunction.js +9 -5
- package/dist/cjs/plugins/analyze/templates.js +12 -8
- package/dist/cjs/plugins/analyze/utils.js +9 -5
- package/dist/cjs/plugins/deploy/index.js +9 -5
- package/dist/cjs/plugins/deploy/platforms/gh-pages.js +9 -5
- package/dist/cjs/plugins/deploy/platforms/netlify.js +9 -5
- package/dist/cjs/plugins/deploy/platforms/node.js +9 -5
- package/dist/cjs/plugins/deploy/platforms/vercel.js +9 -5
- package/dist/cjs/plugins/deploy/utils/generator.js +9 -5
- package/dist/cjs/plugins/deploy/utils/index.js +9 -5
- package/dist/cjs/plugins/initialize/index.js +19 -6
- package/dist/cjs/plugins/serverBuild.js +9 -5
- package/dist/cjs/plugins/serverRuntime.js +12 -8
- package/dist/cjs/rsbuild.js +9 -5
- package/dist/cjs/run/index.js +9 -5
- package/dist/cjs/types/config/index.js +9 -5
- package/dist/cjs/types/index.js +9 -5
- package/dist/cjs/utils/config.js +9 -5
- package/dist/cjs/utils/createServer.js +14 -10
- package/dist/cjs/utils/env.js +9 -5
- package/dist/cjs/utils/generateWatchFiles.js +9 -5
- package/dist/cjs/utils/getConfigFile.js +9 -5
- package/dist/cjs/utils/getSelectedEntries.js +9 -5
- package/dist/cjs/utils/initAppContext.js +9 -5
- package/dist/cjs/utils/loadPlugins.js +9 -5
- package/dist/cjs/utils/printInstructions.js +9 -5
- package/dist/cjs/utils/register.js +9 -5
- package/dist/cjs/utils/restart.js +9 -5
- package/dist/cjs/utils/routes.js +9 -5
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +29 -4
- package/dist/esm/builder/shared/lazyCompilation.mjs +44 -0
- package/dist/esm/config/default.mjs +14 -1
- package/dist/esm/plugins/analyze/index.mjs +3 -1
- package/dist/esm/plugins/initialize/index.mjs +11 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +29 -4
- package/dist/esm-node/builder/shared/lazyCompilation.mjs +45 -0
- package/dist/esm-node/config/default.mjs +14 -1
- package/dist/esm-node/plugins/analyze/index.mjs +3 -1
- package/dist/esm-node/plugins/initialize/index.mjs +11 -2
- package/dist/types/builder/shared/lazyCompilation.d.ts +43 -0
- package/dist/types/builder/shared/types.d.ts +10 -0
- package/dist/types/config/default.d.ts +6 -0
- package/dist/types/types/plugin.d.ts +14 -0
- package/package.json +18 -18
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -23,11 +27,6 @@ var __webpack_require__ = {};
|
|
|
23
27
|
})();
|
|
24
28
|
var __webpack_exports__ = {};
|
|
25
29
|
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
closeServer: ()=>closeServer,
|
|
28
|
-
getServer: ()=>getServer,
|
|
29
|
-
setServer: ()=>setServer
|
|
30
|
-
});
|
|
31
30
|
let server = null;
|
|
32
31
|
const getServer = ()=>server;
|
|
33
32
|
const setServer = (newServer)=>{
|
|
@@ -39,6 +38,11 @@ const closeServer = async ()=>{
|
|
|
39
38
|
server = null;
|
|
40
39
|
}
|
|
41
40
|
};
|
|
41
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
42
|
+
closeServer: closeServer,
|
|
43
|
+
getServer: getServer,
|
|
44
|
+
setServer: setServer
|
|
45
|
+
});
|
|
42
46
|
exports.closeServer = __webpack_exports__.closeServer;
|
|
43
47
|
exports.getServer = __webpack_exports__.getServer;
|
|
44
48
|
exports.setServer = __webpack_exports__.setServer;
|
package/dist/cjs/utils/env.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
3
|
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
9
13
|
};
|
|
10
14
|
})();
|
|
11
15
|
(()=>{
|
package/dist/cjs/utils/routes.js
CHANGED
|
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
|
|
|
10
10
|
};
|
|
11
11
|
})();
|
|
12
12
|
(()=>{
|
|
13
|
-
__webpack_require__.d = (exports1,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
14
|
+
var define = (defs, kind)=>{
|
|
15
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
[kind]: defs[key]
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
define(getters, "get");
|
|
21
|
+
define(values, "value");
|
|
18
22
|
};
|
|
19
23
|
})();
|
|
20
24
|
(()=>{
|
|
@@ -38,7 +38,7 @@ function applyBottomHtmlPlugin({ chain, options, CHAIN_ID, HtmlBundlerPlugin, ht
|
|
|
38
38
|
const baseTemplateParams = {
|
|
39
39
|
entryName,
|
|
40
40
|
title: modernConfig.html.title,
|
|
41
|
-
mountId: modernConfig.html.
|
|
41
|
+
mountId: modernConfig.html.mountId
|
|
42
42
|
};
|
|
43
43
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args)=>[
|
|
44
44
|
{
|
|
@@ -1,21 +1,30 @@
|
|
|
1
1
|
import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
|
|
2
|
-
import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
|
|
2
|
+
import { fs, isUseRsc, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
3
3
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
|
4
4
|
import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
|
|
5
5
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
|
|
6
|
+
import { aggregateEagerRouteComponentFiles, planSSRLazyCompilation } from "../lazyCompilation.mjs";
|
|
6
7
|
import * as __rspack_external_path from "path";
|
|
7
8
|
const builderPluginAdapterSSR = (options)=>({
|
|
8
9
|
name: 'builder-plugin-adapter-modern-ssr',
|
|
9
10
|
setup (api) {
|
|
10
|
-
const { normalizedConfig } = options;
|
|
11
|
-
api.modifyRsbuildConfig((config)=>
|
|
11
|
+
const { normalizedConfig, appContext, eagerRouteComponentFilesByEntry } = options;
|
|
12
|
+
api.modifyRsbuildConfig((config)=>{
|
|
13
|
+
const merged = mergeRsbuildConfig(config, {
|
|
12
14
|
html: {
|
|
13
15
|
inject: isStreamingSSR(normalizedConfig) ? 'head' : void 0
|
|
14
16
|
},
|
|
15
17
|
server: {
|
|
16
18
|
compress: isStreamingSSR(normalizedConfig) || isUseRsc(normalizedConfig) ? false : void 0
|
|
17
19
|
}
|
|
18
|
-
})
|
|
20
|
+
});
|
|
21
|
+
const lazyCompilation = getSSRLazyCompilation(merged.dev?.lazyCompilation, normalizedConfig, appContext, eagerRouteComponentFilesByEntry);
|
|
22
|
+
if (void 0 !== lazyCompilation) merged.dev = {
|
|
23
|
+
...merged.dev,
|
|
24
|
+
lazyCompilation
|
|
25
|
+
};
|
|
26
|
+
return merged;
|
|
27
|
+
});
|
|
19
28
|
api.modifyBundlerChain(async (chain, { target, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer, environment })=>{
|
|
20
29
|
const builderConfig = environment.config;
|
|
21
30
|
const { normalizedConfig } = options;
|
|
@@ -51,6 +60,22 @@ const isStreamingSSR = (userConfig)=>{
|
|
|
51
60
|
}
|
|
52
61
|
return false;
|
|
53
62
|
};
|
|
63
|
+
function getSSRLazyCompilation(current, normalizedConfig, appContext, eagerRouteComponentFilesByEntry) {
|
|
64
|
+
if (!current || isUseRsc(normalizedConfig) || !isStreamingSSR(normalizedConfig)) return;
|
|
65
|
+
const plan = planSSRLazyCompilation(current, aggregateEagerRouteComponentFiles(eagerRouteComponentFilesByEntry));
|
|
66
|
+
if (!plan.apply) {
|
|
67
|
+
if (plan.unresolvedByEntry) warnUnresolvedRouteComponents(appContext.appDirectory, plan.unresolvedByEntry);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
return plan.lazyCompilation;
|
|
71
|
+
}
|
|
72
|
+
const warnedLazyApps = new Set();
|
|
73
|
+
function warnUnresolvedRouteComponents(appDirectory, unresolvedByEntry) {
|
|
74
|
+
if (warnedLazyApps.has(appDirectory)) return;
|
|
75
|
+
warnedLazyApps.add(appDirectory);
|
|
76
|
+
const detail = Array.from(unresolvedByEntry).map(([entry, comps])=>`${entry}: ${comps.join(', ')}`).join('; ');
|
|
77
|
+
logger.warn(`[lazyCompilation] Skipped stream SSR route-eager optimization because some route components could not be resolved to a file (${detail}). Lazy compilation may break first-screen CSS/JS for these routes.`);
|
|
78
|
+
}
|
|
54
79
|
function applyAsyncChunkHtmlPlugin({ chain, modernConfig, HtmlBundlerPlugin }) {
|
|
55
80
|
if (isStreamingSSR(modernConfig) || isUseRsc(modernConfig)) chain.plugin('html-async-chunk').use(HtmlAsyncChunkPlugin, [
|
|
56
81
|
HtmlBundlerPlugin
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { collectRouteComponentFiles, normalizeModulePath } from "@modern-js/utils";
|
|
2
|
+
function aggregateEagerRouteComponentFiles(byEntry) {
|
|
3
|
+
const files = new Set();
|
|
4
|
+
const unresolvedByEntry = new Map();
|
|
5
|
+
if (byEntry) for (const [entryName, collection] of byEntry){
|
|
6
|
+
for (const file of collection.resolvedFiles)files.add(file);
|
|
7
|
+
if (collection.unresolvedSpecifiers.length > 0) unresolvedByEntry.set(entryName, collection.unresolvedSpecifiers);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
files,
|
|
11
|
+
unresolvedByEntry
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
|
|
15
|
+
const userTestFn = 'function' == typeof userTest ? userTest : userTest instanceof RegExp ? (m)=>userTest.test(m.resource || '') : ()=>true;
|
|
16
|
+
return (m)=>{
|
|
17
|
+
const resource = m.resource;
|
|
18
|
+
if (!resource) return userTestFn(m);
|
|
19
|
+
if (eagerRouteFiles.has(normalizeModulePath(resource))) return false;
|
|
20
|
+
return userTestFn(m);
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function planSSRLazyCompilation(current, info) {
|
|
24
|
+
if (!current) return {
|
|
25
|
+
apply: false
|
|
26
|
+
};
|
|
27
|
+
if (info.unresolvedByEntry.size > 0) return {
|
|
28
|
+
apply: false,
|
|
29
|
+
unresolvedByEntry: info.unresolvedByEntry
|
|
30
|
+
};
|
|
31
|
+
if (0 === info.files.size) return {
|
|
32
|
+
apply: false
|
|
33
|
+
};
|
|
34
|
+
const base = 'object' == typeof current ? current : {};
|
|
35
|
+
const userTest = current.test;
|
|
36
|
+
return {
|
|
37
|
+
apply: true,
|
|
38
|
+
lazyCompilation: {
|
|
39
|
+
...base,
|
|
40
|
+
test: buildSSRLazyCompilationTest(info.files, userTest)
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export { aggregateEagerRouteComponentFiles, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planSSRLazyCompilation };
|
|
@@ -88,4 +88,17 @@ function createDefaultConfig(appContext) {
|
|
|
88
88
|
builderPlugins: []
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
const isStreamSSRConfig = (ssr)=>{
|
|
92
|
+
if (!ssr) return false;
|
|
93
|
+
if ('boolean' == typeof ssr) return ssr;
|
|
94
|
+
return 'string' !== ssr.mode;
|
|
95
|
+
};
|
|
96
|
+
function isLazyCompilationSafeByDefault(userConfig) {
|
|
97
|
+
const { server, output } = userConfig;
|
|
98
|
+
if (output?.ssg || output?.ssgByEntries && Object.keys(output.ssgByEntries).length > 0) return false;
|
|
99
|
+
if (server?.rsc) return false;
|
|
100
|
+
if (server?.ssr && !isStreamSSRConfig(server.ssr)) return false;
|
|
101
|
+
if (server?.ssrByEntries && 'object' == typeof server.ssrByEntries && Object.values(server.ssrByEntries).some((ssr)=>Boolean(ssr) && !isStreamSSRConfig(ssr))) return false;
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
export { createDefaultConfig, isLazyCompilationSafeByDefault };
|
|
@@ -122,10 +122,12 @@ const analyze = ()=>({
|
|
|
122
122
|
entrypoints
|
|
123
123
|
});
|
|
124
124
|
const normalizedConfig = api.getNormalizedConfig();
|
|
125
|
+
const { eagerRouteComponentFilesByEntry } = api.getAppContext();
|
|
125
126
|
const createBuilderForModern = await createBuilderGenerator();
|
|
126
127
|
const builder = await createBuilderForModern({
|
|
127
128
|
normalizedConfig: normalizedConfig,
|
|
128
|
-
appContext: appContext
|
|
129
|
+
appContext: appContext,
|
|
130
|
+
eagerRouteComponentFilesByEntry
|
|
129
131
|
});
|
|
130
132
|
builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile, environments, isWatch })=>{
|
|
131
133
|
if (!isFirstCompile) return;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
|
|
2
|
-
import { createDefaultConfig } from "../../config/index.mjs";
|
|
2
|
+
import { createDefaultConfig, isLazyCompilationSafeByDefault } from "../../config/index.mjs";
|
|
3
3
|
const initialize = ()=>({
|
|
4
4
|
name: '@modern-js/plugin-initialize',
|
|
5
5
|
post: [
|
|
@@ -11,7 +11,16 @@ const initialize = ()=>({
|
|
|
11
11
|
setup (api) {
|
|
12
12
|
api.config(()=>{
|
|
13
13
|
const appContext = api.getAppContext();
|
|
14
|
-
|
|
14
|
+
const userConfig = api.getConfig();
|
|
15
|
+
const defaultConfig = createDefaultConfig(appContext);
|
|
16
|
+
if (userConfig.dev?.lazyCompilation === void 0 && isLazyCompilationSafeByDefault(userConfig)) defaultConfig.dev = {
|
|
17
|
+
...defaultConfig.dev,
|
|
18
|
+
lazyCompilation: {
|
|
19
|
+
imports: true,
|
|
20
|
+
entries: false
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
return defaultConfig;
|
|
15
24
|
});
|
|
16
25
|
api.modifyResolvedConfig(async (resolved)=>{
|
|
17
26
|
let appContext = api.getAppContext();
|
|
@@ -39,7 +39,7 @@ function applyBottomHtmlPlugin({ chain, options, CHAIN_ID, HtmlBundlerPlugin, ht
|
|
|
39
39
|
const baseTemplateParams = {
|
|
40
40
|
entryName,
|
|
41
41
|
title: modernConfig.html.title,
|
|
42
|
-
mountId: modernConfig.html.
|
|
42
|
+
mountId: modernConfig.html.mountId
|
|
43
43
|
};
|
|
44
44
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args)=>[
|
|
45
45
|
{
|
|
@@ -1,23 +1,32 @@
|
|
|
1
1
|
import __rslib_shim_module__ from "node:module";
|
|
2
2
|
const require = /*#__PURE__*/ __rslib_shim_module__.createRequire(/*#__PURE__*/ (()=>import.meta.url)());
|
|
3
3
|
import { SERVICE_WORKER_ENVIRONMENT_NAME, isHtmlDisabled } from "@modern-js/builder";
|
|
4
|
-
import { fs, isUseRsc, isUseSSRBundle } from "@modern-js/utils";
|
|
4
|
+
import { fs, isUseRsc, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
5
5
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
|
6
6
|
import { getServerCombinedModuleFile } from "../../../plugins/analyze/utils.mjs";
|
|
7
7
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins/index.mjs";
|
|
8
|
+
import { aggregateEagerRouteComponentFiles, planSSRLazyCompilation } from "../lazyCompilation.mjs";
|
|
8
9
|
import * as __rspack_external_path from "path";
|
|
9
10
|
const builderPluginAdapterSSR = (options)=>({
|
|
10
11
|
name: 'builder-plugin-adapter-modern-ssr',
|
|
11
12
|
setup (api) {
|
|
12
|
-
const { normalizedConfig } = options;
|
|
13
|
-
api.modifyRsbuildConfig((config)=>
|
|
13
|
+
const { normalizedConfig, appContext, eagerRouteComponentFilesByEntry } = options;
|
|
14
|
+
api.modifyRsbuildConfig((config)=>{
|
|
15
|
+
const merged = mergeRsbuildConfig(config, {
|
|
14
16
|
html: {
|
|
15
17
|
inject: isStreamingSSR(normalizedConfig) ? 'head' : void 0
|
|
16
18
|
},
|
|
17
19
|
server: {
|
|
18
20
|
compress: isStreamingSSR(normalizedConfig) || isUseRsc(normalizedConfig) ? false : void 0
|
|
19
21
|
}
|
|
20
|
-
})
|
|
22
|
+
});
|
|
23
|
+
const lazyCompilation = getSSRLazyCompilation(merged.dev?.lazyCompilation, normalizedConfig, appContext, eagerRouteComponentFilesByEntry);
|
|
24
|
+
if (void 0 !== lazyCompilation) merged.dev = {
|
|
25
|
+
...merged.dev,
|
|
26
|
+
lazyCompilation
|
|
27
|
+
};
|
|
28
|
+
return merged;
|
|
29
|
+
});
|
|
21
30
|
api.modifyBundlerChain(async (chain, { target, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer, environment })=>{
|
|
22
31
|
const builderConfig = environment.config;
|
|
23
32
|
const { normalizedConfig } = options;
|
|
@@ -53,6 +62,22 @@ const isStreamingSSR = (userConfig)=>{
|
|
|
53
62
|
}
|
|
54
63
|
return false;
|
|
55
64
|
};
|
|
65
|
+
function getSSRLazyCompilation(current, normalizedConfig, appContext, eagerRouteComponentFilesByEntry) {
|
|
66
|
+
if (!current || isUseRsc(normalizedConfig) || !isStreamingSSR(normalizedConfig)) return;
|
|
67
|
+
const plan = planSSRLazyCompilation(current, aggregateEagerRouteComponentFiles(eagerRouteComponentFilesByEntry));
|
|
68
|
+
if (!plan.apply) {
|
|
69
|
+
if (plan.unresolvedByEntry) warnUnresolvedRouteComponents(appContext.appDirectory, plan.unresolvedByEntry);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
return plan.lazyCompilation;
|
|
73
|
+
}
|
|
74
|
+
const warnedLazyApps = new Set();
|
|
75
|
+
function warnUnresolvedRouteComponents(appDirectory, unresolvedByEntry) {
|
|
76
|
+
if (warnedLazyApps.has(appDirectory)) return;
|
|
77
|
+
warnedLazyApps.add(appDirectory);
|
|
78
|
+
const detail = Array.from(unresolvedByEntry).map(([entry, comps])=>`${entry}: ${comps.join(', ')}`).join('; ');
|
|
79
|
+
logger.warn(`[lazyCompilation] Skipped stream SSR route-eager optimization because some route components could not be resolved to a file (${detail}). Lazy compilation may break first-screen CSS/JS for these routes.`);
|
|
80
|
+
}
|
|
56
81
|
function applyAsyncChunkHtmlPlugin({ chain, modernConfig, HtmlBundlerPlugin }) {
|
|
57
82
|
if (isStreamingSSR(modernConfig) || isUseRsc(modernConfig)) chain.plugin('html-async-chunk').use(HtmlAsyncChunkPlugin, [
|
|
58
83
|
HtmlBundlerPlugin
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import { collectRouteComponentFiles, normalizeModulePath } from "@modern-js/utils";
|
|
3
|
+
function aggregateEagerRouteComponentFiles(byEntry) {
|
|
4
|
+
const files = new Set();
|
|
5
|
+
const unresolvedByEntry = new Map();
|
|
6
|
+
if (byEntry) for (const [entryName, collection] of byEntry){
|
|
7
|
+
for (const file of collection.resolvedFiles)files.add(file);
|
|
8
|
+
if (collection.unresolvedSpecifiers.length > 0) unresolvedByEntry.set(entryName, collection.unresolvedSpecifiers);
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
files,
|
|
12
|
+
unresolvedByEntry
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function buildSSRLazyCompilationTest(eagerRouteFiles, userTest) {
|
|
16
|
+
const userTestFn = 'function' == typeof userTest ? userTest : userTest instanceof RegExp ? (m)=>userTest.test(m.resource || '') : ()=>true;
|
|
17
|
+
return (m)=>{
|
|
18
|
+
const resource = m.resource;
|
|
19
|
+
if (!resource) return userTestFn(m);
|
|
20
|
+
if (eagerRouteFiles.has(normalizeModulePath(resource))) return false;
|
|
21
|
+
return userTestFn(m);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function planSSRLazyCompilation(current, info) {
|
|
25
|
+
if (!current) return {
|
|
26
|
+
apply: false
|
|
27
|
+
};
|
|
28
|
+
if (info.unresolvedByEntry.size > 0) return {
|
|
29
|
+
apply: false,
|
|
30
|
+
unresolvedByEntry: info.unresolvedByEntry
|
|
31
|
+
};
|
|
32
|
+
if (0 === info.files.size) return {
|
|
33
|
+
apply: false
|
|
34
|
+
};
|
|
35
|
+
const base = 'object' == typeof current ? current : {};
|
|
36
|
+
const userTest = current.test;
|
|
37
|
+
return {
|
|
38
|
+
apply: true,
|
|
39
|
+
lazyCompilation: {
|
|
40
|
+
...base,
|
|
41
|
+
test: buildSSRLazyCompilationTest(info.files, userTest)
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export { aggregateEagerRouteComponentFiles, buildSSRLazyCompilationTest, collectRouteComponentFiles, normalizeModulePath, planSSRLazyCompilation };
|
|
@@ -89,4 +89,17 @@ function createDefaultConfig(appContext) {
|
|
|
89
89
|
builderPlugins: []
|
|
90
90
|
};
|
|
91
91
|
}
|
|
92
|
-
|
|
92
|
+
const isStreamSSRConfig = (ssr)=>{
|
|
93
|
+
if (!ssr) return false;
|
|
94
|
+
if ('boolean' == typeof ssr) return ssr;
|
|
95
|
+
return 'string' !== ssr.mode;
|
|
96
|
+
};
|
|
97
|
+
function isLazyCompilationSafeByDefault(userConfig) {
|
|
98
|
+
const { server, output } = userConfig;
|
|
99
|
+
if (output?.ssg || output?.ssgByEntries && Object.keys(output.ssgByEntries).length > 0) return false;
|
|
100
|
+
if (server?.rsc) return false;
|
|
101
|
+
if (server?.ssr && !isStreamSSRConfig(server.ssr)) return false;
|
|
102
|
+
if (server?.ssrByEntries && 'object' == typeof server.ssrByEntries && Object.values(server.ssrByEntries).some((ssr)=>Boolean(ssr) && !isStreamSSRConfig(ssr))) return false;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
export { createDefaultConfig, isLazyCompilationSafeByDefault };
|
|
@@ -123,10 +123,12 @@ const analyze = ()=>({
|
|
|
123
123
|
entrypoints
|
|
124
124
|
});
|
|
125
125
|
const normalizedConfig = api.getNormalizedConfig();
|
|
126
|
+
const { eagerRouteComponentFilesByEntry } = api.getAppContext();
|
|
126
127
|
const createBuilderForModern = await createBuilderGenerator();
|
|
127
128
|
const builder = await createBuilderForModern({
|
|
128
129
|
normalizedConfig: normalizedConfig,
|
|
129
|
-
appContext: appContext
|
|
130
|
+
appContext: appContext,
|
|
131
|
+
eagerRouteComponentFilesByEntry
|
|
130
132
|
});
|
|
131
133
|
builder.onBeforeBuild(async ({ bundlerConfigs, isFirstCompile, environments, isWatch })=>{
|
|
132
134
|
if (!isFirstCompile) return;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
|
|
3
|
-
import { createDefaultConfig } from "../../config/index.mjs";
|
|
3
|
+
import { createDefaultConfig, isLazyCompilationSafeByDefault } from "../../config/index.mjs";
|
|
4
4
|
const initialize = ()=>({
|
|
5
5
|
name: '@modern-js/plugin-initialize',
|
|
6
6
|
post: [
|
|
@@ -12,7 +12,16 @@ const initialize = ()=>({
|
|
|
12
12
|
setup (api) {
|
|
13
13
|
api.config(()=>{
|
|
14
14
|
const appContext = api.getAppContext();
|
|
15
|
-
|
|
15
|
+
const userConfig = api.getConfig();
|
|
16
|
+
const defaultConfig = createDefaultConfig(appContext);
|
|
17
|
+
if (userConfig.dev?.lazyCompilation === void 0 && isLazyCompilationSafeByDefault(userConfig)) defaultConfig.dev = {
|
|
18
|
+
...defaultConfig.dev,
|
|
19
|
+
lazyCompilation: {
|
|
20
|
+
imports: true,
|
|
21
|
+
entries: false
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
return defaultConfig;
|
|
16
25
|
});
|
|
17
26
|
api.modifyResolvedConfig(async (resolved)=>{
|
|
18
27
|
let appContext = api.getAppContext();
|