@modern-js/app-tools 2.5.1-alpha.0 → 2.5.1-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/cjs/analyze/generateCode.js +19 -13
  2. package/dist/cjs/analyze/getBundleEntry.js +1 -1
  3. package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +3 -3
  4. package/dist/cjs/builder/builder-webpack/index.js +11 -5
  5. package/dist/cjs/builder/generator/getBuilderTargets.js +1 -1
  6. package/dist/cjs/commands/dev.js +12 -14
  7. package/dist/cjs/commands/serve.js +17 -0
  8. package/dist/cjs/config/legacy/createToolsConfig.js +1 -4
  9. package/dist/esm/analyze/generateCode.js +37 -26
  10. package/dist/esm/analyze/getBundleEntry.js +2 -2
  11. package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
  12. package/dist/esm/builder/builder-webpack/index.js +11 -7
  13. package/dist/esm/builder/generator/getBuilderTargets.js +1 -1
  14. package/dist/esm/commands/dev.js +9 -8
  15. package/dist/esm/commands/serve.js +6 -1
  16. package/dist/esm/config/legacy/createToolsConfig.js +1 -4
  17. package/dist/esm-node/analyze/generateCode.js +20 -14
  18. package/dist/esm-node/analyze/getBundleEntry.js +2 -3
  19. package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -2
  20. package/dist/esm-node/builder/builder-webpack/index.js +12 -6
  21. package/dist/esm-node/builder/generator/getBuilderTargets.js +1 -1
  22. package/dist/esm-node/commands/dev.js +12 -14
  23. package/dist/esm-node/commands/serve.js +18 -1
  24. package/dist/esm-node/config/legacy/createToolsConfig.js +1 -4
  25. package/dist/js/modern/analyze/constants.js +3 -1
  26. package/dist/js/modern/analyze/getServerRoutes.js +5 -2
  27. package/dist/js/modern/analyze/index.js +47 -46
  28. package/dist/js/modern/analyze/nestedRoutes.js +32 -3
  29. package/dist/js/modern/analyze/templates.js +4 -10
  30. package/dist/js/modern/builder/builder-rspack/index.js +8 -0
  31. package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
  32. package/dist/js/modern/builder/builder-webpack/index.js +93 -0
  33. package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
  34. package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
  35. package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
  36. package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
  37. package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
  38. package/dist/js/modern/builder/generator/index.js +53 -0
  39. package/dist/js/modern/builder/index.js +13 -133
  40. package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
  41. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
  42. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
  43. package/dist/js/modern/builder/shared/index.js +3 -0
  44. package/dist/js/modern/builder/shared/types.js +0 -0
  45. package/dist/js/modern/config/default.js +2 -2
  46. package/dist/js/modern/config/index.js +3 -8
  47. package/dist/js/modern/config/initialize/index.js +12 -0
  48. package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
  49. package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
  50. package/dist/js/modern/index.js +18 -8
  51. package/dist/js/modern/initialize/index.js +36 -28
  52. package/dist/js/modern/locale/zh.js +1 -1
  53. package/dist/js/modern/types/utils.js +0 -0
  54. package/dist/js/node/analyze/constants.js +3 -1
  55. package/dist/js/node/analyze/getServerRoutes.js +3 -1
  56. package/dist/js/node/analyze/index.js +48 -47
  57. package/dist/js/node/analyze/nestedRoutes.js +32 -3
  58. package/dist/js/node/analyze/templates.js +4 -10
  59. package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
  60. package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  61. package/dist/js/node/builder/builder-webpack/index.js +118 -0
  62. package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
  63. package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
  64. package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
  65. package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
  66. package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
  67. package/dist/js/node/builder/generator/index.js +82 -0
  68. package/dist/js/node/builder/index.js +14 -123
  69. package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
  70. package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
  71. package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
  72. package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
  73. package/dist/js/node/builder/shared/index.js +19 -0
  74. package/dist/js/node/builder/shared/types.js +15 -0
  75. package/dist/js/node/config/default.js +2 -2
  76. package/dist/js/node/config/index.js +4 -19
  77. package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
  78. package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
  79. package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
  80. package/dist/js/node/index.js +18 -8
  81. package/dist/js/node/initialize/index.js +35 -28
  82. package/dist/js/node/locale/zh.js +1 -1
  83. package/dist/js/node/types/utils.js +15 -0
  84. package/dist/js/treeshaking/analyze/constants.js +3 -1
  85. package/dist/js/treeshaking/analyze/generateCode.js +14 -14
  86. package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
  87. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
  88. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  89. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
  90. package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
  91. package/dist/js/treeshaking/analyze/index.js +142 -137
  92. package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
  93. package/dist/js/treeshaking/analyze/templates.js +10 -13
  94. package/dist/js/treeshaking/analyze/utils.js +3 -3
  95. package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
  96. package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  97. package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
  98. package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
  99. package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
  100. package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
  101. package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
  102. package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
  103. package/dist/js/treeshaking/builder/generator/index.js +199 -0
  104. package/dist/js/treeshaking/builder/index.js +29 -228
  105. package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
  106. package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
  107. package/dist/js/treeshaking/builder/shared/index.js +3 -0
  108. package/dist/js/treeshaking/builder/shared/types.js +1 -0
  109. package/dist/js/treeshaking/commands/dev.js +2 -2
  110. package/dist/js/treeshaking/commands/serve.js +2 -2
  111. package/dist/js/treeshaking/config/default.js +2 -2
  112. package/dist/js/treeshaking/config/index.js +3 -3
  113. package/dist/js/treeshaking/config/initialize/index.js +10 -0
  114. package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
  115. package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
  116. package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
  117. package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
  118. package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
  119. package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
  120. package/dist/js/treeshaking/index.js +19 -12
  121. package/dist/js/treeshaking/initialize/index.js +36 -28
  122. package/dist/js/treeshaking/locale/zh.js +1 -1
  123. package/dist/js/treeshaking/types/utils.js +1 -0
  124. package/dist/js/treeshaking/utils/config.js +2 -2
  125. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
  126. package/dist/types/builder/builder-webpack/builderPlugins/compatModern.d.ts +7 -1
  127. package/package.json +6 -6
  128. package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
  129. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
  130. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
  131. package/dist/js/modern/config/initial/index.js +0 -16
  132. package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
  133. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
  134. package/dist/js/treeshaking/config/initial/index.js +0 -12
  135. /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
  136. /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  137. /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
  138. /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
  139. /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
  140. /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
  141. /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  142. /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
  143. /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
  144. /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
  145. /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
  146. /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
  147. /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
  148. /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
