@bleedingdev/modern-js-app-tools 3.2.0-ultramodern.99 → 3.4.0-ultramodern.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/baseline.js +12 -92
- 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 +41 -9
- package/dist/cjs/builder/generator/index.js +16 -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/adapterPrecompress.js +9 -5
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +39 -9
- 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 +41 -8
- 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 +12 -11
- package/dist/cjs/commands/info.js +9 -5
- package/dist/cjs/commands/inspect.js +12 -8
- package/dist/cjs/commands/runtime.js +50 -13
- 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 +12 -8
- package/dist/cjs/esm/ts-paths-loader.js +9 -5
- package/dist/cjs/index.js +23 -17
- 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 +10 -6
- 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/cloudflare.js +185 -7
- 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/templates/cloudflare-entry.mjs +141 -16
- 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 +19 -40
- 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/presetUltramodern.js +96 -7
- package/dist/cjs/rsbuild.js +55 -67
- package/dist/cjs/run/index.js +9 -5
- package/dist/cjs/types/config/cloudflareDeploy.js +18 -0
- package/dist/cjs/types/config/index.js +9 -5
- package/dist/cjs/types/config/precompress.js +18 -0
- package/dist/cjs/types/index.js +9 -5
- package/dist/cjs/ultramodern/designSystem.js +16 -12
- 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/baseline.mjs +3 -77
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +32 -4
- package/dist/esm/builder/generator/index.mjs +7 -0
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.mjs +31 -5
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.mjs +32 -3
- package/dist/esm/builder/shared/lazyCompilation.mjs +44 -0
- package/dist/esm/commands/index.mjs +2 -5
- package/dist/esm/commands/runtime.mjs +33 -3
- package/dist/esm/config/default.mjs +14 -1
- package/dist/esm/index.mjs +3 -2
- package/dist/esm/plugins/analyze/index.mjs +3 -1
- package/dist/esm/plugins/analyze/isDefaultExportFunction.mjs +1 -1
- package/dist/esm/plugins/deploy/platforms/cloudflare.mjs +176 -2
- package/dist/esm/plugins/deploy/platforms/templates/cloudflare-entry.mjs +141 -16
- package/dist/esm/plugins/deploy/utils/index.mjs +11 -36
- package/dist/esm/plugins/initialize/index.mjs +11 -2
- package/dist/esm/presetUltramodern.mjs +77 -3
- package/dist/esm/rsbuild.mjs +1 -8
- package/dist/esm/types/config/cloudflareDeploy.mjs +0 -0
- package/dist/esm/types/config/precompress.mjs +0 -0
- package/dist/esm-node/baseline.mjs +3 -77
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +32 -4
- package/dist/esm-node/builder/generator/index.mjs +7 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.mjs +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.mjs +31 -5
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.mjs +32 -3
- package/dist/esm-node/builder/shared/lazyCompilation.mjs +45 -0
- package/dist/esm-node/commands/index.mjs +2 -5
- package/dist/esm-node/commands/runtime.mjs +33 -3
- package/dist/esm-node/config/default.mjs +14 -1
- package/dist/esm-node/index.mjs +3 -2
- package/dist/esm-node/plugins/analyze/index.mjs +3 -1
- package/dist/esm-node/plugins/analyze/isDefaultExportFunction.mjs +1 -1
- package/dist/esm-node/plugins/deploy/platforms/cloudflare.mjs +176 -2
- package/dist/esm-node/plugins/deploy/platforms/templates/cloudflare-entry.mjs +141 -16
- package/dist/esm-node/plugins/deploy/utils/index.mjs +12 -36
- package/dist/esm-node/plugins/initialize/index.mjs +11 -2
- package/dist/esm-node/presetUltramodern.mjs +77 -3
- package/dist/esm-node/rsbuild.mjs +1 -8
- package/dist/esm-node/types/config/cloudflareDeploy.mjs +1 -0
- package/dist/esm-node/types/config/precompress.mjs +1 -0
- package/dist/types/baseline.d.ts +16 -46
- package/dist/types/builder/builder-rspack/index.d.ts +1 -1
- package/dist/types/builder/generator/index.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +3 -1
- package/dist/types/builder/shared/createCopyInfo.d.ts +1 -1
- package/dist/types/builder/shared/lazyCompilation.d.ts +43 -0
- package/dist/types/builder/shared/types.d.ts +10 -0
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +1 -1
- package/dist/types/commands/runtime.d.ts +1 -0
- package/dist/types/config/default.d.ts +6 -0
- package/dist/types/locale/index.d.ts +89 -2
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +2 -2
- package/dist/types/plugins/analyze/index.d.ts +1 -1
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/plugins/deploy/index.d.ts +1 -1
- package/dist/types/plugins/deploy/platforms/templates/cloudflare-entry.d.mts +1 -1
- package/dist/types/plugins/deploy/platforms/templates/netlify-entry.d.cts +1 -1
- package/dist/types/plugins/deploy/platforms/templates/vercel-entry.d.cts +1 -1
- package/dist/types/plugins/deploy/utils/generator.d.ts +2 -2
- package/dist/types/plugins/deploy/utils/index.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/plugins/serverRuntime.d.ts +1 -1
- package/dist/types/presetUltramodern.d.ts +52 -2
- package/dist/types/rsbuild.d.ts +1 -1
- package/dist/types/run/index.d.ts +1 -1
- package/dist/types/types/config/cloudflareDeploy.d.ts +79 -0
- package/dist/types/types/config/deploy.d.ts +9 -15
- package/dist/types/types/config/output.d.ts +4 -20
- package/dist/types/types/config/precompress.d.ts +20 -0
- package/dist/types/types/plugin.d.ts +20 -0
- package/dist/types/utils/getConfigFile.d.ts +1 -1
- package/dist/types/utils/loadPlugins.d.ts +2 -2
- package/package.json +26 -21
- package/dist/esm/rslib-runtime.mjs +0 -18
- package/dist/esm-node/rslib-runtime.mjs +0 -19
|
@@ -1,4 +1,78 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import node_fs from "node:fs";
|
|
2
|
+
import node_path from "node:path";
|
|
3
|
+
import { mergeConfig } from "@modern-js/plugin/cli";
|
|
4
|
+
const DEFAULT_OTLP_ENDPOINT = 'http://127.0.0.1:4318/v1/logs';
|
|
5
|
+
const DEFAULT_VICTORIA_METRICS_ENDPOINT = 'http://127.0.0.1:8428/api/v1/import/prometheus';
|
|
6
|
+
const resolveReactRouterPackageDir = (appDirectory)=>{
|
|
7
|
+
const resolveNodeModulePackageJson = (packageName, fromDirectory)=>{
|
|
8
|
+
let currentDirectory = node_path.resolve(fromDirectory);
|
|
9
|
+
while(true){
|
|
10
|
+
const packageJson = node_path.join(currentDirectory, 'node_modules', packageName, 'package.json');
|
|
11
|
+
if (node_fs.existsSync(packageJson)) return node_fs.realpathSync(packageJson);
|
|
12
|
+
const parentDirectory = node_path.dirname(currentDirectory);
|
|
13
|
+
if (parentDirectory === currentDirectory) return;
|
|
14
|
+
currentDirectory = parentDirectory;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const reactRouterPackageJson = resolveNodeModulePackageJson('react-router', appDirectory);
|
|
18
|
+
if (reactRouterPackageJson) return node_path.dirname(reactRouterPackageJson);
|
|
19
|
+
const reactRouterDomPackageJson = resolveNodeModulePackageJson('react-router-dom', appDirectory);
|
|
20
|
+
if (!reactRouterDomPackageJson) return;
|
|
21
|
+
const nestedReactRouterPackageJson = resolveNodeModulePackageJson('react-router', node_path.dirname(reactRouterDomPackageJson));
|
|
22
|
+
if (nestedReactRouterPackageJson) return node_path.dirname(nestedReactRouterPackageJson);
|
|
23
|
+
};
|
|
24
|
+
const setReactRouterBridgeSafeAliases = (chain, { isProd })=>{
|
|
25
|
+
const chainContext = chain.get('context');
|
|
26
|
+
const appDirectory = 'string' == typeof chainContext && chainContext.length > 0 ? chainContext : process.cwd();
|
|
27
|
+
const reactRouterPackageDir = resolveReactRouterPackageDir(appDirectory);
|
|
28
|
+
if (!reactRouterPackageDir) return;
|
|
29
|
+
const productionEntry = node_path.join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
30
|
+
const developmentEntry = node_path.join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
31
|
+
chain.resolve.alias.set('react-router$', isProd ? productionEntry : developmentEntry);
|
|
32
|
+
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
33
|
+
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
34
|
+
};
|
|
35
|
+
const createPresetUltramodernConfig = (options = {})=>{
|
|
36
|
+
const { appId = 'app', enableBffRequestId = true, enableTelemetry = true, enableTelemetryExporters, otlpEndpoint = process.env.MODERN_TELEMETRY_OTLP_ENDPOINT, victoriaMetricsEndpoint = process.env.MODERN_TELEMETRY_VICTORIA_ENDPOINT, telemetryFailLoudStartup = true, enableModuleFederationSSR = true } = options;
|
|
37
|
+
const server = {};
|
|
38
|
+
if (enableTelemetry) {
|
|
39
|
+
server.telemetry = {
|
|
40
|
+
enabled: true,
|
|
41
|
+
failLoudStartup: telemetryFailLoudStartup
|
|
42
|
+
};
|
|
43
|
+
if (false !== enableTelemetryExporters) {
|
|
44
|
+
const exporters = {};
|
|
45
|
+
if (true === enableTelemetryExporters || otlpEndpoint) exporters.otlp = {
|
|
46
|
+
enabled: true,
|
|
47
|
+
endpoint: otlpEndpoint || DEFAULT_OTLP_ENDPOINT
|
|
48
|
+
};
|
|
49
|
+
if (true === enableTelemetryExporters || victoriaMetricsEndpoint) exporters.victoriaMetrics = {
|
|
50
|
+
enabled: true,
|
|
51
|
+
endpoint: victoriaMetricsEndpoint || DEFAULT_VICTORIA_METRICS_ENDPOINT
|
|
52
|
+
};
|
|
53
|
+
if (Object.keys(exporters).length > 0) server.telemetry.exporters = exporters;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (enableModuleFederationSSR) server.ssr = {
|
|
57
|
+
mode: 'stream',
|
|
58
|
+
moduleFederationAppSSR: true
|
|
59
|
+
};
|
|
60
|
+
const presetConfig = {
|
|
61
|
+
output: {
|
|
62
|
+
precompress: true
|
|
63
|
+
},
|
|
64
|
+
server,
|
|
65
|
+
tools: {
|
|
66
|
+
bundlerChain: setReactRouterBridgeSafeAliases
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
if (enableBffRequestId) presetConfig.bff = {
|
|
70
|
+
requestId: appId
|
|
71
|
+
};
|
|
72
|
+
return presetConfig;
|
|
73
|
+
};
|
|
74
|
+
const presetUltramodern = (config, options = {})=>mergeConfig([
|
|
75
|
+
createPresetUltramodernConfig(options),
|
|
76
|
+
config
|
|
77
|
+
]);
|
|
4
78
|
export { createPresetUltramodernConfig, presetUltramodern };
|
package/dist/esm/rsbuild.mjs
CHANGED
|
@@ -1,18 +1,11 @@
|
|
|
1
1
|
import { parseRspackConfig } from "@modern-js/builder";
|
|
2
|
+
import { createConfigOptions } from "@modern-js/plugin/cli";
|
|
2
3
|
import { INTERNAL_RUNTIME_PLUGINS } from "@modern-js/utils";
|
|
3
4
|
import { builderPluginAdapterBasic, builderPluginAdapterHooks } from "./builder/shared/builderPlugins/index.mjs";
|
|
4
5
|
import { DEFAULT_CONFIG_FILE } from "./constants.mjs";
|
|
5
6
|
import { getConfigFile } from "./utils/getConfigFile.mjs";
|
|
6
7
|
import { loadInternalPlugins } from "./utils/loadPlugins.mjs";
|
|
7
|
-
import { __webpack_require__ } from "./rslib-runtime.mjs";
|
|
8
|
-
import * as __rspack_external__modern_js_plugin_cli_caa09fa2 from "@modern-js/plugin/cli";
|
|
9
|
-
__webpack_require__.add({
|
|
10
|
-
"@modern-js/plugin/cli?8936" (module) {
|
|
11
|
-
module.exports = __rspack_external__modern_js_plugin_cli_caa09fa2;
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
8
|
const MODERN_META_NAME = 'modern-js';
|
|
15
|
-
const { createConfigOptions: createConfigOptions } = __webpack_require__("@modern-js/plugin/cli?8936");
|
|
16
9
|
async function resolveModernRsbuildConfig(options) {
|
|
17
10
|
const { cwd = process.cwd(), metaName = MODERN_META_NAME } = options;
|
|
18
11
|
const configFile = options.configPath || getConfigFile(void 0, cwd);
|
|
File without changes
|
|
File without changes
|
|
@@ -1,79 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const resolveReactRouterPackageDir = ()=>{
|
|
6
|
-
const localRequire = createRequire(node_path.join(process.cwd(), 'package.json'));
|
|
7
|
-
try {
|
|
8
|
-
const reactRouterDomPackageJson = localRequire.resolve('react-router-dom/package.json', {
|
|
9
|
-
paths: [
|
|
10
|
-
process.cwd()
|
|
11
|
-
]
|
|
12
|
-
});
|
|
13
|
-
const reactRouterPackageJson = localRequire.resolve('react-router/package.json', {
|
|
14
|
-
paths: [
|
|
15
|
-
node_path.dirname(reactRouterDomPackageJson)
|
|
16
|
-
]
|
|
17
|
-
});
|
|
18
|
-
return node_path.dirname(reactRouterPackageJson);
|
|
19
|
-
} catch {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
const setReactRouterBridgeSafeAliases = (chain)=>{
|
|
24
|
-
const reactRouterPackageDir = resolveReactRouterPackageDir();
|
|
25
|
-
if (!reactRouterPackageDir) return;
|
|
26
|
-
const productionEntry = node_path.join(reactRouterPackageDir, 'dist/production/index.mjs');
|
|
27
|
-
const developmentEntry = node_path.join(reactRouterPackageDir, 'dist/development/index.mjs');
|
|
28
|
-
chain.resolve.alias.set('react-router$', productionEntry);
|
|
29
|
-
chain.resolve.alias.set('react-router/dist/production/index.js', productionEntry);
|
|
30
|
-
chain.resolve.alias.set('react-router/dist/development/index.js', developmentEntry);
|
|
31
|
-
};
|
|
32
|
-
const createAppBaselineConfig = (options = {})=>{
|
|
33
|
-
const { appId = 'app', enableBffRequestId = true, enableTelemetry = true, enableTelemetryExporters = true, otlpEndpoint = process.env.MODERN_TELEMETRY_OTLP_ENDPOINT || 'http://127.0.0.1:4318/v1/logs', victoriaMetricsEndpoint = process.env.MODERN_TELEMETRY_VICTORIA_ENDPOINT || 'http://127.0.0.1:8428/api/v1/import/prometheus', telemetryFailLoudStartup = true, enableModuleFederationSSR = true } = options;
|
|
34
|
-
const server = {};
|
|
35
|
-
if (enableTelemetry) {
|
|
36
|
-
server.telemetry = {
|
|
37
|
-
enabled: true,
|
|
38
|
-
failLoudStartup: telemetryFailLoudStartup
|
|
39
|
-
};
|
|
40
|
-
if (enableTelemetryExporters) server.telemetry.exporters = {
|
|
41
|
-
otlp: {
|
|
42
|
-
enabled: true,
|
|
43
|
-
endpoint: otlpEndpoint
|
|
44
|
-
},
|
|
45
|
-
victoriaMetrics: {
|
|
46
|
-
enabled: true,
|
|
47
|
-
endpoint: victoriaMetricsEndpoint
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
if (enableModuleFederationSSR) server.ssr = {
|
|
52
|
-
mode: 'stream',
|
|
53
|
-
moduleFederationAppSSR: true
|
|
54
|
-
};
|
|
55
|
-
const baselineConfig = {
|
|
56
|
-
output: {
|
|
57
|
-
precompress: true
|
|
58
|
-
},
|
|
59
|
-
performance: {
|
|
60
|
-
rsdoctor: {
|
|
61
|
-
enabled: 'production' === process.env.NODE_ENV,
|
|
62
|
-
disableClientServer: true
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
server,
|
|
66
|
-
tools: {
|
|
67
|
-
bundlerChain: setReactRouterBridgeSafeAliases
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
if (enableBffRequestId) baselineConfig.bff = {
|
|
71
|
-
requestId: appId
|
|
72
|
-
};
|
|
73
|
-
return baselineConfig;
|
|
74
|
-
};
|
|
75
|
-
const withAppBaseline = (config, options = {})=>mergeConfig([
|
|
76
|
-
createAppBaselineConfig(options),
|
|
77
|
-
config
|
|
78
|
-
]);
|
|
2
|
+
import { createPresetUltramodernConfig, presetUltramodern } from "./presetUltramodern.mjs";
|
|
3
|
+
const createAppBaselineConfig = createPresetUltramodernConfig;
|
|
4
|
+
const withAppBaseline = presetUltramodern;
|
|
79
5
|
export { createAppBaselineConfig, withAppBaseline };
|
|
@@ -17,6 +17,20 @@ const JS_OR_TS_EXTS = [
|
|
|
17
17
|
'.mjs',
|
|
18
18
|
'.cjs'
|
|
19
19
|
];
|
|
20
|
+
const CLOUDFLARE_WORKER_NODE_BUILTINS = [
|
|
21
|
+
'async_hooks',
|
|
22
|
+
'buffer',
|
|
23
|
+
'crypto',
|
|
24
|
+
'events',
|
|
25
|
+
'fs/promises',
|
|
26
|
+
'module',
|
|
27
|
+
'path',
|
|
28
|
+
'process',
|
|
29
|
+
'stream',
|
|
30
|
+
'string_decoder',
|
|
31
|
+
'url',
|
|
32
|
+
'util'
|
|
33
|
+
];
|
|
20
34
|
const CLOUDFLARE_WORKER_COMPAT_TEMPLATE_DIR = node_path.resolve(getBuilderEnvironments_dirname, '../../plugins/deploy/platforms/templates');
|
|
21
35
|
function findExistingFile(candidates) {
|
|
22
36
|
return candidates.find((candidate)=>node_fs.existsSync(candidate));
|
|
@@ -60,6 +74,21 @@ function setAliasIfPresent(alias, name, value) {
|
|
|
60
74
|
function getCloudflareWorkerCompatFile(file) {
|
|
61
75
|
return node_path.join(CLOUDFLARE_WORKER_COMPAT_TEMPLATE_DIR, file);
|
|
62
76
|
}
|
|
77
|
+
function getCloudflareWorkerNodeExternals() {
|
|
78
|
+
return Object.fromEntries(CLOUDFLARE_WORKER_NODE_BUILTINS.flatMap((builtin)=>{
|
|
79
|
+
const nodeBuiltin = `node:${builtin}`;
|
|
80
|
+
return [
|
|
81
|
+
[
|
|
82
|
+
builtin,
|
|
83
|
+
`module-import ${nodeBuiltin}`
|
|
84
|
+
],
|
|
85
|
+
[
|
|
86
|
+
nodeBuiltin,
|
|
87
|
+
`module-import ${nodeBuiltin}`
|
|
88
|
+
]
|
|
89
|
+
];
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
63
92
|
function getEffectBffEntry(normalizedConfig, appContext) {
|
|
64
93
|
if (!normalizedConfig.bff || 'hono' === normalizedConfig.bff.runtimeFramework) return;
|
|
65
94
|
const configuredEntry = normalizedConfig.bff.effect?.entry;
|
|
@@ -181,12 +210,13 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
|
|
|
181
210
|
chain.merge({
|
|
182
211
|
experiments: {
|
|
183
212
|
outputModule: true
|
|
184
|
-
}
|
|
213
|
+
},
|
|
214
|
+
externals: getCloudflareWorkerNodeExternals(),
|
|
215
|
+
externalsType: 'module-import'
|
|
185
216
|
});
|
|
186
217
|
chain.output.module(true).library({
|
|
187
218
|
type: 'module'
|
|
188
219
|
}).chunkFormat('module').chunkLoading('import').workerChunkLoading('import');
|
|
189
|
-
chain.target('webworker');
|
|
190
220
|
chain.plugins.delete('plugin-module-federation');
|
|
191
221
|
if (tanstackRouterSsrServerFile) {
|
|
192
222
|
chain.resolve.alias.set('@tanstack/router-core/ssr/server$', tanstackRouterSsrServerFile);
|
|
@@ -216,8 +246,6 @@ function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig)
|
|
|
216
246
|
chain.resolve.alias.set('react-server-dom-rspack/server.node', 'react-server-dom-rspack/server.edge');
|
|
217
247
|
chain.resolve.alias.set('react-server-dom-rspack/client.node$', 'react-server-dom-rspack/client.edge');
|
|
218
248
|
chain.resolve.alias.set('react-server-dom-rspack/client.node', 'react-server-dom-rspack/client.edge');
|
|
219
|
-
chain.resolve.fallback.set('async_hooks', false);
|
|
220
|
-
chain.resolve.fallback.set('node:async_hooks', false);
|
|
221
249
|
chain.resolve.fallback.set('fs', false);
|
|
222
250
|
chain.resolve.fallback.set('node:fs', false);
|
|
223
251
|
}
|
|
@@ -17,6 +17,13 @@ async function generateBuilder(options, bundlerType) {
|
|
|
17
17
|
else mergedEnvironments[name] = builderConfig.environments[name];
|
|
18
18
|
builderConfig.environments = mergedEnvironments;
|
|
19
19
|
} else builderConfig.environments = environments;
|
|
20
|
+
const hooks = appContext._internalContext.pluginAPI?.getHooks();
|
|
21
|
+
if (hooks?.modifyBuilderEnvironments) {
|
|
22
|
+
const { environments: modifiedEnvironments } = await hooks.modifyBuilderEnvironments.call({
|
|
23
|
+
environments: builderConfig.environments
|
|
24
|
+
});
|
|
25
|
+
builderConfig.environments = modifiedEnvironments;
|
|
26
|
+
}
|
|
20
27
|
const builder = await createBuilder({
|
|
21
28
|
cwd: appContext.appDirectory,
|
|
22
29
|
rscClientRuntimePath: `@${appContext.metaName}/runtime/rsc/client`,
|
|
@@ -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
|
|
@@ -72,7 +97,8 @@ function applyRouterPlugin(chain, pluginName, options, HtmlBundlerPlugin) {
|
|
|
72
97
|
staticJsDir: normalizedConfig.output?.distPath?.js,
|
|
73
98
|
disableFilenameHash: normalizedConfig.output?.filenameHash === false,
|
|
74
99
|
scriptLoading: normalizedConfig.html?.scriptLoading,
|
|
75
|
-
nonce: normalizedConfig.security?.nonce
|
|
100
|
+
nonce: normalizedConfig.security?.nonce,
|
|
101
|
+
useRsc: isUseRsc(normalizedConfig)
|
|
76
102
|
}
|
|
77
103
|
]);
|
|
78
104
|
}
|
|
@@ -65,6 +65,25 @@ class RouterPlugin {
|
|
|
65
65
|
routeAssets: {}
|
|
66
66
|
});
|
|
67
67
|
const prevManifest = JSON.parse(prevManifestStr);
|
|
68
|
+
const namedChunkGroupInstances = new Map();
|
|
69
|
+
for (const cg of compilation.chunkGroups || [])if (cg.name) namedChunkGroupInstances.set(cg.name, cg);
|
|
70
|
+
const collectDescendantCssAssets = (name)=>{
|
|
71
|
+
const root = namedChunkGroupInstances.get(name);
|
|
72
|
+
if (!root) return [];
|
|
73
|
+
const cssFiles = new Set();
|
|
74
|
+
const visited = new Set();
|
|
75
|
+
const stack = [
|
|
76
|
+
...root.childrenIterable
|
|
77
|
+
];
|
|
78
|
+
while(stack.length){
|
|
79
|
+
const child = stack.pop();
|
|
80
|
+
if (visited.has(child)) continue;
|
|
81
|
+
visited.add(child);
|
|
82
|
+
for (const chunk of child.chunks)for (const file of chunk.files)if (/\.css$/.test(file)) cssFiles.add(publicPath ? normalizePath(publicPath) + file : file);
|
|
83
|
+
for (const c of child.childrenIterable)stack.push(c);
|
|
84
|
+
}
|
|
85
|
+
return Array.from(cssFiles);
|
|
86
|
+
};
|
|
68
87
|
const asyncEntryNames = [];
|
|
69
88
|
for (const [name, chunkGroup] of Object.entries(namedChunkGroups)){
|
|
70
89
|
if (name.startsWith('async-')) asyncEntryNames.push(name);
|
|
@@ -72,7 +91,12 @@ class RouterPlugin {
|
|
|
72
91
|
const filename = asset.name;
|
|
73
92
|
return publicPath ? normalizePath(publicPath) + filename : filename;
|
|
74
93
|
});
|
|
75
|
-
const
|
|
94
|
+
const directCssAssets = assets.filter((asset)=>/\.css$/.test(asset));
|
|
95
|
+
const descendantCssAssets = collectDescendantCssAssets(name).filter((asset)=>!directCssAssets.includes(asset));
|
|
96
|
+
const referenceCssAssets = [
|
|
97
|
+
...directCssAssets,
|
|
98
|
+
...descendantCssAssets
|
|
99
|
+
];
|
|
76
100
|
routeAssets[name] = {
|
|
77
101
|
chunkIds: chunkGroup.chunks,
|
|
78
102
|
assets,
|
|
@@ -114,10 +138,14 @@ class RouterPlugin {
|
|
|
114
138
|
const manifest = {
|
|
115
139
|
routeAssets: relatedAssets
|
|
116
140
|
};
|
|
141
|
+
const { useRsc } = this;
|
|
117
142
|
const injectedContent = `
|
|
118
143
|
;(function(){
|
|
119
144
|
window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v)=>{
|
|
120
|
-
if (('assets' === k || 'referenceCssAssets' === k) && Array.isArray(v))
|
|
145
|
+
if (('assets' === k || 'referenceCssAssets' === k) && Array.isArray(v)) {
|
|
146
|
+
if (!useRsc) return;
|
|
147
|
+
return v.map((item)=>item.replace(publicPath, ''));
|
|
148
|
+
}
|
|
121
149
|
return v;
|
|
122
150
|
})};
|
|
123
151
|
})();
|
|
@@ -145,7 +173,7 @@ class RouterPlugin {
|
|
|
145
173
|
});
|
|
146
174
|
});
|
|
147
175
|
}
|
|
148
|
-
constructor({ staticJsDir = 'static/js', HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = 'defer', nonce }){
|
|
176
|
+
constructor({ staticJsDir = 'static/js', HtmlBundlerPlugin, enableInlineRouteManifests, disableFilenameHash = false, scriptLoading = 'defer', nonce, useRsc = false }){
|
|
149
177
|
this.name = 'RouterPlugin';
|
|
150
178
|
this.HtmlBundlerPlugin = HtmlBundlerPlugin;
|
|
151
179
|
this.enableInlineRouteManifests = enableInlineRouteManifests;
|
|
@@ -153,6 +181,7 @@ class RouterPlugin {
|
|
|
153
181
|
this.disableFilenameHash = disableFilenameHash;
|
|
154
182
|
this.scriptLoading = scriptLoading;
|
|
155
183
|
this.nonce = nonce;
|
|
184
|
+
this.useRsc = useRsc;
|
|
156
185
|
}
|
|
157
186
|
}
|
|
158
187
|
export { RouterPlugin };
|
|
@@ -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 };
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { i18n, localeKeys } from "../locale/index.mjs";
|
|
3
|
-
import { runtimeCommand } from "./runtime.mjs";
|
|
4
3
|
const devCommand = async (program, api)=>{
|
|
5
4
|
program.command('dev').alias('start').usage('[options]').description(i18n.t(localeKeys.command.dev.describe)).option('-c --config <config>', i18n.t(localeKeys.command.shared.config)).option('-e --entry [entry...]', i18n.t(localeKeys.command.dev.entry)).option('--analyze', i18n.t(localeKeys.command.shared.analyze)).option('--api-only', i18n.t(localeKeys.command.dev.apiOnly)).option('--web-only', i18n.t(localeKeys.command.dev.webOnly)).action(async (options)=>{
|
|
6
5
|
const { dev } = await import("./dev.mjs");
|
|
@@ -42,7 +41,5 @@ const infoCommand = (program, api)=>{
|
|
|
42
41
|
await info(api, options);
|
|
43
42
|
});
|
|
44
43
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
export { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, runtimeOperationsCommand, serverCommand };
|
|
44
|
+
export { runtimeCommand } from "./runtime.mjs";
|
|
45
|
+
export { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, serverCommand };
|
|
@@ -55,9 +55,39 @@ const parseResponseBody = async (response)=>{
|
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
|
+
const INDENT_STEP = ' ';
|
|
59
|
+
const formatScalar = (value)=>'string' == typeof value ? value : JSON.stringify(value) ?? 'undefined';
|
|
60
|
+
const formatHumanReadableLines = (value, indent)=>{
|
|
61
|
+
if (Array.isArray(value)) {
|
|
62
|
+
if (0 === value.length) return [
|
|
63
|
+
`${indent}(empty)`
|
|
64
|
+
];
|
|
65
|
+
return value.flatMap((entry)=>null !== entry && 'object' == typeof entry ? [
|
|
66
|
+
`${indent}-`,
|
|
67
|
+
...formatHumanReadableLines(entry, indent + INDENT_STEP)
|
|
68
|
+
] : [
|
|
69
|
+
`${indent}- ${formatScalar(entry)}`
|
|
70
|
+
]);
|
|
71
|
+
}
|
|
72
|
+
if (null !== value && 'object' == typeof value) {
|
|
73
|
+
const entries = Object.entries(value);
|
|
74
|
+
if (0 === entries.length) return [
|
|
75
|
+
`${indent}(empty)`
|
|
76
|
+
];
|
|
77
|
+
return entries.flatMap(([key, entry])=>null !== entry && 'object' == typeof entry ? [
|
|
78
|
+
`${indent}${key}:`,
|
|
79
|
+
...formatHumanReadableLines(entry, indent + INDENT_STEP)
|
|
80
|
+
] : [
|
|
81
|
+
`${indent}${key}: ${formatScalar(entry)}`
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
return [
|
|
85
|
+
`${indent}${formatScalar(value)}`
|
|
86
|
+
];
|
|
87
|
+
};
|
|
88
|
+
const formatRuntimeOutput = (payload, jsonOnly)=>jsonOnly ? JSON.stringify(payload, null, 2) : formatHumanReadableLines(payload, '').join('\n');
|
|
58
89
|
const printOutput = (payload, jsonOnly)=>{
|
|
59
|
-
|
|
60
|
-
console.log(JSON.stringify(payload, null, 2));
|
|
90
|
+
console.log(formatRuntimeOutput(payload, jsonOnly));
|
|
61
91
|
};
|
|
62
92
|
const createRuntimeFallbackSignalPayload = (options)=>{
|
|
63
93
|
const payload = {
|
|
@@ -114,4 +144,4 @@ const runtimeCommand = async (program, _api)=>{
|
|
|
114
144
|
printOutput(responsePayload, options.json);
|
|
115
145
|
});
|
|
116
146
|
};
|
|
117
|
-
export { createRuntimeFallbackSignalPayload, resolveRuntimeEndpoint, resolveToken, runtimeCommand };
|
|
147
|
+
export { createRuntimeFallbackSignalPayload, formatRuntimeOutput, resolveRuntimeEndpoint, resolveToken, runtimeCommand };
|
|
@@ -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 };
|
package/dist/esm-node/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { getLocaleLanguage } from "@modern-js/i18n-utils/language-detector";
|
|
|
5
5
|
import { createAsyncHook } from "@modern-js/plugin";
|
|
6
6
|
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
|
7
7
|
import path from "path";
|
|
8
|
-
import { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand,
|
|
8
|
+
import { buildCommand, deployCommand, devCommand, infoCommand, inspectCommand, runtimeCommand, serverCommand } from "./commands/index.mjs";
|
|
9
9
|
import { compatPlugin } from "./compat/index.mjs";
|
|
10
10
|
import { DEFAULT_RUNTIME_CONFIG_FILE } from "./constants.mjs";
|
|
11
11
|
import { i18n } from "./locale/index.mjs";
|
|
@@ -45,6 +45,7 @@ const appTools = ()=>({
|
|
|
45
45
|
deploy: createAsyncHook(),
|
|
46
46
|
checkEntryPoint: createAsyncHook(),
|
|
47
47
|
modifyEntrypoints: createAsyncHook(),
|
|
48
|
+
modifyBuilderEnvironments: createAsyncHook(),
|
|
48
49
|
modifyFileSystemRoutes: createAsyncHook(),
|
|
49
50
|
generateEntryCode: createAsyncHook(),
|
|
50
51
|
onBeforeGenerateRoutes: createAsyncHook(),
|
|
@@ -73,7 +74,7 @@ const appTools = ()=>({
|
|
|
73
74
|
deployCommand(program, api);
|
|
74
75
|
inspectCommand(program, api);
|
|
75
76
|
infoCommand(program, api);
|
|
76
|
-
await
|
|
77
|
+
await runtimeCommand(program, api);
|
|
77
78
|
deprecatedCommands(program);
|
|
78
79
|
});
|
|
79
80
|
api.onPrepare(async ()=>{
|
|
@@ -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;
|