@modern-js/app-tools 2.10.1-alpha.0 → 2.11.1-alpha.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.
Files changed (140) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/dist/cjs/analyze/index.js +1 -1
  3. package/dist/cjs/builder/index.js +2 -2
  4. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
  5. package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +17 -12
  6. package/dist/cjs/utils/restart.js +1 -1
  7. package/dist/esm/analyze/index.js +2 -2
  8. package/dist/esm/builder/index.js +14 -9
  9. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
  10. package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +20 -13
  11. package/dist/esm/utils/restart.js +2 -2
  12. package/dist/esm-node/analyze/index.js +3 -2
  13. package/dist/esm-node/builder/index.js +1 -1
  14. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
  15. package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +17 -12
  16. package/dist/esm-node/utils/restart.js +8 -2
  17. package/dist/js/modern/analyze/constants.js +3 -1
  18. package/dist/js/modern/analyze/getServerRoutes.js +5 -2
  19. package/dist/js/modern/analyze/index.js +47 -46
  20. package/dist/js/modern/analyze/nestedRoutes.js +32 -3
  21. package/dist/js/modern/analyze/templates.js +4 -10
  22. package/dist/js/modern/builder/builder-rspack/index.js +8 -0
  23. package/dist/js/modern/builder/builder-webpack/builderPlugins/compatModern.js +41 -0
  24. package/dist/js/modern/builder/builder-webpack/index.js +93 -0
  25. package/dist/js/modern/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +4 -1
  26. package/dist/js/modern/builder/builder-webpack/webpackPlugins/index.js +1 -0
  27. package/dist/js/modern/builder/generator/createBuilderOptions.js +24 -0
  28. package/dist/js/modern/builder/generator/createBuilderProviderConfig.js +39 -0
  29. package/dist/js/modern/builder/generator/getBuilderTargets.js +21 -0
  30. package/dist/js/modern/builder/generator/index.js +53 -0
  31. package/dist/js/modern/builder/index.js +13 -133
  32. package/dist/js/modern/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +102 -116
  33. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +27 -0
  34. package/dist/js/modern/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +34 -0
  35. package/dist/js/modern/builder/shared/index.js +3 -0
  36. package/dist/js/modern/builder/shared/types.js +0 -0
  37. package/dist/js/modern/config/default.js +2 -2
  38. package/dist/js/modern/config/index.js +3 -8
  39. package/dist/js/modern/config/initialize/index.js +12 -0
  40. package/dist/js/modern/config/{initial → initialize}/inits.js +4 -2
  41. package/dist/js/modern/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -0
  42. package/dist/js/modern/index.js +18 -8
  43. package/dist/js/modern/initialize/index.js +36 -28
  44. package/dist/js/modern/locale/zh.js +1 -1
  45. package/dist/js/modern/types/utils.js +0 -0
  46. package/dist/js/node/analyze/constants.js +3 -1
  47. package/dist/js/node/analyze/getServerRoutes.js +3 -1
  48. package/dist/js/node/analyze/index.js +48 -47
  49. package/dist/js/node/analyze/nestedRoutes.js +32 -3
  50. package/dist/js/node/analyze/templates.js +4 -10
  51. package/dist/js/node/{config/initial → builder/builder-rspack}/index.js +9 -19
  52. package/dist/js/node/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  53. package/dist/js/node/builder/builder-webpack/index.js +118 -0
  54. package/dist/js/node/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +10 -5
  55. package/dist/js/node/builder/builder-webpack/webpackPlugins/index.js +17 -0
  56. package/dist/js/node/builder/generator/createBuilderOptions.js +47 -0
  57. package/dist/js/node/builder/generator/createBuilderProviderConfig.js +60 -0
  58. package/dist/js/node/builder/generator/getBuilderTargets.js +39 -0
  59. package/dist/js/node/builder/generator/index.js +82 -0
  60. package/dist/js/node/builder/index.js +14 -123
  61. package/dist/js/node/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +107 -120
  62. package/dist/js/node/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +17 -20
  63. package/dist/js/node/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +21 -24
  64. package/dist/js/node/builder/{share.js → shared/createCopyPattern.js} +3 -3
  65. package/dist/js/node/builder/shared/index.js +19 -0
  66. package/dist/js/node/builder/shared/types.js +15 -0
  67. package/dist/js/node/config/default.js +2 -2
  68. package/dist/js/node/config/index.js +4 -19
  69. package/dist/js/node/{builder/loaders/routerLoader.js → config/initialize/index.js} +14 -17
  70. package/dist/js/node/config/{initial → initialize}/inits.js +4 -2
  71. package/dist/js/node/config/{initial/transformNormalizedConfig.js → legacy/index.js} +8 -3
  72. package/dist/js/node/index.js +18 -8
  73. package/dist/js/node/initialize/index.js +35 -28
  74. package/dist/js/node/locale/zh.js +1 -1
  75. package/dist/js/node/types/utils.js +15 -0
  76. package/dist/js/treeshaking/analyze/constants.js +3 -1
  77. package/dist/js/treeshaking/analyze/generateCode.js +14 -14
  78. package/dist/js/treeshaking/analyze/getBundleEntry.js +2 -2
  79. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +1 -1
  80. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +1 -1
  81. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
  82. package/dist/js/treeshaking/analyze/getServerRoutes.js +8 -6
  83. package/dist/js/treeshaking/analyze/index.js +142 -137
  84. package/dist/js/treeshaking/analyze/nestedRoutes.js +29 -4
  85. package/dist/js/treeshaking/analyze/templates.js +10 -13
  86. package/dist/js/treeshaking/analyze/utils.js +3 -3
  87. package/dist/js/treeshaking/builder/builder-rspack/index.js +6 -0
  88. package/dist/js/treeshaking/builder/builder-webpack/builderPlugins/compatModern.js +64 -0
  89. package/dist/js/treeshaking/builder/builder-webpack/index.js +301 -0
  90. package/dist/js/treeshaking/builder/{webpackPlugins/routerPlugin.js → builder-webpack/webpackPlugins/RouterPlugin.js} +6 -3
  91. package/dist/js/treeshaking/builder/builder-webpack/webpackPlugins/index.js +1 -0
  92. package/dist/js/treeshaking/builder/generator/createBuilderOptions.js +41 -0
  93. package/dist/js/treeshaking/builder/generator/createBuilderProviderConfig.js +70 -0
  94. package/dist/js/treeshaking/builder/generator/getBuilderTargets.js +16 -0
  95. package/dist/js/treeshaking/builder/generator/index.js +199 -0
  96. package/dist/js/treeshaking/builder/index.js +29 -228
  97. package/dist/js/treeshaking/builder/{builderPlugins/compatModern.js → shared/builderPlugins/adapterModern.js} +138 -142
  98. package/dist/js/treeshaking/builder/{webpackPlugins/htmlBottomTemplate.js → shared/bundlerPlugins/HtmlBottomTemplate.js} +2 -2
  99. package/dist/js/treeshaking/builder/shared/index.js +3 -0
  100. package/dist/js/treeshaking/builder/shared/types.js +1 -0
  101. package/dist/js/treeshaking/commands/dev.js +2 -2
  102. package/dist/js/treeshaking/commands/serve.js +2 -2
  103. package/dist/js/treeshaking/config/default.js +2 -2
  104. package/dist/js/treeshaking/config/index.js +3 -3
  105. package/dist/js/treeshaking/config/initialize/index.js +10 -0
  106. package/dist/js/treeshaking/config/{initial → initialize}/inits.js +6 -4
  107. package/dist/js/treeshaking/config/legacy/createHtmlConfig.js +19 -0
  108. package/dist/js/treeshaking/config/{initial → legacy}/createOutputConfig.js +1 -1
  109. package/dist/js/treeshaking/config/{initial → legacy}/createSourceConfig.js +1 -1
  110. package/dist/js/treeshaking/config/{initial → legacy}/createToolsConfig.js +1 -1
  111. package/dist/js/treeshaking/config/{initial/transformNormalizedConfig.js → legacy/index.js} +4 -1
  112. package/dist/js/treeshaking/index.js +19 -12
  113. package/dist/js/treeshaking/initialize/index.js +36 -28
  114. package/dist/js/treeshaking/locale/zh.js +1 -1
  115. package/dist/js/treeshaking/types/utils.js +1 -0
  116. package/dist/js/treeshaking/utils/config.js +2 -2
  117. package/dist/js/treeshaking/utils/getServerInternalPlugins.js +2 -2
  118. package/dist/types/types/config/source.d.ts +2 -2
  119. package/package.json +24 -24
  120. package/dist/js/modern/builder/loaders/routerLoader.js +0 -17
  121. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -30
  122. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +0 -37
  123. package/dist/js/modern/config/initial/index.js +0 -16
  124. package/dist/js/treeshaking/builder/loaders/routerLoader.js +0 -13
  125. package/dist/js/treeshaking/config/initial/createHtmlConfig.js +0 -19
  126. package/dist/js/treeshaking/config/initial/index.js +0 -12
  127. /package/dist/js/modern/builder/{share.js → shared/createCopyPattern.js} +0 -0
  128. /package/dist/js/modern/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  129. /package/dist/js/modern/config/{initial → legacy}/createHtmlConfig.js +0 -0
  130. /package/dist/js/modern/config/{initial → legacy}/createOutputConfig.js +0 -0
  131. /package/dist/js/modern/config/{initial → legacy}/createSourceConfig.js +0 -0
  132. /package/dist/js/modern/config/{initial → legacy}/createToolsConfig.js +0 -0
  133. /package/dist/js/node/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
  134. /package/dist/js/node/config/{initial → legacy}/createHtmlConfig.js +0 -0
  135. /package/dist/js/node/config/{initial → legacy}/createOutputConfig.js +0 -0
  136. /package/dist/js/node/config/{initial → legacy}/createSourceConfig.js +0 -0
  137. /package/dist/js/node/config/{initial → legacy}/createToolsConfig.js +0 -0
  138. /package/dist/js/treeshaking/builder/{webpackPlugins/htmlAsyncChunkPlugin.js → shared/bundlerPlugins/HtmlAsyncChunkPlugin.js} +0 -0
  139. /package/dist/js/treeshaking/builder/{share.js → shared/createCopyPattern.js} +0 -0
  140. /package/dist/js/treeshaking/builder/{loaders → shared/loaders}/serverModuleLoader.js +0 -0