@@ -83,6 +83,7 @@ ${initialize || ""}`
83
83
  ).join("\n");
84
84
  };
85
85
  const generateCode = async (appContext, config, entrypoints, api) => {
86
+ var _a, _b, _c;
86
87
  const {
87
88
  internalDirectory,
88
89
  srcDirectory,
@@ -91,7 +92,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
91
92
  packageName
92
93
  } = appContext;
93
94
  const hookRunners = api.useHookRunners();
94
- const isV5 = (0, import_utils.isRouterV5)(config);
95
+ const isV5 = typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
95
96
  const { mountId } = config.html;
96
97
  const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
97
98
  await Promise.all(entrypoints.map(generateEntryCode));
@@ -110,18 +111,23 @@ const generateCode = async (appContext, config, entrypoints, api) => {
110
111
  internalDirAlias
111
112
  });
112
113
  }
113
- if (!isV5 && entrypoint.nestedRoutesEntry) {
114
- nestedRoute = await (0, import_nestedRoutes.walk)(
115
- entrypoint.nestedRoutesEntry,
116
- entrypoint.nestedRoutesEntry,
117
- {
118
- name: internalSrcAlias,
119
- basename: srcDirectory
120
- },
121
- entrypoint.entryName
122
- );
123
- if (nestedRoute) {
124
- initialRoutes.unshift(nestedRoute);
114
+ if (entrypoint.nestedRoutesEntry) {
115
+ if (!isV5) {
116
+ nestedRoute = await (0, import_nestedRoutes.walk)(
117
+ entrypoint.nestedRoutesEntry,
118
+ entrypoint.nestedRoutesEntry,
119
+ {
120
+ name: internalSrcAlias,
121
+ basename: srcDirectory
122
+ },
123
+ entrypoint.entryName
124
+ );
125
+ if (nestedRoute) {
126
+ initialRoutes.unshift(nestedRoute);
127
+ }
128
+ } else {
129
+ import_utils.logger.error("Nested routes is not supported in legacy mode.");
130
+ process.exit(1);
125
131
  }
126
132
  }
127
133
  const { routes } = await hookRunners.modifyFileSystemRoutes({
@@ -78,7 +78,7 @@ const getBundleEntry = (appContext, config) => {
78
78
  customBootstrap: value.customBootstrap && (0, import_utils.ensureAbsolutePath)(appDirectory, value.customBootstrap),
79
79
  fileSystemRoutes: import_utils.fs.statSync((0, import_utils.ensureAbsolutePath)(appDirectory, value.entry)).isDirectory() ? {} : void 0
80
80
  };
81
- if (entrypoint.fileSystemRoutes && (0, import_utils.isRouterV5)(config)) {
81
+ if (entrypoint.fileSystemRoutes) {
82
82
  entrypoint.nestedRoutesEntry = entrypoint.entry;
83
83
  }
84
84
  if (!ifAlreadyExists(defaults, entrypoint)) {
@@ -17,13 +17,13 @@ var __copyProps = (to, from, except, desc) => {
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
18
  var compatModern_exports = {};
19
19
  __export(compatModern_exports, {
20
- builderPluginCompatModern: () => builderPluginCompatModern
20
+ PluginCompatModern: () => PluginCompatModern
21
21
  });
22
22
  module.exports = __toCommonJS(compatModern_exports);
23
23
  var import_path = require("path");
24
24
  var import_shared = require("../../shared");
25
25
  var import_webpackPlugins = require("../webpackPlugins");
26
- const builderPluginCompatModern = (options) => ({
26
+ const PluginCompatModern = (options) => ({
27
27
  name: "builder-plugin-compat-modern",
28
28
  setup(api) {
29
29
  const { normalizedConfig: modernConfig, appContext } = options;
@@ -60,5 +60,5 @@ const builderPluginCompatModern = (options) => ({
60
60
  });
61
61
  // Annotate the CommonJS export names for ESM import in node:
62
62
  0 && (module.exports = {
63
- builderPluginCompatModern
63
+ PluginCompatModern
64
64
  });
@@ -27,6 +27,7 @@ __export(builder_webpack_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(builder_webpack_exports);
29
29
  var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
30
+ var import_utils = require("@modern-js/utils");
30
31
  var import_shared = require("../shared");
31
32
  var import_generator = require("../generator");
32
33
  var import_compatModern = require("./builderPlugins/compatModern");
@@ -56,15 +57,20 @@ function modifyOutputConfig(config, appContext) {
56
57
  async function applyBuilderPlugins(builder, options) {
57
58
  const { normalizedConfig } = options;
58
59
  if (!normalizedConfig.output.disableNodePolyfill) {
59
- const { builderPluginNodePolyfill } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
60
- builder.addPlugins([builderPluginNodePolyfill()]);
60
+ const { PluginNodePolyfill } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
61
+ builder.addPlugins([PluginNodePolyfill()]);
61
62
  }
62
63
  if (normalizedConfig.tools.esbuild) {
63
64
  const { esbuild: esbuildOptions } = normalizedConfig.tools;
64
- const { builderPluginEsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
65
- builder.addPlugins([builderPluginEsbuild(esbuildOptions)]);
65
+ const { PluginEsbuild } = await Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
66
+ builder.addPlugins([
67
+ PluginEsbuild({
68
+ loader: false,
69
+ minimize: (0, import_utils.applyOptionsChain)({}, esbuildOptions)
70
+ })
71
+ ]);
66
72
  }
67
- builder.addPlugins([(0, import_compatModern.builderPluginCompatModern)(options)]);
73
+ builder.addPlugins([(0, import_compatModern.PluginCompatModern)(options)]);
68
74
  }
69
75
  // Annotate the CommonJS export names for ESM import in node:
70
76
  0 && (module.exports = {
@@ -27,7 +27,7 @@ function getBuilderTargets(normalizedConfig) {
27
27
  if (useNodeTarget) {
28
28
  targets.push("node");
29
29
  }
30
- const useWorkerTarget = (0, import_utils.isServiceWorker)(normalizedConfig);
30
+ const useWorkerTarget = (0, import_utils.isProd)() ? (0, import_utils.isServiceWorker)(normalizedConfig) : false;
31
31
  if (useWorkerTarget) {
32
32
  targets.push("service-worker");
33
33
  }
@@ -27,7 +27,7 @@ var import_routes = require("../utils/routes");
27
27
  var import_config = require("../utils/config");
28
28
  var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
29
29
  const dev = async (api, options) => {
30
- var _a, _b;
30
+ var _a;
31
31
  if (options.analyze) {
32
32
  process.env.BUNDLE_ANALYZE = "true";
33
33
  }
@@ -59,9 +59,14 @@ const dev = async (api, options) => {
59
59
  dev: {
60
60
  port,
61
61
  https: normalizedConfig.dev.https,
62
- host: normalizedConfig.dev.host,
63
62
  ...(_a = normalizedConfig.tools) == null ? void 0 : _a.devServer
64
63
  },
64
+ appContext: {
65
+ appDirectory: appContext.appDirectory,
66
+ sharedDirectory: appContext.sharedDirectory,
67
+ apiDirectory: appContext.apiDirectory,
68
+ lambdaDirectory: appContext.lambdaDirectory
69
+ },
65
70
  pwd: appDirectory,
66
71
  config: normalizedConfig,
67
72
  serverConfigFile,
@@ -72,19 +77,12 @@ const dev = async (api, options) => {
72
77
  ...serverOptions,
73
78
  compiler: null
74
79
  });
75
- const host = ((_b = normalizedConfig.dev) == null ? void 0 : _b.host) || "localhost";
76
- app.listen(
77
- {
78
- port,
79
- host
80
- },
81
- async (err) => {
82
- if (err) {
83
- throw err;
84
- }
85
- (0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
80
+ app.listen(port, async (err) => {
81
+ if (err) {
82
+ throw err;
86
83
  }
87
- );
84
+ (0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
85
+ });
88
86
  } else {
89
87
  const { server } = await appContext.builder.startDevServer({
90
88
  printURLs: false,
@@ -46,6 +46,23 @@ const start = async (api) => {
46
46
  const app = await (0, import_prod_server.default)({
47
47
  pwd: appDirectory,
48
48
  config: userConfig,
49
+ appContext: {
50
+ sharedDirectory: (0, import_utils.getTargetDir)(
51
+ appContext.sharedDirectory,
52
+ appContext.appDirectory,
53
+ appContext.distDirectory
54
+ ),
55
+ apiDirectory: (0, import_utils.getTargetDir)(
56
+ appContext.apiDirectory,
57
+ appContext.appDirectory,
58
+ appContext.distDirectory
59
+ ),
60
+ lambdaDirectory: (0, import_utils.getTargetDir)(
61
+ appContext.lambdaDirectory,
62
+ appContext.appDirectory,
63
+ appContext.distDirectory
64
+ )
65
+ },
49
66
  serverConfigFile,
50
67
  internalPlugins: (0, import_createServer.injectDataLoaderPlugin)(serverInternalPlugins),
51
68
  apiOnly
@@ -56,10 +56,7 @@ function createToolsConfig(config) {
56
56
  devServer,
57
57
  tailwindcss,
58
58
  jest,
59
- esbuild: {
60
- loader: false,
61
- minimize: esbuild
62
- }
59
+ esbuild
63
60
  };
64
61
  }
65
62
  // Annotate the CommonJS export names for ESM import in node:
@@ -148,7 +148,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
148
148
  }
149
149
  };
150
150
  import path from "path";
151
- import { fs, getEntryOptions, isRouterV5, logger } from "@modern-js/utils";
151
+ import { fs, getEntryOptions, logger } from "@modern-js/utils";
152
152
  import { useResolvedConfigContext } from "@modern-js/core";
153
153
  import * as templates from "./templates";
154
154
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
@@ -240,7 +240,7 @@ var createImportStatements = function(statements) {
240
240
  };
241
241
  var generateCode = function() {
242
242
  var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
243
- var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
243
+ var _config_runtime, _config_runtime1, _config_runtime_router, internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
244
244
  function generateEntryCode(entrypoint) {
245
245
  return _generateEntryCode.apply(this, arguments);
246
246
  }
@@ -253,11 +253,11 @@ var generateCode = function() {
253
253
  entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
254
254
  if (!isAutoMount) return [
255
255
  3,
256
- 16
256
+ 17
257
257
  ];
258
258
  if (!fileSystemRoutes) return [
259
259
  3,
260
- 9
260
+ 10
261
261
  ];
262
262
  initialRoutes = [];
263
263
  nestedRoute = null;
@@ -270,7 +270,11 @@ var generateCode = function() {
270
270
  internalDirAlias: internalDirAlias
271
271
  });
272
272
  }
273
- if (!(!isV5 && entrypoint.nestedRoutesEntry)) return [
273
+ if (!entrypoint.nestedRoutesEntry) return [
274
+ 3,
275
+ 3
276
+ ];
277
+ if (!!isV5) return [
274
278
  3,
275
279
  2
276
280
  ];
@@ -286,8 +290,15 @@ var generateCode = function() {
286
290
  if (nestedRoute) {
287
291
  initialRoutes.unshift(nestedRoute);
288
292
  }
289
- _state.label = 2;
293
+ return [
294
+ 3,
295
+ 3
296
+ ];
290
297
  case 2:
298
+ logger.error("Nested routes is not supported in legacy mode.");
299
+ process.exit(1);
300
+ _state.label = 3;
301
+ case 3:
291
302
  return [
292
303
  4,
293
304
  hookRunners.modifyFileSystemRoutes({
@@ -295,7 +306,7 @@ var generateCode = function() {
295
306
  routes: initialRoutes
296
307
  })
297
308
  ];
298
- case 3:
309
+ case 4:
299
310
  routes = _state.sent().routes;
300
311
  config2 = useResolvedConfigContext();
301
312
  ssr = getEntryOptions(entryName, config2.server.ssr, config2.server.ssrByEntries, packageName);
@@ -327,18 +338,18 @@ var generateCode = function() {
327
338
  internalDirectory: internalDirectory
328
339
  })
329
340
  ];
330
- case 4:
341
+ case 5:
331
342
  return [
332
343
  4,
333
344
  _.apply(hookRunners, [
334
345
  (_tmp.code = _state.sent(), _tmp)
335
346
  ])
336
347
  ];
337
- case 5:
348
+ case 6:
338
349
  _ref = _state.sent(), code2 = _ref.code;
339
350
  if (!(entrypoint.nestedRoutesEntry && mode)) return [
340
351
  3,
341
- 8
352
+ 9
342
353
  ];
343
354
  routesServerFile = getServerLoadersFile(internalDirectory, entryName);
344
355
  code3 = templates.routesForServer({
@@ -348,19 +359,19 @@ var generateCode = function() {
348
359
  4,
349
360
  fs.ensureFile(routesServerFile)
350
361
  ];
351
- case 6:
362
+ case 7:
352
363
  _state.sent();
353
364
  return [
354
365
  4,
355
366
  fs.writeFile(routesServerFile, code3)
356
367
  ];
357
- case 7:
358
- _state.sent();
359
- _state.label = 8;
360
368
  case 8:
361
- fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
369
+ _state.sent();
362
370
  _state.label = 9;
363
371
  case 9:
372
+ fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
373
+ _state.label = 10;
374
+ case 10:
364
375
  return [
365
376
  4,
366
377
  hookRunners.modifyEntryImports({
@@ -374,7 +385,7 @@ var generateCode = function() {
374
385
  })
375
386
  })
376
387
  ];
377
- case 10:
388
+ case 11:
378
389
  _ref1 = _state.sent(), importStatements = _ref1.imports;
379
390
  return [
380
391
  4,
@@ -383,7 +394,7 @@ var generateCode = function() {
383
394
  plugins: []
384
395
  })
385
396
  ];
386
- case 11:
397
+ case 12:
387
398
  plugins = _state.sent().plugins;
388
399
  return [
389
400
  4,
@@ -396,7 +407,7 @@ var generateCode = function() {
396
407
  })
397
408
  })
398
409
  ];
399
- case 12:
410
+ case 13:
400
411
  _ref2 = _state.sent(), renderFunction = _ref2.code;
401
412
  return [
402
413
  4,
@@ -405,7 +416,7 @@ var generateCode = function() {
405
416
  exportStatement: "export default AppWrapper;"
406
417
  })
407
418
  ];
408
- case 13:
419
+ case 14:
409
420
  exportStatement = _state.sent().exportStatement;
410
421
  code = templates.index({
411
422
  mountId: mountId,
@@ -417,7 +428,7 @@ var generateCode = function() {
417
428
  entrypoint.entry = entryFile;
418
429
  if (!config.source.enableAsyncEntry) return [
419
430
  3,
420
- 15
431
+ 16
421
432
  ];
422
433
  return [
423
434
  4,
@@ -426,19 +437,19 @@ var generateCode = function() {
426
437
  code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
427
438
  })
428
439
  ];
429
- case 14:
440
+ case 15:
430
441
  _ref3 = _state.sent(), asyncEntryCode = _ref3.code;
431
442
  fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
432
443
  bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
433
444
  fs.outputFileSync(bootstrapFile, code, "utf8");
434
445
  return [
435
446
  3,
436
- 16
447
+ 17
437
448
  ];
438
- case 15:
439
- fs.outputFileSync(entryFile, code, "utf8");
440
- _state.label = 16;
441
449
  case 16:
450
+ fs.outputFileSync(entryFile, code, "utf8");
451
+ _state.label = 17;
452
+ case 17:
442
453
  return [
443
454
  2
444
455
  ];
@@ -452,7 +463,7 @@ var generateCode = function() {
452
463
  case 0:
453
464
  internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
454
465
  hookRunners = api.useHookRunners();
455
- isV5 = isRouterV5(config);
466
+ isV5 = typeof ((_config_runtime = config.runtime) === null || _config_runtime === void 0 ? void 0 : _config_runtime.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (_config_runtime1 = config.runtime) === null || _config_runtime1 === void 0 ? void 0 : (_config_runtime_router = _config_runtime1.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.mode) === "react-router-5";
456
467
  mountId = config.html.mountId;
457
468
  getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
458
469
  return [
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME, isRouterV5 } from "@modern-js/utils";
2
+ import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME } from "@modern-js/utils";
3
3
  import { getFileSystemEntry } from "./getFileSystemEntry";
4
4
  import { JS_EXTENSIONS } from "./constants";
5
5
  var ensureExtensions = function(file) {
@@ -43,7 +43,7 @@ var getBundleEntry = function(appContext, config) {
43
43
  customBootstrap: value.customBootstrap && ensureAbsolutePath(appDirectory, value.customBootstrap),
44
44
  fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value.entry)).isDirectory() ? {} : void 0
45
45
  };
46
- if (entrypoint.fileSystemRoutes && isRouterV5(config)) {
46
+ if (entrypoint.fileSystemRoutes) {
47
47
  entrypoint.nestedRoutesEntry = entrypoint.entry;
48
48
  }
49
49
  if (!ifAlreadyExists(defaults, entrypoint)) {
@@ -26,7 +26,7 @@ function _unsupportedIterableToArray(o, minLen) {
26
26
  import { join } from "path";
27
27
  import { createCopyPattern } from "../../shared";
28
28
  import { RouterPlugin } from "../webpackPlugins";
29
- var builderPluginCompatModern = function(options) {
29
+ var PluginCompatModern = function(options) {
30
30
  return {
31
31
  name: "builder-plugin-compat-modern",
32
32
  setup: function setup(api) {
@@ -61,4 +61,4 @@ var builderPluginCompatModern = function(options) {
61
61
  }
62
62
  };
63
63
  };
64
- export { builderPluginCompatModern };
64
+ export { PluginCompatModern };
@@ -200,9 +200,10 @@ var __generator = this && this.__generator || function(thisArg, body) {
200
200
  }
201
201
  };
202
202
  import { builderWebpackProvider } from "@modern-js/builder-webpack-provider";
203
+ import { applyOptionsChain } from "@modern-js/utils";
203
204
  import { createCopyPattern } from "../shared";
204
205
  import { generateBuilder } from "../generator";
205
- import { builderPluginCompatModern } from "./builderPlugins/compatModern";
206
+ import { PluginCompatModern } from "./builderPlugins/compatModern";
206
207
  function createWebpackBuilderForModern(options) {
207
208
  return generateBuilder(options, builderWebpackProvider, {
208
209
  modifyBuilderConfig: function modifyBuilderConfig(config) {
@@ -247,7 +248,7 @@ function applyBuilderPlugins(builder, options) {
247
248
  }
248
249
  function _applyBuilderPlugins() {
249
250
  _applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
250
- var normalizedConfig, builderPluginNodePolyfill, _normalizedConfig_tools, esbuildOptions, builderPluginEsbuild;
251
+ var normalizedConfig, PluginNodePolyfill, _normalizedConfig_tools, esbuildOptions, PluginEsbuild;
251
252
  return __generator(this, function(_state) {
252
253
  switch(_state.label){
253
254
  case 0:
@@ -261,9 +262,9 @@ function _applyBuilderPlugins() {
261
262
  import("@modern-js/builder-plugin-node-polyfill")
262
263
  ];
263
264
  case 1:
264
- builderPluginNodePolyfill = _state.sent().builderPluginNodePolyfill;
265
+ PluginNodePolyfill = _state.sent().PluginNodePolyfill;
265
266
  builder.addPlugins([
266
- builderPluginNodePolyfill()
267
+ PluginNodePolyfill()
267
268
  ]);
268
269
  _state.label = 2;
269
270
  case 2:
@@ -277,14 +278,17 @@ function _applyBuilderPlugins() {
277
278
  import("@modern-js/builder-plugin-esbuild")
278
279
  ];
279
280
  case 3:
280
- builderPluginEsbuild = _state.sent().builderPluginEsbuild;
281
+ PluginEsbuild = _state.sent().PluginEsbuild;
281
282
  builder.addPlugins([
282
- builderPluginEsbuild(esbuildOptions)
283
+ PluginEsbuild({
284
+ loader: false,
285
+ minimize: applyOptionsChain({}, esbuildOptions)
286
+ })
283
287
  ]);
284
288
  _state.label = 4;
285
289
  case 4:
286
290
  builder.addPlugins([
287
- builderPluginCompatModern(options)
291
+ PluginCompatModern(options)
288
292
  ]);
289
293
  return [
290
294
  2
@@ -7,7 +7,7 @@ function getBuilderTargets(normalizedConfig) {
7
7
  if (useNodeTarget) {
8
8
  targets.push("node");
9
9
  }
10
- var useWorkerTarget = isServiceWorker(normalizedConfig);
10
+ var useWorkerTarget = isProd() ? isServiceWorker(normalizedConfig) : false;
11
11
  if (useWorkerTarget) {
12
12
  targets.push("service-worker");
13
13
  }
@@ -182,7 +182,7 @@ import { buildServerConfig } from "../utils/config";
182
182
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
183
183
  var dev = function() {
184
184
  var _ref = _asyncToGenerator(function(api, options) {
185
- var _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
185
+ var _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, serverInternalPlugins, serverOptions, app, server;
186
186
  return __generator(this, function(_state) {
187
187
  switch(_state.label){
188
188
  case 0:
@@ -236,9 +236,14 @@ var dev = function() {
236
236
  serverOptions = {
237
237
  dev: _objectSpread({
238
238
  port: port,
239
- https: normalizedConfig.dev.https,
240
- host: normalizedConfig.dev.host
239
+ https: normalizedConfig.dev.https
241
240
  }, (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer),
241
+ appContext: {
242
+ appDirectory: appContext.appDirectory,
243
+ sharedDirectory: appContext.sharedDirectory,
244
+ apiDirectory: appContext.apiDirectory,
245
+ lambdaDirectory: appContext.lambdaDirectory
246
+ },
242
247
  pwd: appDirectory,
243
248
  config: normalizedConfig,
244
249
  serverConfigFile: serverConfigFile,
@@ -256,11 +261,7 @@ var dev = function() {
256
261
  ];
257
262
  case 5:
258
263
  app = _state.sent();
259
- host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || "localhost";
260
- app.listen({
261
- port: port,
262
- host: host
263
- }, function() {
264
+ app.listen(port, function() {
264
265
  var _ref = _asyncToGenerator(function(err) {
265
266
  return __generator(this, function(_state) {
266
267
  if (err) {
@@ -122,7 +122,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
122
122
  };
123
123
  }
124
124
  };
125
- import { logger, chalk, isApiOnly } from "@modern-js/utils";
125
+ import { logger, chalk, isApiOnly, getTargetDir } from "@modern-js/utils";
126
126
  import server from "@modern-js/prod-server";
127
127
  import { printInstructions } from "../utils/printInstructions";
128
128
  import { injectDataLoaderPlugin } from "../utils/createServer";
@@ -155,6 +155,11 @@ var start = function() {
155
155
  server({
156
156
  pwd: appDirectory,
157
157
  config: userConfig,
158
+ appContext: {
159
+ sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
160
+ apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
161
+ lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
162
+ },
158
163
  serverConfigFile: serverConfigFile,
159
164
  internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
160
165
  apiOnly: apiOnly
@@ -17,10 +17,7 @@ function createToolsConfig(config) {
17
17
  devServer: devServer,
18
18
  tailwindcss: tailwindcss,
19
19
  jest: jest,
20
- esbuild: {
21
- loader: false,
22
- minimize: esbuild
23
- }
20
+ esbuild: esbuild
24
21
  };
25
22
  }
26
23
  export { createToolsConfig };
@@ -1,5 +1,5 @@
1
1
  import path from "path";
2
- import { fs, getEntryOptions, isRouterV5, logger } from "@modern-js/utils";
2
+ import { fs, getEntryOptions, logger } from "@modern-js/utils";
3
3
  import {
4
4
  useResolvedConfigContext
5
5
  } from "@modern-js/core";
@@ -60,6 +60,7 @@ ${initialize || ""}`
60
60
  ).join("\n");
