@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.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 (126) hide show
  1. package/CHANGELOG.md +181 -0
  2. package/dist/js/modern/analyze/generateCode.js +29 -37
  3. package/dist/js/modern/analyze/getBundleEntry.js +4 -12
  4. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
  6. package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
  7. package/dist/js/modern/analyze/getFileSystemEntry.js +4 -17
  8. package/dist/js/modern/analyze/getHtmlTemplate.js +2 -9
  9. package/dist/js/modern/analyze/getServerRoutes.js +15 -32
  10. package/dist/js/modern/analyze/index.js +79 -22
  11. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
  12. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
  13. package/dist/js/modern/analyze/nestedRoutes.js +8 -33
  14. package/dist/js/modern/analyze/templates.js +22 -37
  15. package/dist/js/modern/analyze/utils.js +0 -7
  16. package/dist/js/modern/builder/builderPlugins/compatModern.js +30 -48
  17. package/dist/js/modern/builder/createHtmlConfig.js +2 -2
  18. package/dist/js/modern/builder/createOutputConfig.js +7 -4
  19. package/dist/js/modern/builder/createSourceConfig.js +0 -11
  20. package/dist/js/modern/builder/createToolsConfig.js +3 -10
  21. package/dist/js/modern/builder/index.js +24 -22
  22. package/dist/js/modern/builder/share.js +0 -4
  23. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
  24. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
  25. package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
  26. package/dist/js/modern/commands/build.js +6 -46
  27. package/dist/js/modern/commands/dev.js +4 -16
  28. package/dist/js/modern/commands/inspect.js +3 -20
  29. package/dist/js/modern/commands/start.js +0 -2
  30. package/dist/js/modern/index.js +6 -15
  31. package/dist/js/modern/utils/config.js +1 -12
  32. package/dist/js/modern/utils/createServer.js +0 -5
  33. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
  34. package/dist/js/modern/utils/printInstructions.js +2 -1
  35. package/dist/js/modern/utils/routes.js +0 -2
  36. package/dist/js/node/analyze/generateCode.js +29 -60
  37. package/dist/js/node/analyze/getBundleEntry.js +4 -18
  38. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
  39. package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
  40. package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
  41. package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
  42. package/dist/js/node/analyze/getFileSystemEntry.js +4 -25
  43. package/dist/js/node/analyze/getHtmlTemplate.js +2 -23
  44. package/dist/js/node/analyze/getServerRoutes.js +14 -40
  45. package/dist/js/node/analyze/index.js +79 -32
  46. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
  47. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
  48. package/dist/js/node/analyze/nestedRoutes.js +8 -41
  49. package/dist/js/node/analyze/templates.js +22 -47
  50. package/dist/js/node/analyze/utils.js +0 -20
  51. package/dist/js/node/builder/builderPlugins/compatModern.js +30 -59
  52. package/dist/js/node/builder/createHtmlConfig.js +2 -10
  53. package/dist/js/node/builder/createOutputConfig.js +7 -6
  54. package/dist/js/node/builder/createSourceConfig.js +0 -17
  55. package/dist/js/node/builder/createToolsConfig.js +3 -12
  56. package/dist/js/node/builder/index.js +24 -36
  57. package/dist/js/node/builder/share.js +0 -12
  58. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
  59. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
  60. package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
  61. package/dist/js/node/commands/build.js +4 -57
  62. package/dist/js/node/commands/deploy.js +0 -2
  63. package/dist/js/node/commands/dev.js +3 -27
  64. package/dist/js/node/commands/index.js +0 -6
  65. package/dist/js/node/commands/inspect.js +3 -27
  66. package/dist/js/node/commands/start.js +0 -11
  67. package/dist/js/node/exports/server.js +0 -1
  68. package/dist/js/node/hooks.js +0 -2
  69. package/dist/js/node/index.js +7 -34
  70. package/dist/js/node/locale/index.js +0 -4
  71. package/dist/js/node/utils/commands.js +0 -2
  72. package/dist/js/node/utils/config.js +1 -25
  73. package/dist/js/node/utils/createServer.js +0 -15
  74. package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
  75. package/dist/js/node/utils/language.js +0 -2
  76. package/dist/js/node/utils/printInstructions.js +2 -5
  77. package/dist/js/node/utils/routes.js +0 -5
  78. package/dist/js/treeshaking/analyze/generateCode.js +57 -100
  79. package/dist/js/treeshaking/analyze/getBundleEntry.js +11 -19
  80. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
  81. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
  82. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
  83. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +4 -17
  84. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +2 -26
  85. package/dist/js/treeshaking/analyze/getServerRoutes.js +24 -37
  86. package/dist/js/treeshaking/analyze/index.js +185 -65
  87. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
  88. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
  89. package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
  90. package/dist/js/treeshaking/analyze/templates.js +31 -50
  91. package/dist/js/treeshaking/analyze/utils.js +7 -14
  92. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +40 -59
  93. package/dist/js/treeshaking/builder/createHtmlConfig.js +15 -15
  94. package/dist/js/treeshaking/builder/createOutputConfig.js +26 -23
  95. package/dist/js/treeshaking/builder/createSourceConfig.js +7 -19
  96. package/dist/js/treeshaking/builder/createToolsConfig.js +16 -21
  97. package/dist/js/treeshaking/builder/index.js +38 -49
  98. package/dist/js/treeshaking/builder/share.js +0 -4
  99. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
  100. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
  101. package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
  102. package/dist/js/treeshaking/commands/build.js +26 -111
  103. package/dist/js/treeshaking/commands/deploy.js +0 -3
  104. package/dist/js/treeshaking/commands/dev.js +13 -35
  105. package/dist/js/treeshaking/commands/inspect.js +5 -28
  106. package/dist/js/treeshaking/commands/start.js +0 -9
  107. package/dist/js/treeshaking/index.js +2 -39
  108. package/dist/js/treeshaking/utils/config.js +1 -17
  109. package/dist/js/treeshaking/utils/createServer.js +0 -10
  110. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
  111. package/dist/js/treeshaking/utils/printInstructions.js +0 -5
  112. package/dist/js/treeshaking/utils/routes.js +0 -4
  113. package/dist/types/analyze/index.d.ts +2 -3
  114. package/dist/types/analyze/nestedRoutes.d.ts +1 -1
  115. package/dist/types/analyze/templates.d.ts +3 -1
  116. package/dist/types/builder/builderPlugins/compatModern.d.ts +0 -1
  117. package/dist/types/builder/index.d.ts +2 -6
  118. package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
  119. package/dist/types/commands/inspect.d.ts +1 -4
  120. package/dist/types/index.d.ts +0 -2
  121. package/dist/types/utils/config.d.ts +0 -1
  122. package/package.json +23 -22
  123. package/dist/js/modern/utils/createCompiler.js +0 -58
  124. package/dist/js/node/utils/createCompiler.js +0 -75
  125. package/dist/js/treeshaking/utils/createCompiler.js +0 -117
  126. package/dist/types/utils/createCompiler.d.ts +0 -12