@@ -66,16 +66,18 @@ module.exports = __toCommonJS(analyze_exports);
66
66
  var path = __toESM(require("path"));
67
67
  var import_utils = require("@modern-js/utils");
68
68
  var import_lodash = require("@modern-js/utils/lodash");
69
- var import_builder = require("../builder");
70
69
  var import_printInstructions = require("../utils/printInstructions");
71
70
  var import_routes = require("../utils/routes");
72
71
  var import_config = require("../utils/config");
73
72
  var import_getSelectedEntries = require("../utils/getSelectedEntries");
74
73
  var import_config2 = require("../config");
74
+ var import_builder = require("../builder");
75
75
  var import_utils2 = require("./utils");
76
76
  var import_constants = require("./constants");
77
77
  const debug = (0, import_utils.createDebugger)("plugin-analyze");
78
- var analyze_default = () => ({
78
+ var analyze_default = ({
79
+ bundler
80
+ }) => ({
79
81
  name: "@modern-js/plugin-analyze",
80
82
  setup: (api) => {
81
83
  let pagesDir = [];
@@ -167,56 +169,55 @@ var analyze_default = () => ({
167
169
  if (buildCommands.includes(command)) {
168
170
  let _b;
169
171
  const normalizedConfig = api.useResolvedConfigContext();
170
- const builder = yield (0, import_builder.createBuilderForModern)({
172
+ const createBuilderForModern = yield (0, import_builder.createBuilderGenerator)(bundler);
173
+ const builder = yield createBuilderForModern({
171
174
  normalizedConfig,
172
175
  appContext,
173
- compatPluginConfig: {
174
- onBeforeBuild(_0) {
175
- return __async(this, arguments, function* ({ bundlerConfigs }) {
176
- const hookRunners2 = api.useHookRunners();
177
- yield (0, import_routes.generateRoutes)(appContext);
178
- yield hookRunners2.beforeBuild({ bundlerConfigs });
179
- });
180
- },
181
- onAfterBuild(_0) {
182
- return __async(this, arguments, function* ({ stats }) {
183
- const hookRunners2 = api.useHookRunners();
184
- yield hookRunners2.afterBuild({ stats });
185
- yield (0, import_config.emitResolvedConfig)(
186
- appContext.appDirectory,
187
- normalizedConfig
188
- );
176
+ onBeforeBuild(_0) {
177
+ return __async(this, arguments, function* ({ bundlerConfigs }) {
178
+ const hookRunners2 = api.useHookRunners();
179
+ yield (0, import_routes.generateRoutes)(appContext);
180
+ yield hookRunners2.beforeBuild({
181
+ bundlerConfigs
189
182
  });
190
- },
191
- onDevCompileDone(_0) {
192
- return __async(this, arguments, function* ({ isFirstCompile }) {
193
- const hookRunners2 = api.useHookRunners();
194
- if (process.stdout.isTTY || isFirstCompile) {
195
- hookRunners2.afterDev();
196
- if (isFirstCompile) {
197
- (0, import_printInstructions.printInstructions)(
198
- hookRunners2,
199
- appContext,
200
- normalizedConfig
201
- );
202
- }
183
+ });
184
+ },
185
+ onAfterBuild(_0) {
186
+ return __async(this, arguments, function* ({ stats }) {
187
+ const hookRunners2 = api.useHookRunners();
188
+ yield hookRunners2.afterBuild({ stats });
189
+ yield (0, import_config.emitResolvedConfig)(
190
+ appContext.appDirectory,
191
+ normalizedConfig
192
+ );
193
+ });
194
+ },
195
+ onDevCompileDone(_0) {
196
+ return __async(this, arguments, function* ({ isFirstCompile }) {
197
+ const hookRunners2 = api.useHookRunners();
198
+ if (process.stdout.isTTY || isFirstCompile) {
199
+ hookRunners2.afterDev();
200
+ if (isFirstCompile) {
201
+ (0, import_printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
203
202
  }
203
+ }
204
+ });
205
+ },
206
+ onBeforeCreateCompiler(_0) {
207
+ return __async(this, arguments, function* ({ bundlerConfigs }) {
208
+ const hookRunners2 = api.useHookRunners();
209
+ yield hookRunners2.beforeCreateCompiler({
210
+ bundlerConfigs
204
211
  });
205
- },
206
- onBeforeCreateCompiler(_0) {
207
- return __async(this, arguments, function* ({ bundlerConfigs }) {
208
- const hookRunners2 = api.useHookRunners();
209
- yield hookRunners2.beforeCreateCompiler({
210
- bundlerConfigs
211
- });
212
- });
213
- },
214
- onAfterCreateCompiler(_0) {
215
- return __async(this, arguments, function* ({ compiler }) {
216
- const hookRunners2 = api.useHookRunners();
217
- yield hookRunners2.afterCreateCompiler({ compiler });
212
+ });
213
+ },
214
+ onAfterCreateCompiler(_0) {
215
+ return __async(this, arguments, function* ({ compiler }) {
216
+ const hookRunners2 = api.useHookRunners();
217
+ yield hookRunners2.afterCreateCompiler({
218
+ compiler
218
219
  });
219
- }
220
+ });
220
221
  }
221
222
  });
222
223
  builder.addPlugins(resolvedConfig.builderPlugins);
@@ -259,7 +260,7 @@ var analyze_default = () => ({
259
260
  },
260
261
  resolvedConfig({ resolved }) {
261
262
  const appContext = api.useAppContext();
262
- const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext);
263
+ const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext, bundler);
263
264
  return {
264
265
  resolved: config
265
266
  };
@@ -90,7 +90,7 @@ const createRoute = (routeInfo, rootDir, filename, entryName) => {
90
90
  });
91
91
  };
92
92
  const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, function* () {
93
- var _a, _b, _c;
93
+ var _a, _b, _c, _d;
94
94
  if (!(yield import_utils.fs.pathExists(dirname))) {
95
95
  return null;
96
96
  }
@@ -116,6 +116,8 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
116
116
  };
117
117
  let pageLoaderFile = "";
118
118
  let pageRoute = null;
119
+ let splatLoaderFile = "";
120
+ let splatRoute = null;
119
121
  const items = yield import_utils.fs.readdir(dirname);
120
122
  for (const item of items) {
121
123
  const itemPath = path.join(dirname, item);
@@ -156,6 +158,24 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
156
158
  }
157
159
  (_b = route.children) == null ? void 0 : _b.push(pageRoute);
158
160
  }
161
+ if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_LOADER_FILE) {
162
+ splatLoaderFile = itemPath;
163
+ }
164
+ if (itemWithoutExt === import_constants.NESTED_ROUTE.SPLATE_FILE) {
165
+ splatRoute = createRoute(
166
+ {
167
+ _component: (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name),
168
+ path: "*"
169
+ },
170
+ rootDir,
171
+ itemPath,
172
+ entryName
173
+ );
174
+ if (splatLoaderFile) {
175
+ splatRoute.loader = splatLoaderFile;
176
+ }
177
+ (_c = route.children) == null ? void 0 : _c.push(splatRoute);
178
+ }
159
179
  if (itemWithoutExt === import_constants.NESTED_ROUTE.LOADING_FILE) {
160
180
  route.loading = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
161
181
  }
@@ -163,7 +183,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
163
183
  route.error = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
164
184
  }
165
185
  }
166
- const finalRoute = createRoute(
186
+ let finalRoute = createRoute(
167
187
  route,
168
188
  rootDir,
169
189
  path.join(dirname, `${import_constants.NESTED_ROUTE.LAYOUT_FILE}.ts`),
@@ -172,10 +192,19 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
172
192
  if (isPathlessLayout) {
173
193
  delete finalRoute.path;
174
194
  }
175
- route.children = (_c = route.children) == null ? void 0 : _c.filter((childRoute) => childRoute);
195
+ route.children = (_d = route.children) == null ? void 0 : _d.filter((childRoute) => childRoute);
176
196
  if (route.children && route.children.length === 0 && !route.index) {
177
197
  return null;
178
198
  }
199
+ if (finalRoute.children && finalRoute.children.length === 1 && !finalRoute._component) {
200
+ const childRoute = finalRoute.children[0];
201
+ if (childRoute.path === "*") {
202
+ const path2 = `${finalRoute.path || ""}/${childRoute.path || ""}`;
203
+ finalRoute = __spreadProps(__spreadValues({}, childRoute), {
204
+ path: path2
205
+ });
206
+ }
207
+ }
179
208
  return finalRoute;
180
209
  });
181
210
  // Annotate the CommonJS export names for ESM import in node:
@@ -99,6 +99,7 @@ const renderFunction = ({
99
99
  customBootstrap,
100
100
  fileSystemRoutes: fileSystemRoutes2
101
101
  }) => {
102
+ const bootstrap = "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM)";
102
103
  return `
103
104
  const finalAppConfig = {
104
105
  ...App.config,
@@ -120,7 +121,7 @@ const renderFunction = ({
120
121
 
121
122
 
122
123
  if (IS_BROWSER) {
123
- ${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
124
+ ${customBootstrap ? `customBootstrap(AppWrapper, () => ${bootstrap});` : `${bootstrap};`}
124
125
  }
125
126
 
126
127
  return AppWrapper
@@ -228,7 +229,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
228
229
  import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
229
230
  `;
230
231
  let rootLayoutCode = ``;
231
- let componentLoaderPath = "";
232
232
  const getDataLoaderPath = (loaderId) => {
233
233
  if (!ssrMode) {
234
234
  return "";
@@ -241,12 +241,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
241
241
  }
242
242
  return dataLoaderPath;
243
243
  };
244
- if (ssrMode) {
245
- componentLoaderPath = `${import_path.default.join(
246
- __dirname,
247
- "../builder/loaders/routerLoader"
248
- )}!`;
249
- }
250
244
  const traverseRouteTree = (route) => {
251
245
  var _a;
252
246
  let children;
@@ -282,10 +276,10 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
282
276
  rootLayoutCode = `import RootLayout from '${route._component}'`;
283
277
  component = `RootLayout`;
284
278
  } else if (ssrMode === "string") {
285
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
279
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
286
280
  component = `loadable(${lazyImport})`;
287
281
  } else {
288
- lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
282
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${route._component}')`;
289
283
  component = `lazy(${lazyImport})`;
290
284
  }
291
285
  }
@@ -15,27 +15,17 @@ var __copyProps = (to, from, except, desc) => {
15
15
  return to;
16
16
  };
17
17
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
- var initial_exports = {};
19
- __export(initial_exports, {
20
- checkIsLegacyConfig: () => checkIsLegacyConfig,
21
- initialNormalizedConfig: () => initialNormalizedConfig,
22
- transformNormalizedConfig: () => import_transformNormalizedConfig.transformNormalizedConfig
18
+ var builder_rspack_exports = {};
19
+ __export(builder_rspack_exports, {
20
+ createRspackBuilderForModern: () => createRspackBuilderForModern
23
21
  });
24
- module.exports = __toCommonJS(initial_exports);
25
- var import_inits = require("./inits");
26
- var import_transformNormalizedConfig = require("./transformNormalizedConfig");
27
- function checkIsLegacyConfig(config) {
28
- return Boolean(config.legacy);
29
- }
30
- function initialNormalizedConfig(config, appContext) {
31
- (0, import_inits.initHtmlConfig)(config, appContext);
32
- (0, import_inits.initSourceConfig)(config, appContext);
33
- (0, import_inits.initToolsConfig)(config);
34
- return config;
22
+ module.exports = __toCommonJS(builder_rspack_exports);
23
+ var import_builder_rspack_provider = require("@modern-js/builder-rspack-provider");
24
+ var import_generator = require("../generator");
25
+ function createRspackBuilderForModern(options) {
26
+ return (0, import_generator.generateBuilder)(options, import_builder_rspack_provider.builderRspackProvider);
35
27
  }
36
28
  // Annotate the CommonJS export names for ESM import in node:
37
29
  0 && (module.exports = {
38
- checkIsLegacyConfig,
39
- initialNormalizedConfig,
40
- transformNormalizedConfig
30
+ createRspackBuilderForModern
41
31
  });
@@ -0,0 +1,64 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var compatModern_exports = {};
19
+ __export(compatModern_exports, {
20
+ PluginCompatModern: () => PluginCompatModern
21
+ });
22
+ module.exports = __toCommonJS(compatModern_exports);
23
+ var import_path = require("path");
24
+ var import_shared = require("../../shared");
25
+ var import_webpackPlugins = require("../webpackPlugins");
26
+ const PluginCompatModern = (options) => ({
27
+ name: "builder-plugin-compat-modern",
28
+ setup(api) {
29
+ const { normalizedConfig: modernConfig, appContext } = options;
30
+ api.modifyWebpackChain((chain, { CHAIN_ID }) => {
31
+ var _a;
32
+ chain.resolve.modules.add("node_modules").add((0, import_path.join)(api.context.rootPath, "node_modules"));
33
+ if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
34
+ const defaultCopyPattern = (0, import_shared.createCopyPattern)(
35
+ appContext,
36
+ modernConfig,
37
+ "public",
38
+ chain
39
+ );
40
+ chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
41
+ var _a2;
42
+ return [
43
+ {
44
+ patterns: [...((_a2 = args[0]) == null ? void 0 : _a2.patterns) || [], defaultCopyPattern]
45
+ }
46
+ ];
47
+ });
48
+ }
49
+ const { entrypoints } = appContext;
50
+ const existNestedRoutes = entrypoints.some(
51
+ (entrypoint) => entrypoint.nestedRoutesEntry
52
+ );
53
+ const routerConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.router;
54
+ const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
55
+ if (existNestedRoutes || routerManifest) {
56
+ chain.plugin("route-plugin").use(import_webpackPlugins.RouterPlugin);
57
+ }
58
+ });
59
+ }
60
+ });
61
+ // Annotate the CommonJS export names for ESM import in node:
62
+ 0 && (module.exports = {
63
+ PluginCompatModern
64
+ });
@@ -0,0 +1,118 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
35
+ };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
38
+ mod
39
+ ));
40
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
41
+ var __async = (__this, __arguments, generator) => {
42
+ return new Promise((resolve, reject) => {
43
+ var fulfilled = (value) => {
44
+ try {
45
+ step(generator.next(value));
46
+ } catch (e) {
47
+ reject(e);
48
+ }
49
+ };
50
+ var rejected = (value) => {
51
+ try {
52
+ step(generator.throw(value));
53
+ } catch (e) {
54
+ reject(e);
55
+ }
56
+ };
57
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
58
+ step((generator = generator.apply(__this, __arguments)).next());
59
+ });
60
+ };
61
+ var builder_webpack_exports = {};
62
+ __export(builder_webpack_exports, {
63
+ createWebpackBuilderForModern: () => createWebpackBuilderForModern
64
+ });
65
+ module.exports = __toCommonJS(builder_webpack_exports);
66
+ var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
67
+ var import_utils = require("@modern-js/utils");
68
+ var import_shared = require("../shared");
69
+ var import_generator = require("../generator");
70
+ var import_compatModern = require("./builderPlugins/compatModern");
71
+ function createWebpackBuilderForModern(options) {
72
+ return (0, import_generator.generateBuilder)(options, import_builder_webpack_provider.builderWebpackProvider, {
73
+ modifyBuilderConfig(config) {
74
+ modifyOutputConfig(config, options.appContext);
75
+ },
76
+ modifyBuilderInstance(builder) {
77
+ return __async(this, null, function* () {
78
+ yield applyBuilderPlugins(builder, options);
79
+ });
80
+ }
81
+ });
82
+ }
83
+ function modifyOutputConfig(config, appContext) {
84
+ config.output = createOutputConfig(config, appContext);
85
+ function createOutputConfig(config2, appContext2) {
86
+ const defaultCopyPattern = (0, import_shared.createCopyPattern)(appContext2, config2, "upload");
87
+ const { copy } = config2.output;
88
+ const copyOptions = Array.isArray(copy) ? copy : copy == null ? void 0 : copy.patterns;
89
+ const builderCopy = [...copyOptions || [], defaultCopyPattern];
90
+ return __spreadProps(__spreadValues({}, config2.output), {
91
+ copy: builderCopy
92
+ });
93
+ }
94
+ }
95
+ function applyBuilderPlugins(builder, options) {
96
+ return __async(this, null, function* () {
97
+ const { normalizedConfig } = options;
98
+ if (!normalizedConfig.output.disableNodePolyfill) {
99
+ const { PluginNodePolyfill } = yield Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-node-polyfill")));
100
+ builder.addPlugins([PluginNodePolyfill()]);
101
+ }
102
+ if (normalizedConfig.tools.esbuild) {
103
+ const { esbuild: esbuildOptions } = normalizedConfig.tools;
104
+ const { PluginEsbuild } = yield Promise.resolve().then(() => __toESM(require("@modern-js/builder-plugin-esbuild")));
105
+ builder.addPlugins([
106
+ PluginEsbuild({
107
+ loader: false,
108
+ minimize: (0, import_utils.applyOptionsChain)({}, esbuildOptions)
109
+ })
110
+ ]);
111
+ }
112
+ builder.addPlugins([(0, import_compatModern.PluginCompatModern)(options)]);
113
+ });
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ createWebpackBuilderForModern
118
+ });
@@ -41,11 +41,11 @@ var __async = (__this, __arguments, generator) => {
41
41
  step((generator = generator.apply(__this, __arguments)).next());
42
42
  });
43
43
  };
44
- var routerPlugin_exports = {};
45
- __export(routerPlugin_exports, {
46
- default: () => RouterPlugin
44
+ var RouterPlugin_exports = {};
45
+ __export(RouterPlugin_exports, {
46
+ RouterPlugin: () => RouterPlugin
47
47
  });
48
- module.exports = __toCommonJS(routerPlugin_exports);
48
+ module.exports = __toCommonJS(RouterPlugin_exports);
49
49
  var import_path = __toESM(require("path"));
50
50
  var import_utils = require("@modern-js/utils");
51
51
  const PLUGIN_NAME = "ModernjsRoutePlugin";
@@ -55,6 +55,9 @@ class RouterPlugin {
55
55
  if (target === "node" || Array.isArray(target) && target.includes("node")) {
56
56
  return;
57
57
  }
58
+ if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
59
+ return;
60
+ }
58
61
  const { webpack } = compiler;
59
62
  const { Compilation, sources } = webpack;
60
63
  const { RawSource } = sources;
@@ -132,4 +135,6 @@ class RouterPlugin {
132
135
  }
133
136
  }
134
137
  // Annotate the CommonJS export names for ESM import in node:
135
- 0 && (module.exports = {});
138
+ 0 && (module.exports = {
139
+ RouterPlugin
140
+ });
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var webpackPlugins_exports = {};
16
+ module.exports = __toCommonJS(webpackPlugins_exports);
17
+ __reExport(webpackPlugins_exports, require("./RouterPlugin"), module.exports);
@@ -0,0 +1,47 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var createBuilderOptions_exports = {};
19
+ __export(createBuilderOptions_exports, {
20
+ createBuilderOptions: () => createBuilderOptions
21
+ });
22
+ module.exports = __toCommonJS(createBuilderOptions_exports);
23
+ function createBuilderOptions(target, appContext) {
24
+ const entries = {};
25
+ const { entrypoints = [], checkedEntries } = appContext;
26
+ for (const { entryName, entry } of entrypoints) {
27
+ if (checkedEntries && !checkedEntries.includes(entryName)) {
28
+ continue;
29
+ }
30
+ if (entryName in entries) {
31
+ entries[entryName].push(entry);
32
+ } else {
33
+ entries[entryName] = [entry];
34
+ }
35
+ }
36
+ return {
37
+ cwd: appContext.appDirectory,
38
+ target,
39
+ configPath: appContext.configFile || void 0,
40
+ entry: entries,
41
+ framework: appContext.metaName
42
+ };
43
+ }
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ createBuilderOptions
47
+ });
@@ -0,0 +1,60 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __export = (target, all) => {
23
+ for (var name in all)
24
+ __defProp(target, name, { get: all[name], enumerable: true });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from))
29
+ if (!__hasOwnProp.call(to, key) && key !== except)
30
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
31
+ }
32
+ return to;
33
+ };
34
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
+ var createBuilderProviderConfig_exports = {};
36
+ __export(createBuilderProviderConfig_exports, {
37
+ createBuilderProviderConfig: () => createBuilderProviderConfig
38
+ });
39
+ module.exports = __toCommonJS(createBuilderProviderConfig_exports);
40
+ function createBuilderProviderConfig(resolveConfig, appContext, modifyBuilderConfig) {
41
+ const htmlConfig = __spreadValues({}, resolveConfig.html);
42
+ if (!htmlConfig.template) {
43
+ htmlConfig.templateByEntries = __spreadValues(__spreadValues({}, htmlConfig.templateByEntries), appContext.htmlTemplates);
44
+ }
45
+ const config = __spreadProps(__spreadValues({}, resolveConfig), {
46
+ dev: __spreadProps(__spreadValues({}, resolveConfig.dev), {
47
+ port: appContext.port
48
+ }),
49
+ html: htmlConfig,
50
+ output: __spreadProps(__spreadValues({}, resolveConfig.output), {
51
+ cleanDistPath: false
52
+ })
53
+ });
54
+ modifyBuilderConfig == null ? void 0 : modifyBuilderConfig(config);
55
+ return config;
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ createBuilderProviderConfig
60
+ });