61
61
  };
62
62
  const generateCode = async (appContext, config, entrypoints, api) => {
63
+ var _a, _b, _c;
63
64
  const {
64
65
  internalDirectory,
65
66
  srcDirectory,
@@ -68,7 +69,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
68
69
  packageName
69
70
  } = appContext;
70
71
  const hookRunners = api.useHookRunners();
71
- const isV5 = isRouterV5(config);
72
+ const isV5 = typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
72
73
  const { mountId } = config.html;
73
74
  const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
74
75
  await Promise.all(entrypoints.map(generateEntryCode));
@@ -87,18 +88,23 @@ const generateCode = async (appContext, config, entrypoints, api) => {
87
88
  internalDirAlias
88
89
  });
89
90
  }
90
- if (!isV5 && entrypoint.nestedRoutesEntry) {
91
- nestedRoute = await walk(
92
- entrypoint.nestedRoutesEntry,
93
- entrypoint.nestedRoutesEntry,
94
- {
95
- name: internalSrcAlias,
96
- basename: srcDirectory
97
- },
98
- entrypoint.entryName
99
- );
100
- if (nestedRoute) {
101
- initialRoutes.unshift(nestedRoute);
91
+ if (entrypoint.nestedRoutesEntry) {
92
+ if (!isV5) {
93
+ nestedRoute = await walk(
94
+ entrypoint.nestedRoutesEntry,
95
+ entrypoint.nestedRoutesEntry,
96
+ {
97
+ name: internalSrcAlias,
98
+ basename: srcDirectory
99
+ },
100
+ entrypoint.entryName
101
+ );
102
+ if (nestedRoute) {
103
+ initialRoutes.unshift(nestedRoute);
104
+ }
105
+ } else {
106
+ logger.error("Nested routes is not supported in legacy mode.");
107
+ process.exit(1);
102
108
  }
103
109
  }
104
110
  const { routes } = await hookRunners.modifyFileSystemRoutes({