@@ -4,17 +4,15 @@ import { dirname, isAbsolute, posix, sep } from 'path';
4
4
  import { globby, mergeAlias, findMonorepoRoot, isModernjsMonorepo } from '@modern-js/utils';
5
5
  export function createSourceConfig(normalizedConfig, appContext) {
6
6
  var _normalizedConfig$sou = normalizedConfig.source,
7
- alias = _normalizedConfig$sou.alias,
8
- envVars = _normalizedConfig$sou.envVars,
9
- globalVars = _normalizedConfig$sou.globalVars,
10
- include = _normalizedConfig$sou.include,
11
- moduleScopes = _normalizedConfig$sou.moduleScopes,
12
- preEntry = _normalizedConfig$sou.preEntry;
7
+ alias = _normalizedConfig$sou.alias,
8
+ envVars = _normalizedConfig$sou.envVars,
9
+ globalVars = _normalizedConfig$sou.globalVars,
10
+ include = _normalizedConfig$sou.include,
11
+ moduleScopes = _normalizedConfig$sou.moduleScopes,
12
+ preEntry = _normalizedConfig$sou.preEntry;
13
13
  var builderGlobalVars = globalVars || {};
14
-
15
14
  var _iterator = _createForOfIteratorHelper(envVars || []),
16
- _step;
17
-
15
+ _step;
18
16
  try {
19
17
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
20
18
  var envVar = _step.value;
@@ -26,7 +24,6 @@ export function createSourceConfig(normalizedConfig, appContext) {
26
24
  } finally {
27
25
  _iterator.f();
28
26
  }
29
-
30
27
  var builderModuleScope = createBuilderModuleScope(moduleScopes);
31
28
  var builderInclude = createBuilderInclude(include, appContext);
32
29
  return {
@@ -46,21 +43,16 @@ export function createBuilderInclude(include, appContext) {
46
43
  if (isAbsolute(include)) {
47
44
  return include;
48
45
  }
49
-
50
46
  return new RegExp(include);
51
47
  }
52
-
53
48
  return include;
54
49
  }).concat(defaultInclude); // concat default Include
55
50
 
56
51
  var root = findMonorepoRoot(appContext.appDirectory);
57
-
58
52
  if (!root) {
59
53
  return transformInclude;
60
54
  }
61
-
62
55
  var modernjsMonorepo = isModernjsMonorepo(root);
63
-
64
56
  if (modernjsMonorepo) {
65
57
  var paths = globby.sync(posix.join(root, 'features', '**', 'package.json'), {
66
58
  ignore: ['**/node_modules/**/*']
@@ -69,14 +61,12 @@ export function createBuilderInclude(include, appContext) {
69
61
  });
70
62
  return [].concat(_toConsumableArray(paths), _toConsumableArray(transformInclude));
71
63
  }
72
-
73
64
  return transformInclude;
74
65
  }
75
66
  export function createBuilderModuleScope(moduleScopes) {
76
67
  if (moduleScopes) {
77
68
  var builderModuleScope = [];
78
69
  var DEFAULT_SCOPES = ['./src', './shared', /node_modules/];
79
-
80
70
  if (Array.isArray(moduleScopes)) {
81
71
  if (isPrimitiveScope(moduleScopes)) {
82
72
  builderModuleScope = DEFAULT_SCOPES.concat(moduleScopes);
@@ -86,12 +76,10 @@ export function createBuilderModuleScope(moduleScopes) {
86
76
  } else {
87
77
  builderModuleScope = [DEFAULT_SCOPES, moduleScopes];
88
78
  }
89
-
90
79
  return builderModuleScope;
91
80
  } else {
92
81
  return undefined;
93
82
  }
94
-
95
83
  function isPrimitiveScope(items) {
96
84
  return items.every(function (item) {
97
85
  return typeof item === 'string' || Object.prototype.toString.call(item) === '[object RegExp]';
@@ -4,22 +4,22 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
4
  import { applyOptionsChain } from '@modern-js/utils';
5
5
  export function createToolsConfig(normalizedConfig) {
6
6
  var _normalizedConfig$out = normalizedConfig.output,
7
- disableCssExtract = _normalizedConfig$out.disableCssExtract,
8
- enableTsLoader = _normalizedConfig$out.enableTsLoader;
7
+ disableCssExtract = _normalizedConfig$out.disableCssExtract,
8
+ enableTsLoader = _normalizedConfig$out.enableTsLoader;
9
9
  var _normalizedConfig$too = normalizedConfig.tools,
10
- autoprefixer = _normalizedConfig$too.autoprefixer,
11
- babel = _normalizedConfig$too.babel,
12
- minifyCss = _normalizedConfig$too.minifyCss,
13
- terser = _normalizedConfig$too.terser,
14
- webpack = _normalizedConfig$too.webpack,
15
- webpackChain = _normalizedConfig$too.webpackChain,
16
- tsLoader = _normalizedConfig$too.tsLoader,
17
- styledComponents = _normalizedConfig$too.styledComponents,
18
- sass = _normalizedConfig$too.sass,
19
- postcss = _normalizedConfig$too.postcss,
20
- less = _normalizedConfig$too.less,
21
- htmlPlugin = _normalizedConfig$too.htmlPlugin,
22
- lodash = _normalizedConfig$too.lodash;
10
+ autoprefixer = _normalizedConfig$too.autoprefixer,
11
+ babel = _normalizedConfig$too.babel,
12
+ minifyCss = _normalizedConfig$too.minifyCss,
13
+ terser = _normalizedConfig$too.terser,
14
+ webpack = _normalizedConfig$too.webpack,
15
+ webpackChain = _normalizedConfig$too.webpackChain,
16
+ tsLoader = _normalizedConfig$too.tsLoader,
17
+ styledComponents = _normalizedConfig$too.styledComponents,
18
+ sass = _normalizedConfig$too.sass,
19
+ postcss = _normalizedConfig$too.postcss,
20
+ less = _normalizedConfig$too.less,
21
+ htmlPlugin = _normalizedConfig$too.htmlPlugin,
22
+ lodash = _normalizedConfig$too.lodash;
23
23
  var builderTsLoader = createBuilderTsLoader(tsLoader, enableTsLoader);
24
24
  var builderTsChecker = createBuilderTsChecker(normalizedConfig.output);
25
25
  return {
@@ -48,14 +48,11 @@ export function createToolsConfig(normalizedConfig) {
48
48
  }].concat(_toConsumableArray(Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [htmlPlugin] : []))
49
49
  };
50
50
  }
51
-
52
51
  function createBuilderTsLoader(tsLoader, enableTsLoader) {
53
52
  var useTsLoader = Boolean(enableTsLoader);
54
-
55
53
  if (!useTsLoader) {
56
54
  return undefined;
57
55
  }
58
-
59
56
  var defaultTsLoader = {
60
57
  compilerOptions: {
61
58
  target: 'es5',
@@ -68,12 +65,10 @@ function createBuilderTsLoader(tsLoader, enableTsLoader) {
68
65
  return applyOptionsChain(defaultTsLoader, tsLoader, utils);
69
66
  };
70
67
  }
71
-
72
68
  export function createBuilderTsChecker(output) {
73
- if (output.enableTsLoader || output.disableTsChecker) {
69
+ if (output.enableTsLoader) {
74
70
  return false;
75
71
  }
76
-
77
72
  var defaultTsChecker = {
78
73
  issue: {
79
74
  include: [{
@@ -1,59 +1,58 @@
1
- import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
2
1
  import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
3
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import { createBuilder } from '@modern-js/builder';
5
5
  import { builderWebpackProvider } from '@modern-js/builder-webpack-provider';
6
- import { applyOptionsChain } from '@modern-js/utils';
6
+ import { applyOptionsChain, isUseSSRBundle } from '@modern-js/utils';
7
7
  import { PluginCompatModern } from "./builderPlugins/compatModern";
8
8
  import { createHtmlConfig } from "./createHtmlConfig";
9
9
  import { createOutputConfig } from "./createOutputConfig";
10
10
  import { createSourceConfig } from "./createSourceConfig";
11
11
  import { createToolsConfig } from "./createToolsConfig";
12
- export default /*#__PURE__*/(function () {
13
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
14
- var _ref$target, target, normalizedConfig, appContext, compatPluginConfig, targets, builderConfig, webpackProvider, builderOptions, builder;
15
-
12
+ function getBuilderTargets(normalizedConfig) {
13
+ var targets = ['web'];
14
+ if (normalizedConfig.output.enableModernMode && !targets.includes('modern-web')) {
15
+ targets.push('modern-web');
16
+ }
17
+ if (isUseSSRBundle(normalizedConfig)) {
18
+ targets.push('node');
19
+ }
20
+ return targets;
21
+ }
22
+ export function createBuilderForEdenX(_x) {
23
+ return _createBuilderForEdenX.apply(this, arguments);
24
+ }
25
+ function _createBuilderForEdenX() {
26
+ _createBuilderForEdenX = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
27
+ var normalizedConfig, appContext, compatPluginConfig, builderConfig, webpackProvider, target, builderOptions, builder;
16
28
  return _regeneratorRuntime().wrap(function _callee$(_context) {
17
29
  while (1) {
18
30
  switch (_context.prev = _context.next) {
19
31
  case 0:
20
- _ref$target = _ref.target, target = _ref$target === void 0 ? 'web' : _ref$target, normalizedConfig = _ref.normalizedConfig, appContext = _ref.appContext, compatPluginConfig = _ref.compatPluginConfig;
21
- targets = Array.isArray(target) ? target : [target];
22
-
23
- if (normalizedConfig.output.enableModernMode && !targets.includes('modern-web')) {
24
- targets.push('modern-web');
25
- }
26
-
32
+ normalizedConfig = _ref.normalizedConfig, appContext = _ref.appContext, compatPluginConfig = _ref.compatPluginConfig;
27
33
  builderConfig = createBuilderProviderConfig(normalizedConfig, appContext); // create webpack provider
28
-
29
34
  webpackProvider = builderWebpackProvider({
30
35
  builderConfig: builderConfig
31
36
  });
37
+ target = getBuilderTargets(normalizedConfig);
32
38
  builderOptions = createBuilderOptions(target, appContext);
33
- _context.next = 8;
39
+ _context.next = 7;
34
40
  return createBuilder(webpackProvider, builderOptions);
35
-
36
- case 8:
41
+ case 7:
37
42
  builder = _context.sent;
38
- _context.next = 11;
43
+ _context.next = 10;
39
44
  return applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig);
40
-
41
- case 11:
45
+ case 10:
42
46
  return _context.abrupt("return", builder);
43
-
44
- case 12:
47
+ case 11:
45
48
  case "end":
46
49
  return _context.stop();
47
50
  }
48
51
  }
49
52
  }, _callee);
50
53
  }));
51
-
52
- return function (_x) {
53
- return _ref2.apply(this, arguments);
54
- };
55
- })();
56
-
54
+ return _createBuilderForEdenX.apply(this, arguments);
55
+ }
57
56
  function createBuilderProviderConfig(normalizedConfig, appContext) {
58
57
  var source = createSourceConfig(normalizedConfig, appContext);
59
58
  var html = createHtmlConfig(normalizedConfig, appContext);
@@ -64,33 +63,33 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
64
63
  html: html,
65
64
  output: output,
66
65
  tools: tools,
66
+ dev: {
67
+ https: normalizedConfig.dev.https,
68
+ assetPrefix: normalizedConfig.dev.assetPrefix
69
+ },
67
70
  performance: {
68
71
  // `@modern-js/webpack` used to remove moment locale by default
69
72
  removeMomentLocale: true
70
73
  }
71
74
  };
72
75
  }
73
-
74
76
  export function createBuilderOptions(target, appContext) {
75
77
  // create entries
78
+
76
79
  var entries = {};
77
80
  var _appContext$entrypoin = appContext.entrypoints,
78
- entrypoints = _appContext$entrypoin === void 0 ? [] : _appContext$entrypoin,
79
- checkedEntries = appContext.checkedEntries;
80
-
81
+ entrypoints = _appContext$entrypoin === void 0 ? [] : _appContext$entrypoin,
82
+ checkedEntries = appContext.checkedEntries;
81
83
  var _iterator = _createForOfIteratorHelper(entrypoints),
82
- _step;
83
-
84
+ _step;
84
85
  try {
85
86
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
86
87
  var _step$value = _step.value,
87
- entryName = _step$value.entryName,
88
- entry = _step$value.entry;
89
-
88
+ entryName = _step$value.entryName,
89
+ entry = _step$value.entry;
90
90
  if (checkedEntries && !checkedEntries.includes(entryName)) {
91
91
  continue;
92
92
  }
93
-
94
93
  if (entryName in entries) {
95
94
  entries[entryName].push(entry);
96
95
  } else {
@@ -102,7 +101,6 @@ export function createBuilderOptions(target, appContext) {
102
101
  } finally {
103
102
  _iterator.f();
104
103
  }
105
-
106
104
  return {
107
105
  cwd: appContext.appDirectory,
108
106
  target: target,
@@ -111,18 +109,16 @@ export function createBuilderOptions(target, appContext) {
111
109
  framework: appContext.metaName
112
110
  };
113
111
  }
112
+
114
113
  /**
115
114
  * register builder Plugin by condition
116
115
  */
117
-
118
116
  function applyBuilderPlugins(_x2, _x3, _x4, _x5) {
119
117
  return _applyBuilderPlugins.apply(this, arguments);
120
118
  }
121
-
122
119
  function _applyBuilderPlugins() {
123
120
  _applyBuilderPlugins = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(builder, normalizedConfig, appContext, compatPluginConfig) {
124
121
  var _yield$import, PluginNodePolyfill, esbuildOptions, _yield$import2, PluginEsbuild;
125
-
126
122
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
127
123
  while (1) {
128
124
  switch (_context2.prev = _context2.next) {
@@ -131,25 +127,20 @@ function _applyBuilderPlugins() {
131
127
  _context2.next = 6;
132
128
  break;
133
129
  }
134
-
135
130
  _context2.next = 3;
136
131
  return import('@modern-js/builder-plugin-node-polyfill');
137
-
138
132
  case 3:
139
133
  _yield$import = _context2.sent;
140
134
  PluginNodePolyfill = _yield$import.PluginNodePolyfill;
141
135
  builder.addPlugins([PluginNodePolyfill()]);
142
-
143
136
  case 6:
144
137
  if (!normalizedConfig.tools.esbuild) {
145
138
  _context2.next = 13;
146
139
  break;
147
140
  }
148
-
149
141
  esbuildOptions = normalizedConfig.tools.esbuild;
150
142
  _context2.next = 10;
151
143
  return import('@modern-js/builder-plugin-esbuild');
152
-
153
144
  case 10:
154
145
  _yield$import2 = _context2.sent;
155
146
  PluginEsbuild = _yield$import2.PluginEsbuild;
@@ -157,10 +148,8 @@ function _applyBuilderPlugins() {
157
148
  loader: false,
158
149
  minimize: applyOptionsChain({}, esbuildOptions)
159
150
  })]);
160
-
161
151
  case 13:
162
152
  builder.addPlugins([PluginCompatModern(appContext, normalizedConfig, compatPluginConfig)]);
163
-
164
153
  case 14:
165
154
  case "end":
166
155
  return _context2.stop();
@@ -6,7 +6,6 @@ export function createCopyPattern(appContext, config, patternsType, chain) {
6
6
  var uploadDir = path.posix.join(configDir.replace(/\\/g, '/'), 'upload');
7
7
  var publicDir = path.posix.join(configDir.replace(/\\/g, '/'), 'public');
8
8
  var minifiedJsRexExp = /\.min\.js/;
9
-
10
9
  var info = function info(file) {
11
10
  return {
12
11
  // If the file name ends with `.min.js`, we assume it's a compressed file.
@@ -15,12 +14,10 @@ export function createCopyPattern(appContext, config, patternsType, chain) {
15
14
  minimized: minifiedJsRexExp.test(file.sourceFilename)
16
15
  };
17
16
  };
18
-
19
17
  if (patternsType === 'public') {
20
18
  if (!chain) {
21
19
  throw new Error("expect get a webpackChain, but receive 'undefined'");
22
20
  }
23
-
24
21
  return {
25
22
  info: info,
26
23
  from: '**/*',
@@ -32,7 +29,6 @@ export function createCopyPattern(appContext, config, patternsType, chain) {
32
29
  if (!/\.html?$/.test(absoluteFrom)) {
33
30
  return content;
34
31
  }
35
-
36
32
  return lodashTemplate(content.toString('utf8'))({
37
33
  assetPrefix: removeTailSlash(chain.output.get('publicPath'))
38
34
  });
@@ -6,36 +6,26 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
6
6
  export var HtmlAsyncChunkPlugin = /*#__PURE__*/function () {
7
7
  function HtmlAsyncChunkPlugin(htmlWebpackPlugin) {
8
8
  _classCallCheck(this, HtmlAsyncChunkPlugin);
9
-
10
9
  _defineProperty(this, "name", void 0);
11
-
12
10
  _defineProperty(this, "htmlWebpackPlugin", void 0);
13
-
14
11
  this.name = 'HtmlAsyncChunkPlugin';
15
12
  this.htmlWebpackPlugin = htmlWebpackPlugin;
16
13
  }
17
-
18
14
  _createClass(HtmlAsyncChunkPlugin, [{
19
15
  key: "apply",
20
16
  value: function apply(compiler) {
21
17
  var _this = this;
22
-
23
18
  compiler.hooks.compilation.tap(this.name, function (compilation) {
24
19
  var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
25
-
26
20
  hooks.alterAssetTagGroups.tap(_this.name, function (assets) {
27
21
  var tags = [].concat(_toConsumableArray(assets.headTags), _toConsumableArray(assets.bodyTags));
28
-
29
22
  var _iterator = _createForOfIteratorHelper(tags),
30
- _step;
31
-
23
+ _step;
32
24
  try {
33
25
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
34
26
  var tag = _step.value;
35
-
36
27
  if (tag.tagName === 'script') {
37
28
  var attributes = tag.attributes;
38
-
39
29
  if (attributes && attributes.defer === true) {
40
30
  attributes.async = true;
41
31
  delete attributes.defer;
@@ -47,12 +37,10 @@ export var HtmlAsyncChunkPlugin = /*#__PURE__*/function () {
47
37
  } finally {
48
38
  _iterator.f();
49
39
  }
50
-
51
40
  return assets;
52
41
  });
53
42
  });
54
43
  }
55
44
  }]);
56
-
57
45
  return HtmlAsyncChunkPlugin;
58
46
  }();
@@ -4,50 +4,38 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
4
  export var BottomTemplatePlugin = /*#__PURE__*/function () {
5
5
  function BottomTemplatePlugin(htmlWebpackPlugin) {
6
6
  _classCallCheck(this, BottomTemplatePlugin);
7
-
8
7
  _defineProperty(this, "htmlWebpackPlugin", void 0);
9
-
10
8
  _defineProperty(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
11
-
12
9
  _defineProperty(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
13
-
14
10
  _defineProperty(this, "name", void 0);
15
-
16
11
  this.htmlWebpackPlugin = htmlWebpackPlugin;
17
12
  this.name = 'bottom-template';
18
13
  }
19
-
20
14
  _createClass(BottomTemplatePlugin, [{
21
15
  key: "apply",
22
16
  value: function apply(compiler) {
23
17
  var _this = this;
24
-
25
18
  compiler.hooks.compilation.tap(this.name, function (compilation) {
26
19
  _this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function (data) {
27
20
  var _data$plugin$options;
28
-
29
21
  if (!((_data$plugin$options = data.plugin.options) !== null && _data$plugin$options !== void 0 && _data$plugin$options.__internal__)) {
30
22
  return data;
31
- } // 含有 <!--<?- bottomTemplate ?>--> 占位符时才需要注入 bottom.html
32
-
33
-
23
+ }
24
+ // 含有 <!--<?- bottomTemplate ?>--> 占位符时才需要注入 bottom.html
34
25
  if (_this.bottomTemplateReg.test(data.html)) {
35
26
  // 清空占位符
36
27
  data.html = data.html.replace(_this.bottomTemplateReg, '');
37
28
  var bottomTemplate = data.plugin.options.bottomTemplate;
38
-
39
29
  if (bottomTemplate) {
40
30
  data.html = data.html.replace(_this.bodyRegExp, function (match) {
41
31
  return "\n".concat(bottomTemplate, "\n").concat(match);
42
32
  });
43
33
  }
44
34
  }
45
-
46
35
  return data;
47
36
  });
48
37
  });
49
38
  }
50
39
  }]);
51
-
52
40
  return BottomTemplatePlugin;
53
41
  }();
@@ -0,0 +1,121 @@
1
+ import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
2
+ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
3
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
6
+ import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
7
+ import _createClass from "@babel/runtime/helpers/esm/createClass";
8
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
9
+ import path from 'path';
10
+ import { fs, ROUTE_MANIFEST, logger, ROUTE_MINIFEST_FILE } from '@modern-js/utils';
11
+ var PLUGIN_NAME = 'ModernjsRoutePlugin';
12
+ var RouterPlugin = /*#__PURE__*/function () {
13
+ function RouterPlugin(options) {
14
+ _classCallCheck(this, RouterPlugin);
15
+ _defineProperty(this, "existNestedRoutes", void 0);
16
+ this.existNestedRoutes = options.existNestedRoutes;
17
+ }
18
+ _createClass(RouterPlugin, [{
19
+ key: "apply",
20
+ value: function apply(compiler) {
21
+ var existNestedRoutes = this.existNestedRoutes;
22
+ var target = compiler.options.target;
23
+ if (target === 'node' || Array.isArray(target) && target.includes('node')) {
24
+ return;
25
+ }
26
+ if (!existNestedRoutes) {
27
+ return;
28
+ }
29
+ var webpack = compiler.webpack;
30
+ var Compilation = webpack.Compilation,
31
+ sources = webpack.sources;
32
+ var RawSource = sources.RawSource;
33
+ var PROCESS_ASSETS_STAGE_REPORT = Compilation.PROCESS_ASSETS_STAGE_REPORT;
34
+ var outputPath = compiler.options.output.path;
35
+ var newAssetsMap = new Map();
36
+ var normalizePath = function normalizePath(path) {
37
+ if (!path.endsWith('/')) {
38
+ return "".concat(path, "/");
39
+ }
40
+ return path;
41
+ };
42
+ compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function (compilation) {
43
+ compilation.hooks.processAssets.tapPromise({
44
+ name: PLUGIN_NAME,
45
+ stage: PROCESS_ASSETS_STAGE_REPORT
46
+ }, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
47
+ var stats, publicPath, routeAssets, namedChunkGroups, assetsByChunkName, _i, _Object$entries, _Object$entries$_i, name, chunkGroup, manifest, injectedContent, entrypointsArray, entryChunkIds, entryChunks, entryChunkFiles, _iterator, _step, file, asset, newContent, filename;
48
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
49
+ while (1) {
50
+ switch (_context.prev = _context.next) {
51
+ case 0:
52
+ stats = compilation.getStats().toJson({
53
+ chunkGroups: true,
54
+ chunks: true
55
+ });
56
+ publicPath = stats.publicPath;
57
+ routeAssets = {};
58
+ namedChunkGroups = stats.namedChunkGroups, assetsByChunkName = stats.assetsByChunkName;
59
+ if (!(!namedChunkGroups || !assetsByChunkName)) {
60
+ _context.next = 7;
61
+ break;
62
+ }
63
+ logger.warn('Route manifest does not exist, performance will be affected');
64
+ return _context.abrupt("return");
65
+ case 7:
66
+ for (_i = 0, _Object$entries = Object.entries(namedChunkGroups); _i < _Object$entries.length; _i++) {
67
+ _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2), name = _Object$entries$_i[0], chunkGroup = _Object$entries$_i[1];
68
+ routeAssets[name] = {
69
+ chunkIds: chunkGroup.chunks,
70
+ assets: assetsByChunkName[name].map(function (item) {
71
+ return publicPath ? normalizePath(publicPath) + item : item;
72
+ })
73
+ };
74
+ }
75
+ manifest = {
76
+ routeAssets: routeAssets
77
+ };
78
+ injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest), ";\n })();\n ");
79
+ entrypointsArray = Array.from(compilation.entrypoints.entries());
80
+ entryChunkIds = entrypointsArray.map(function (entrypoint) {
81
+ return entrypoint[0];
82
+ });
83
+ entryChunks = _toConsumableArray(compilation.chunks).filter(function (chunk) {
84
+ return entryChunkIds.includes(chunk.name);
85
+ });
86
+ entryChunkFiles = entryChunks.map(function (chunk) {
87
+ return _toConsumableArray(chunk.files)[0];
88
+ });
89
+ _iterator = _createForOfIteratorHelper(entryChunkFiles);
90
+ try {
91
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
92
+ file = _step.value;
93
+ asset = compilation.assets[file];
94
+ newContent = "".concat(injectedContent).concat(asset.source().toString());
95
+ newAssetsMap.set(path.join(outputPath, file), newContent);
96
+ compilation.updateAsset(file, new RawSource(newContent));
97
+ }
98
+ } catch (err) {
99
+ _iterator.e(err);
100
+ } finally {
101
+ _iterator.f();
102
+ }
103
+ filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
104
+ _context.next = 19;
105
+ return fs.ensureFile(filename);
106
+ case 19:
107
+ _context.next = 21;
108
+ return fs.writeFile(filename, JSON.stringify(manifest, null, 2));
109
+ case 21:
110
+ case "end":
111
+ return _context.stop();
112
+ }
113
+ }
114
+ }, _callee);
115
+ })));
116
+ });
117
+ }
118
+ }]);
119
+ return RouterPlugin;
120
+ }();
121
+ export { RouterPlugin as default };