@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
@@ -15,11 +15,11 @@ 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 htmlBottomTemplate_exports = {};
19
- __export(htmlBottomTemplate_exports, {
18
+ var HtmlBottomTemplate_exports = {};
19
+ __export(HtmlBottomTemplate_exports, {
20
20
  BottomTemplatePlugin: () => BottomTemplatePlugin
21
21
  });
22
- module.exports = __toCommonJS(htmlBottomTemplate_exports);
22
+ module.exports = __toCommonJS(HtmlBottomTemplate_exports);
23
23
  class BottomTemplatePlugin {
24
24
  constructor(htmlWebpackPlugin) {
25
25
  this.bottomTemplateReg = /<!--<\?-\s*bottomTemplate\s*\?>-->/;
@@ -28,30 +28,27 @@ class BottomTemplatePlugin {
28
28
  this.name = "bottom-template";
29
29
  }
30
30
  apply(compiler) {
31
- compiler.hooks.compilation.tap(
32
- this.name,
33
- (compilation) => {
34
- this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
35
- var _a;
36
- if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
37
- return data;
38
- }
39
- if (this.bottomTemplateReg.test(data.html)) {
40
- data.html = data.html.replace(this.bottomTemplateReg, "");
41
- const { bottomTemplate } = data.plugin.options;
42
- if (bottomTemplate) {
43
- data.html = data.html.replace(
44
- this.bodyRegExp,
45
- (match) => `
31
+ compiler.hooks.compilation.tap(this.name, (compilation) => {
32
+ this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
33
+ var _a;
34
+ if (!((_a = data.plugin.options) == null ? void 0 : _a.__internal__)) {
35
+ return data;
36
+ }
37
+ if (this.bottomTemplateReg.test(data.html)) {
38
+ data.html = data.html.replace(this.bottomTemplateReg, "");
39
+ const { bottomTemplate } = data.plugin.options;
40
+ if (bottomTemplate) {
41
+ data.html = data.html.replace(
42
+ this.bodyRegExp,
43
+ (match) => `
46
44
  ${bottomTemplate}
47
45
  ${match}`
48
- );
49
- }
46
+ );
50
47
  }
51
- return data;
52
- });
53
- }
54
- );
48
+ }
49
+ return data;
50
+ });
51
+ });
55
52
  }
56
53
  }
57
54
  // Annotate the CommonJS export names for ESM import in node:
@@ -21,11 +21,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  mod
22
22
  ));
23
23
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
24
- var share_exports = {};
25
- __export(share_exports, {
24
+ var createCopyPattern_exports = {};
25
+ __export(createCopyPattern_exports, {
26
26
  createCopyPattern: () => createCopyPattern
27
27
  });
28
- module.exports = __toCommonJS(share_exports);
28
+ module.exports = __toCommonJS(createCopyPattern_exports);
29
29
  var import_path = __toESM(require("path"));
30
30
  var import_utils = require("@modern-js/utils");
31
31
  function createCopyPattern(appContext, config, patternsType, chain) {
@@ -0,0 +1,19 @@
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 shared_exports = {};
16
+ module.exports = __toCommonJS(shared_exports);
17
+ __reExport(shared_exports, require("./createCopyPattern"), module.exports);
18
+ __reExport(shared_exports, require("./types"), module.exports);
19
+ __reExport(shared_exports, require("./builderPlugins/adapterModern"), module.exports);
@@ -0,0 +1,15 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var types_exports = {};
15
+ module.exports = __toCommonJS(types_exports);
@@ -39,12 +39,11 @@ __export(default_exports, {
39
39
  });
40
40
  module.exports = __toCommonJS(default_exports);
41
41
  var import_builder_webpack_provider = require("@modern-js/builder-webpack-provider");
42
- function createDefaultConfig(appContext) {
42
+ function createDefaultConfig(appContext, bundler) {
43
43
  const defaultBuilderConfig = (0, import_builder_webpack_provider.createDefaultConfig)();
44
44
  const dev = __spreadProps(__spreadValues({}, defaultBuilderConfig.dev), {
45
45
  port: void 0
46
46
  });
47
- const tools = __spreadValues({}, defaultBuilderConfig.tools);
48
47
  const output = __spreadProps(__spreadValues({}, defaultBuilderConfig.output), {
49
48
  disableNodePolyfill: true
50
49
  });
@@ -82,6 +81,7 @@ function createDefaultConfig(appContext) {
82
81
  baseUrl: "/",
83
82
  port: 8080
84
83
  };
84
+ const tools = bundler === "webpack" ? __spreadValues({}, defaultBuilderConfig.tools) : void 0;
85
85
  return {
86
86
  source,
87
87
  output,
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
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
5
  var __copyProps = (to, from, except, desc) => {
10
6
  if (from && typeof from === "object" || typeof from === "function") {
11
7
  for (let key of __getOwnPropNames(from))
@@ -14,21 +10,10 @@ var __copyProps = (to, from, except, desc) => {
14
10
  }
15
11
  return to;
16
12
  };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
17
14
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
15
  var config_exports = {};
19
- __export(config_exports, {
20
- checkIsLegacyConfig: () => import_initial.checkIsLegacyConfig,
21
- createDefaultConfig: () => import_default.createDefaultConfig,
22
- createLegacyDefaultConfig: () => import_default.createLegacyDefaultConfig,
23
- initialNormalizedConfig: () => import_initial.initialNormalizedConfig
24
- });
25
16
  module.exports = __toCommonJS(config_exports);
26
- var import_default = require("./default");
27
- var import_initial = require("./initial");
28
- // Annotate the CommonJS export names for ESM import in node:
29
- 0 && (module.exports = {
30
- checkIsLegacyConfig,
31
- createDefaultConfig,
32
- createLegacyDefaultConfig,
33
- initialNormalizedConfig
34
- });
17
+ __reExport(config_exports, require("./legacy"), module.exports);
18
+ __reExport(config_exports, require("./initialize"), module.exports);
19
+ __reExport(config_exports, require("./default"), module.exports);
@@ -15,24 +15,21 @@ 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 routerLoader_exports = {};
19
- __export(routerLoader_exports, {
20
- default: () => routerLoader_default
18
+ var initialize_exports = {};
19
+ __export(initialize_exports, {
20
+ initialNormalizedConfig: () => initialNormalizedConfig
21
21
  });
22
- module.exports = __toCommonJS(routerLoader_exports);
23
- var import_utils = require("@modern-js/utils");
24
- function loader(source) {
25
- this.cacheable();
26
- const { target } = this._compiler.options;
27
- if (target === "node" || Array.isArray(target) && target.includes("node")) {
28
- return source;
22
+ module.exports = __toCommonJS(initialize_exports);
23
+ var import_inits = require("./inits");
24
+ function initialNormalizedConfig(config, appContext, bundler) {
25
+ (0, import_inits.initHtmlConfig)(config, appContext);
26
+ (0, import_inits.initSourceConfig)(config, appContext, bundler);
27
+ if (bundler === "webpack") {
28
+ (0, import_inits.initToolsConfig)(config);
29
29
  }
30
- const { resourcePath } = this;
31
- const code = `
32
- export { default } from "${(0, import_utils.slash)(resourcePath)}";
33
- `;
34
- return code;
30
+ return config;
35
31
  }
36
- var routerLoader_default = loader;
37
32
  // Annotate the CommonJS export names for ESM import in node:
38
- 0 && (module.exports = {});
33
+ 0 && (module.exports = {
34
+ initialNormalizedConfig
35
+ });
@@ -81,10 +81,12 @@ function initHtmlConfig(config, appContext) {
81
81
  return favicon || defaultFavicon || void 0;
82
82
  }
83
83
  }
84
- function initSourceConfig(config, appContext) {
84
+ function initSourceConfig(config, appContext, bundler) {
85
85
  config.source.include = createBuilderInclude(config, appContext);
86
- config.source.moduleScopes = createBuilderModuleScope(config);
87
86
  config.source.globalVars = createBuilderGlobalVars(config, appContext);
87
+ if (bundler === "webpack") {
88
+ config.source.moduleScopes = createBuilderModuleScope(config);
89
+ }
88
90
  function createBuilderGlobalVars(config2, appContext2) {
89
91
  const { globalVars = {} } = config2.source;
90
92
  const publicEnv = (0, import_env.getAutoInjectEnv)(appContext2);
@@ -15,11 +15,12 @@ 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 transformNormalizedConfig_exports = {};
19
- __export(transformNormalizedConfig_exports, {
18
+ var legacy_exports = {};
19
+ __export(legacy_exports, {
20
+ checkIsLegacyConfig: () => checkIsLegacyConfig,
20
21
  transformNormalizedConfig: () => transformNormalizedConfig
21
22
  });
22
- module.exports = __toCommonJS(transformNormalizedConfig_exports);
23
+ module.exports = __toCommonJS(legacy_exports);
23
24
  var import_createToolsConfig = require("./createToolsConfig");
24
25
  var import_createSourceConfig = require("./createSourceConfig");
25
26
  var import_createOutputConfig = require("./createOutputConfig");
@@ -64,7 +65,11 @@ function transformNormalizedConfig(config) {
64
65
  }
65
66
  };
66
67
  }
68
+ function checkIsLegacyConfig(config) {
69
+ return Boolean(config.legacy);
70
+ }
67
71
  // Annotate the CommonJS export names for ESM import in node:
68
72
  0 && (module.exports = {
73
+ checkIsLegacyConfig,
69
74
  transformNormalizedConfig
70
75
  });
@@ -127,7 +127,9 @@ const buildCommand = (program, api) => __async(void 0, null, function* () {
127
127
  }
128
128
  }
129
129
  });
130
- var src_default = () => ({
130
+ var src_default = (options = {
131
+ bundler: "webpack"
132
+ }) => ({
131
133
  name: "@modern-js/app-tools",
132
134
  post: [
133
135
  "@modern-js/plugin-initialize",
@@ -140,7 +142,15 @@ var src_default = () => ({
140
142
  "@modern-js/plugin-polyfill"
141
143
  ],
142
144
  registerHook: import_hooks.hooks,
143
- usePlugins: [(0, import_initialize.default)(), (0, import_analyze.default)(), (0, import_plugin_lint.default)()],
145
+ usePlugins: [
146
+ (0, import_initialize.default)({
147
+ bundler: (options == null ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
148
+ }),
149
+ (0, import_analyze.default)({
150
+ bundler: (options == null ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
151
+ }),
152
+ (0, import_plugin_lint.default)()
153
+ ],
144
154
  setup: (api) => {
145
155
  const locale = (0, import_language.getLocaleLanguage)();
146
156
  import_locale.i18n.changeLanguage({ locale });
@@ -159,19 +169,19 @@ var src_default = () => ({
159
169
  program.command("deploy").usage("[options]").option(
160
170
  "-c --config <config>",
161
171
  import_locale.i18n.t(import_locale.localeKeys.command.shared.config)
162
- ).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action((options) => __async(this, null, function* () {
172
+ ).description(import_locale.i18n.t(import_locale.localeKeys.command.deploy.describe)).action((options2) => __async(this, null, function* () {
163
173
  const { build } = yield Promise.resolve().then(() => __toESM(require("./commands/build")));
164
174
  yield build(api);
165
175
  const { deploy } = yield Promise.resolve().then(() => __toESM(require("./commands/deploy")));
166
- yield deploy(api, options);
176
+ yield deploy(api, options2);
167
177
  process.exit(0);
168
178
  }));
169
179
  program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("--lang <lang>", import_locale.i18n.t(import_locale.localeKeys.command.new.lang)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option(
170
180
  "-c, --config <config>",
171
181
  import_locale.i18n.t(import_locale.localeKeys.command.new.config)
172
- ).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).action((options) => __async(this, null, function* () {
182
+ ).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).action((options2) => __async(this, null, function* () {
173
183
  const { MWANewAction } = yield Promise.resolve().then(() => __toESM(require("@modern-js/new-action")));
174
- yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale: options.lang || locale }));
184
+ yield MWANewAction(__spreadProps(__spreadValues({}, options2), { locale: options2.lang || locale }));
175
185
  }));
176
186
  program.command("inspect").description("inspect internal webpack config").option(
177
187
  `--env <env>`,
@@ -184,9 +194,9 @@ var src_default = () => ({
184
194
  ).option("--verbose", import_locale.i18n.t(import_locale.localeKeys.command.inspect.verbose)).option(
185
195
  "-c --config <config>",
186
196
  import_locale.i18n.t(import_locale.localeKeys.command.shared.config)
187
- ).action((options) => __async(this, null, function* () {
197
+ ).action((options2) => __async(this, null, function* () {
188
198
  const { inspect } = yield Promise.resolve().then(() => __toESM(require("./commands/inspect")));
189
- inspect(api, options);
199
+ inspect(api, options2);
190
200
  }));
191
201
  upgradeModel.defineCommand(program.command("upgrade"));
192
202
  });
@@ -59,15 +59,16 @@ __export(initialize_exports, {
59
59
  module.exports = __toCommonJS(initialize_exports);
60
60
  var import_utils = require("@modern-js/utils");
61
61
  var import_schema = require("../schema");
62
- var import_transformNormalizedConfig = require("../config/initial/transformNormalizedConfig");
63
62
  var import_config = require("../config");
64
- var initialize_default = () => ({
63
+ var initialize_default = ({
64
+ bundler
65
+ }) => ({
65
66
  name: "@modern-js/plugin-initialize",
66
67
  setup(api) {
67
68
  const config = () => {
68
69
  const appContext = api.useAppContext();
69
70
  const userConfig = api.useConfigContext();
70
- return (0, import_config.checkIsLegacyConfig)(userConfig) ? (0, import_config.createLegacyDefaultConfig)(appContext) : (0, import_config.createDefaultConfig)(appContext);
71
+ return (0, import_config.checkIsLegacyConfig)(userConfig) ? (0, import_config.createLegacyDefaultConfig)(appContext) : (0, import_config.createDefaultConfig)(appContext, bundler);
71
72
  };
72
73
  const validateSchema = () => {
73
74
  const userConfig = api.useConfigContext();
@@ -91,36 +92,42 @@ var initialize_default = () => ({
91
92
  )
92
93
  });
93
94
  api.setAppContext(appContext);
94
- const normalizedConfig = (0, import_config.checkIsLegacyConfig)(resolved) ? (0, import_transformNormalizedConfig.transformNormalizedConfig)(resolved) : resolved;
95
- return {
96
- resolved: {
97
- _raw: userConfig,
98
- source: normalizedConfig.source || {},
99
- server: __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
100
- port
101
- }),
102
- bff: normalizedConfig.bff || {},
103
- dev: normalizedConfig.dev || {},
104
- html: normalizedConfig.html || {},
105
- output: normalizedConfig.output || {},
106
- security: normalizedConfig.security || {},
107
- tools: normalizedConfig.tools || {},
108
- testing: normalizedConfig.testing || {},
109
- plugins: normalizedConfig.plugins || [],
110
- builderPlugins: normalizedConfig.builderPlugins || [],
111
- runtime: normalizedConfig.runtime || {},
112
- runtimeByEntries: normalizedConfig.runtimeByEntries || {},
113
- deploy: normalizedConfig.deploy || {},
114
- performance: normalizedConfig.performance || {},
115
- experiments: normalizedConfig.experiments || {},
116
- autoLoadPlugins: normalizedConfig.autoLoadPlugins || false
117
- }
118
- };
95
+ const normalizedConfig = (0, import_config.checkIsLegacyConfig)(resolved) ? (0, import_config.transformNormalizedConfig)(resolved) : resolved;
96
+ resolved._raw = userConfig;
97
+ resolved.server = __spreadProps(__spreadValues({}, normalizedConfig.server || {}), {
98
+ port
99
+ });
100
+ resolved.autoLoadPlugins = normalizedConfig.autoLoadPlugins || false;
101
+ stabilizeConfig(resolved, normalizedConfig, [
102
+ "source",
103
+ "bff",
104
+ "dev",
105
+ "html",
106
+ "output",
107
+ "tools",
108
+ "testing",
109
+ "plugins",
110
+ "builderPlugins",
111
+ "runtime",
112
+ "runtimeByEntries",
113
+ "deploy",
114
+ "performance"
115
+ ]);
116
+ if (bundler === "webpack") {
117
+ resolved.security = normalizedConfig.security || {};
118
+ resolved.experiments = normalizedConfig.experiments;
119
+ }
120
+ return { resolved };
119
121
  });
120
122
  }
121
123
  };
122
124
  }
123
125
  });
126
+ function stabilizeConfig(resolve, config, keys) {
127
+ keys.forEach((key) => {
128
+ resolve[key] = config[key] || {};
129
+ });
130
+ }
124
131
  function getServerPort(config) {
125
132
  return __async(this, null, function* () {
126
133
  const prodPort = config.server.port || 8080;
@@ -39,7 +39,7 @@ const ZH_LOCALE = {
39
39
  serve: { describe: "应用启动命令" },
40
40
  deploy: { describe: "部署应用命令" },
41
41
  new: {
42
- describe: "MWA 项目中执行生成器",
42
+ describe: "Web App 项目中执行生成器",
43
43
  debug: "开启 Debug 模式,打印调试日志信息",
44
44
  config: "生成器运行默认配置(JSON 字符串)",
45
45
  distTag: "生成器使用特殊的 npm Tag 版本",
@@ -0,0 +1,15 @@
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var utils_exports = {};
15
+ module.exports = __toCommonJS(utils_exports);
@@ -32,7 +32,9 @@ var NESTED_ROUTE = {
32
32
  PAGE_LOADER_FILE: "page.loader",
33
33
  LOADING_FILE: "loading",
34
34
  ERROR_FILE: "error",
35
- LOADER_FILE: "loader"
35
+ LOADER_FILE: "loader",
36
+ SPLATE_FILE: "$",
37
+ SPLATE_LOADER_FILE: "$.loader"
36
38
  };
37
39
  var APP_CONFIG_NAME = "config";
38
40
  var APP_INIT_EXPORTED = "init";
@@ -161,7 +161,7 @@ var createImportSpecifier = function(specifiers) {
161
161
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
162
162
  try {
163
163
  for(var _iterator = specifiers[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
164
- var _value = _step.value, local = _value.local, imported = _value.imported;
164
+ var _step_value = _step.value, local = _step_value.local, imported = _step_value.imported;
165
165
  if (local && imported) {
166
166
  named.push("".concat(imported, " as ").concat(local));
167
167
  } else if (local) {
@@ -198,7 +198,7 @@ var createImportStatements = function(statements) {
198
198
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
199
199
  try {
200
200
  var _loop = function() {
201
- var _value = _step.value, value = _value.value, specifiers = _value.specifiers, initialize = _value.initialize;
201
+ var _step_value = _step.value, value = _step_value.value, specifiers = _step_value.specifiers, initialize = _step_value.initialize;
202
202
  if (!seen.has(value)) {
203
203
  deDuplicated.push({
204
204
  value: value,
@@ -207,14 +207,14 @@ var createImportStatements = function(statements) {
207
207
  });
208
208
  seen.set(value, specifiers);
209
209
  } else {
210
- var _instance;
211
- var ref;
212
- (_instance = seen.get(value)).push.apply(_instance, _toConsumableArray(specifiers));
210
+ var _seen_get;
211
+ var _deDuplicated_modifyIndex;
212
+ (_seen_get = seen.get(value)).push.apply(_seen_get, _toConsumableArray(specifiers));
213
213
  var modifyIndex = deDuplicated.findIndex(function(v) {
214
214
  return v.value === value;
215
215
  });
216
- var ref1;
217
- var originInitialize = (ref1 = (ref = deDuplicated[modifyIndex]) === null || ref === void 0 ? void 0 : ref.initialize) !== null && ref1 !== void 0 ? ref1 : "";
216
+ var _deDuplicated_modifyIndex_initialize;
217
+ var originInitialize = (_deDuplicated_modifyIndex_initialize = (_deDuplicated_modifyIndex = deDuplicated[modifyIndex]) === null || _deDuplicated_modifyIndex === void 0 ? void 0 : _deDuplicated_modifyIndex.initialize) !== null && _deDuplicated_modifyIndex_initialize !== void 0 ? _deDuplicated_modifyIndex_initialize : "";
218
218
  deDuplicated[modifyIndex].initialize = originInitialize.concat("\n".concat(initialize || ""));
219
219
  }
220
220
  };
@@ -240,13 +240,13 @@ var createImportStatements = function(statements) {
240
240
  };
241
241
  var generateCode = function() {
242
242
  var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
243
- var ref, ref1, ref2, 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
  }
247
247
  function _generateEntryCode() {
248
248
  _generateEntryCode = _asyncToGenerator(function(entrypoint) {
249
- var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, ref, code2, _, _tmp, routesServerFile, code3, ref1, importStatements, plugins, ref2, renderFunction, exportStatement, code, entryFile, ref3, asyncEntryCode, bootstrapFile;
249
+ var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
250
250
  return __generator(this, function(_state) {
251
251
  switch(_state.label){
252
252
  case 0:
@@ -346,7 +346,7 @@ var generateCode = function() {
346
346
  ])
347
347
  ];
348
348
  case 6:
349
- ref = _state.sent(), code2 = ref.code;
349
+ _ref = _state.sent(), code2 = _ref.code;
350
350
  if (!(entrypoint.nestedRoutesEntry && mode)) return [
351
351
  3,
352
352
  9
@@ -386,7 +386,7 @@ var generateCode = function() {
386
386
  })
387
387
  ];
388
388
  case 11:
389
- ref1 = _state.sent(), importStatements = ref1.imports;
389
+ _ref1 = _state.sent(), importStatements = _ref1.imports;
390
390
  return [
391
391
  4,
392
392
  hookRunners.modifyEntryRuntimePlugins({
@@ -408,7 +408,7 @@ var generateCode = function() {
408
408
  })
409
409
  ];
410
410
  case 13:
411
- ref2 = _state.sent(), renderFunction = ref2.code;
411
+ _ref2 = _state.sent(), renderFunction = _ref2.code;
412
412
  return [
413
413
  4,
414
414
  hookRunners.modifyEntryExport({
@@ -438,7 +438,7 @@ var generateCode = function() {
438
438
  })
439
439
  ];
440
440
  case 15:
441
- ref3 = _state.sent(), asyncEntryCode = ref3.code;
441
+ _ref3 = _state.sent(), asyncEntryCode = _ref3.code;
442
442
  fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
443
443
  bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
444
444
  fs.outputFileSync(bootstrapFile, code, "utf8");
@@ -463,7 +463,7 @@ var generateCode = function() {
463
463
  case 0:
464
464
  internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
465
465
  hookRunners = api.useHookRunners();
466
- isV5 = typeof ((ref = config.runtime) === null || ref === void 0 ? void 0 : ref.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (ref1 = config.runtime) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.router) === null || ref2 === void 0 ? void 0 : ref2.mode) === "react-router-5";
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";
467
467
  mountId = config.html.mountId;
468
468
  getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
469
469
  return [
@@ -24,7 +24,7 @@ var ifAlreadyExists = function(entrypoints, checked) {
24
24
  };
25
25
  var getBundleEntry = function(appContext, config) {
26
26
  var appDirectory = appContext.appDirectory, packageName = appContext.packageName;
27
- var _source = config.source, disableDefaultEntries = _source.disableDefaultEntries, entries = _source.entries, entriesDir = _source.entriesDir;
27
+ var _config_source = config.source, disableDefaultEntries = _config_source.disableDefaultEntries, entries = _config_source.entries, entriesDir = _config_source.entriesDir;
28
28
  var defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config);
29
29
  if (entries) {
30
30
  Object.keys(entries).forEach(function(name) {
@@ -52,7 +52,7 @@ var getBundleEntry = function(appContext, config) {
52
52
  if (!disableDefaultEntries) {
53
53
  var entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || "");
54
54
  var found = defaults.find(function(param) {
55
- var entryName = param.entryName, entry = param.entry, _nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _nestedRoutesEntry === void 0 ? "" : _nestedRoutesEntry;
55
+ var entryName = param.entryName, entry = param.entry, _param_nestedRoutesEntry = param.nestedRoutesEntry, nestedRoutesEntry = _param_nestedRoutesEntry === void 0 ? "" : _param_nestedRoutesEntry;
56
56
  return entryName === packageName || path.dirname(entry) === entriesDirAbs || path.dirname(nestedRoutesEntry) === entriesDirAbs;
57
57
  });
58
58
  found && (found.entryName = MAIN_ENTRY_NAME);
@@ -67,7 +67,7 @@ var layoutNameAbbr = function(filePath) {
67
67
  };
68
68
  var parents = [];
69
69
  var recursiveReadDir = function(param) {
70
- var dir = param.dir, routes = param.routes, _basePath = param.basePath, basePath = _basePath === void 0 ? "/" : _basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
70
+ var dir = param.dir, routes = param.routes, _param_basePath = param.basePath, basePath = _param_basePath === void 0 ? "/" : _param_basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
71
71
  var hasDynamicRoute = false;
72
72
  var resetParent = false;
73
73
  var parent = parents[parents.length - 1];
@@ -67,7 +67,7 @@ var layoutNameAbbr = function(filePath) {
67
67
  };
68
68
  var parents = [];
69
69
  var recursiveReadDirLegacy = function(param) {
70
- var dir = param.dir, routes = param.routes, _basePath = param.basePath, basePath = _basePath === void 0 ? "/" : _basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
70
+ var dir = param.dir, routes = param.routes, _param_basePath = param.basePath, basePath = _param_basePath === void 0 ? "/" : _param_basePath, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias;
71
71
  var hasDynamicRoute = false;
72
72
  var resetParent = false;
73
73
  var parent = parents[parents.length - 1];
@@ -80,7 +80,7 @@ var scanDir = function(dirs) {
80
80
  };
81
81
  var getFileSystemEntry = function(appContext, config) {
82
82
  var appDirectory = appContext.appDirectory;
83
- var _source = config.source, entriesDir = _source.entriesDir, disableEntryDirs = _source.disableEntryDirs;
83
+ var _config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs;
84
84
  var disabledDirs = [];
85
85
  if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
86
86
  disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {