@modern-js/app-tools 2.0.0-beta.2 → 2.0.0-beta.3

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 (60) hide show
  1. package/CHANGELOG.md +251 -0
  2. package/bin/modern.js +10 -1
  3. package/dist/js/modern/analyze/constants.js +2 -0
  4. package/dist/js/modern/analyze/generateCode.js +38 -18
  5. package/dist/js/modern/analyze/getServerRoutes.js +3 -3
  6. package/dist/js/modern/analyze/nestedRoutes.js +17 -6
  7. package/dist/js/modern/analyze/templates.js +59 -27
  8. package/dist/js/modern/analyze/utils.js +30 -4
  9. package/dist/js/modern/builder/builderPlugins/compatModern.js +6 -1
  10. package/dist/js/modern/builder/index.js +3 -5
  11. package/dist/js/modern/builder/loaders/routerLoader.js +20 -0
  12. package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -0
  13. package/dist/js/modern/commands/dev.js +23 -27
  14. package/dist/js/modern/commands/start.js +0 -1
  15. package/dist/js/modern/config/default.js +0 -1
  16. package/dist/js/modern/config/initial/createOutputConfig.js +3 -0
  17. package/dist/js/modern/utils/createFileWatcher.js +1 -1
  18. package/dist/js/modern/utils/restart.js +1 -1
  19. package/dist/js/node/analyze/constants.js +5 -1
  20. package/dist/js/node/analyze/generateCode.js +36 -16
  21. package/dist/js/node/analyze/getServerRoutes.js +3 -3
  22. package/dist/js/node/analyze/nestedRoutes.js +15 -4
  23. package/dist/js/node/analyze/templates.js +60 -27
  24. package/dist/js/node/analyze/utils.js +31 -3
  25. package/dist/js/node/builder/builderPlugins/compatModern.js +6 -1
  26. package/dist/js/node/builder/index.js +3 -5
  27. package/dist/js/node/builder/loaders/routerLoader.js +27 -0
  28. package/dist/js/node/builder/loaders/serverModuleLoader.js +11 -0
  29. package/dist/js/node/commands/dev.js +23 -27
  30. package/dist/js/node/commands/start.js +0 -1
  31. package/dist/js/node/config/default.js +0 -1
  32. package/dist/js/node/config/initial/createOutputConfig.js +3 -0
  33. package/dist/js/node/utils/createFileWatcher.js +2 -1
  34. package/dist/js/node/utils/restart.js +1 -1
  35. package/dist/js/treeshaking/analyze/constants.js +2 -0
  36. package/dist/js/treeshaking/analyze/generateCode.js +137 -81
  37. package/dist/js/treeshaking/analyze/getServerRoutes.js +4 -3
  38. package/dist/js/treeshaking/analyze/nestedRoutes.js +98 -55
  39. package/dist/js/treeshaking/analyze/templates.js +175 -101
  40. package/dist/js/treeshaking/analyze/utils.js +80 -4
  41. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +6 -1
  42. package/dist/js/treeshaking/builder/index.js +3 -5
  43. package/dist/js/treeshaking/builder/loaders/routerLoader.js +14 -0
  44. package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +4 -0
  45. package/dist/js/treeshaking/commands/dev.js +37 -38
  46. package/dist/js/treeshaking/commands/start.js +0 -1
  47. package/dist/js/treeshaking/config/default.js +0 -1
  48. package/dist/js/treeshaking/config/initial/createOutputConfig.js +3 -0
  49. package/dist/js/treeshaking/utils/createFileWatcher.js +1 -1
  50. package/dist/js/treeshaking/utils/restart.js +1 -1
  51. package/dist/types/analyze/constants.d.ts +2 -0
  52. package/dist/types/analyze/templates.d.ts +8 -7
  53. package/dist/types/analyze/utils.d.ts +9 -1
  54. package/dist/types/builder/loaders/routerLoader.d.ts +3 -0
  55. package/dist/types/builder/loaders/serverModuleLoader.d.ts +3 -0
  56. package/dist/types/types/config/tools.d.ts +8 -1
  57. package/dist/types/types/hooks.d.ts +2 -1
  58. package/dist/types/utils/createFileWatcher.d.ts +2 -1
  59. package/lib/types.d.ts +1 -1
  60. package/package.json +25 -22
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function loader(source) {
8
+ // eslint-disable-next-line @babel/no-invalid-this
9
+ this.cacheable();
10
+ // eslint-disable-next-line @babel/no-invalid-this
11
+ const {
12
+ target
13
+ } = this._compiler.options;
14
+ if (target === 'node' || Array.isArray(target) && target.includes('node')) {
15
+ return source;
16
+ }
17
+ // eslint-disable-next-line @babel/no-invalid-this
18
+ const {
19
+ resourcePath
20
+ } = this;
21
+ const code = `
22
+ export { default } from "${resourcePath}";
23
+ `;
24
+ return code;
25
+ }
26
+ var _default = loader;
27
+ exports.default = _default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function loader() {
8
+ return `module.exports = {}`;
9
+ }
10
+ var _default = loader;
11
+ exports.default = _default;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.dev = void 0;
7
- var _utils = require("@modern-js/utils");
8
7
  var _core = require("@modern-js/core");
9
8
  var _createFileWatcher = require("../utils/createFileWatcher");
10
9
  var _printInstructions = require("../utils/printInstructions");
@@ -53,43 +52,40 @@ const dev = async (api, options) => {
53
52
  }
54
53
  });
55
54
  await hookRunners.beforeDev();
56
- let compiler = null;
55
+ let compiler;
56
+ if (!appContext.builder && !apiOnly) {
57
+ throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
58
+ }
57
59
  if (!apiOnly) {
58
- if (!appContext.builder) {
59
- throw new Error('Expect the Builder to have been initialized, But the appContext.builder received `undefined`');
60
- }
61
60
  compiler = await appContext.builder.createCompiler();
62
61
  }
63
62
  await (0, _routes.generateRoutes)(appContext);
64
- const app = await (0, _createServer.createServer)({
65
- dev: _objectSpread(_objectSpread({}, {
66
- client: {
67
- port: port.toString()
68
- },
69
- devMiddleware: {
70
- writeToDisk: file => !file.includes('.hot-update.')
71
- },
72
- hot: true,
73
- liveReload: true,
63
+ const serverOptions = {
64
+ dev: _objectSpread({
74
65
  port,
75
66
  https: normalizedConfig.dev.https
76
- }), (_normalizedConfig$too = normalizedConfig.tools) === null || _normalizedConfig$too === void 0 ? void 0 : _normalizedConfig$too.devServer),
77
- compiler,
67
+ }, (_normalizedConfig$too = normalizedConfig.tools) === null || _normalizedConfig$too === void 0 ? void 0 : _normalizedConfig$too.devServer),
68
+ compiler: compiler || null,
78
69
  pwd: appDirectory,
79
70
  config: normalizedConfig,
80
71
  serverConfigFile,
81
72
  internalPlugins: (0, _createServer.injectDataLoaderPlugin)(serverInternalPlugins)
82
- });
83
- app.listen(port, async err => {
84
- if (err) {
85
- throw err;
86
- }
87
- if (!apiOnly) {
88
- _utils.logger.info(`Starting dev server...\n`);
89
- } else {
73
+ };
74
+ if (apiOnly) {
75
+ const app = await (0, _createServer.createServer)(serverOptions);
76
+ app.listen(port, async err => {
77
+ if (err) {
78
+ throw err;
79
+ }
90
80
  (0, _printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
91
- }
92
- });
81
+ });
82
+ } else {
83
+ await appContext.builder.startDevServer({
84
+ compiler,
85
+ printURLs: false,
86
+ serverOptions
87
+ });
88
+ }
93
89
  await (0, _createFileWatcher.createFileWatcher)(appContext, normalizedConfig.source.configDir, hookRunners);
94
90
  };
95
91
  exports.dev = dev;
@@ -23,7 +23,6 @@ const start = async api => {
23
23
  const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
24
24
  const app = await (0, _prodServer.default)({
25
25
  pwd: appDirectory,
26
- // FIXME: remove the `any` type
27
26
  config: userConfig,
28
27
  serverConfigFile,
29
28
  internalPlugins: (0, _createServer.injectDataLoaderPlugin)(appContext.serverInternalPlugins),
@@ -43,7 +43,6 @@ function createDefaultConfig(appContext) {
43
43
  disableFilenameHash: false,
44
44
  enableLatestDecorators: false,
45
45
  polyfill: 'entry',
46
- dataUriLimit: 10000,
47
46
  cssModuleLocalIdentName: undefined
48
47
  };
49
48
  const html = {
@@ -68,6 +68,9 @@ function createOutputConfig(config) {
68
68
  css: cssModuleLocalIdentName
69
69
  },
70
70
  ssg,
71
+ // set `true`, only in legacy config
72
+ enableAssetFallback: true,
73
+ enableAssetManifest: true,
71
74
  enableModernMode,
72
75
  disableNodePolyfill
73
76
  };
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createFileWatcher = void 0;
6
+ exports.createFileWatcher = exports.addServerConfigToDeps = void 0;
7
7
  var _crypto = _interopRequireDefault(require("crypto"));
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
  var _path = _interopRequireDefault(require("path"));
@@ -26,6 +26,7 @@ const addServerConfigToDeps = async (dependencies, appDirectory, serverConfigFil
26
26
  dependencies.push(serverConfig);
27
27
  }
28
28
  };
29
+ exports.addServerConfigToDeps = addServerConfigToDeps;
29
30
  const debug = (0, _utils.createDebugger)('watch-files');
30
31
  const md5 = data => _crypto.default.createHash('md5').update(data).digest('hex');
31
32
  const hashMap = new Map();
@@ -11,7 +11,7 @@ async function restart(hooksRunner) {
11
11
  let hasGetError = false;
12
12
  await hooksRunner.beforeRestart();
13
13
  try {
14
- await _core.cli.init(_core.cli.initOptions);
14
+ await _core.cli.init(_core.cli.getPrevInitOptions());
15
15
  } catch (err) {
16
16
  console.error(err);
17
17
  hasGetError = true;
@@ -4,6 +4,8 @@ export var APP_FILE_NAME = 'App';
4
4
  export var PAGES_DIR_NAME = 'pages';
5
5
  export var NESTED_ROUTES_DIR = 'routes';
6
6
  export var FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
7
+ export var LOADER_EXPORT_NAME = 'loader';
8
+ export var TEMP_LOADERS_DIR = '__loaders__';
7
9
  export var ENTRY_POINT_FILE_NAME = 'index.js';
8
10
  export var ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
9
11
  export var FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
@@ -4,15 +4,20 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
4
4
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
5
5
  import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
6
6
  import path from 'path';
7
- import { fs, logger } from '@modern-js/utils';
7
+ import { fs, LOADER_ROUTES_DIR, logger } from '@modern-js/utils';
8
8
  import { useResolvedConfigContext } from '@modern-js/core';
9
9
  import esbuild from 'esbuild';
10
10
  import { getCommand } from "../utils/commands";
11
11
  import * as templates from "./templates";
12
12
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
13
- import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
13
+ import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
14
14
  import { getDefaultImports } from "./utils";
15
15
  import { walk } from "./nestedRoutes";
16
+ var loader = {
17
+ '.js': 'jsx',
18
+ '.ts': 'tsx'
19
+ };
20
+ var EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
16
21
  var createImportSpecifier = function createImportSpecifier(specifiers) {
17
22
  var defaults = '';
18
23
  var named = [];
@@ -91,21 +96,16 @@ export var createImportStatements = function createImportStatements(statements)
91
96
  };
92
97
  var buildLoader = /*#__PURE__*/function () {
93
98
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(entry, outfile) {
94
- var loader, EXTERNAL_REGEXP, command;
99
+ var command;
95
100
  return _regeneratorRuntime().wrap(function _callee$(_context) {
96
101
  while (1) {
97
102
  switch (_context.prev = _context.next) {
98
103
  case 0:
99
- loader = {
100
- '.js': 'jsx',
101
- '.ts': 'tsx'
102
- };
103
- EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
104
104
  command = getCommand();
105
- _context.next = 5;
105
+ _context.next = 3;
106
106
  return esbuild.build({
107
- format: 'cjs',
108
- platform: 'node',
107
+ format: 'esm',
108
+ platform: 'browser',
109
109
  target: 'esnext',
110
110
  loader: loader,
111
111
  watch: command === 'dev' && {},
@@ -133,7 +133,7 @@ var buildLoader = /*#__PURE__*/function () {
133
133
  }
134
134
  }]
135
135
  });
136
- case 5:
136
+ case 3:
137
137
  case "end":
138
138
  return _context.stop();
139
139
  }
@@ -144,28 +144,59 @@ var buildLoader = /*#__PURE__*/function () {
144
144
  return _ref2.apply(this, arguments);
145
145
  };
146
146
  }();
147
+ var buildServerLoader = /*#__PURE__*/function () {
148
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(entry, outfile) {
149
+ var command;
150
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
151
+ while (1) {
152
+ switch (_context2.prev = _context2.next) {
153
+ case 0:
154
+ command = getCommand();
155
+ _context2.next = 3;
156
+ return esbuild.build({
157
+ format: 'cjs',
158
+ platform: 'node',
159
+ target: 'esnext',
160
+ loader: loader,
161
+ watch: command === 'dev' && {},
162
+ bundle: true,
163
+ logLevel: 'error',
164
+ entryPoints: [entry],
165
+ outfile: outfile
166
+ });
167
+ case 3:
168
+ case "end":
169
+ return _context2.stop();
170
+ }
171
+ }
172
+ }, _callee2);
173
+ }));
174
+ return function buildServerLoader(_x3, _x4) {
175
+ return _ref3.apply(this, arguments);
176
+ };
177
+ }();
147
178
  export var generateCode = /*#__PURE__*/function () {
148
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(appContext, config, entrypoints, api) {
179
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(appContext, config, entrypoints, api) {
149
180
  var _config$runtime, _config$runtime$route;
150
181
  var internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, hookRunners, islegacy, mountId, getRoutes, generateEntryCode, _generateEntryCode;
151
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
182
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
152
183
  while (1) {
153
- switch (_context3.prev = _context3.next) {
184
+ switch (_context4.prev = _context4.next) {
154
185
  case 0:
155
186
  _generateEntryCode = function _generateEntryCode3() {
156
- _generateEntryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(entrypoint) {
157
- var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, _yield$hookRunners$mo, routes, _config, ssr, mode, hasPageRoute, _yield$hookRunners$be, _code, routesServerFile, outputRoutesServerFile, _code2, _yield$hookRunners$mo2, importStatements, _yield$hookRunners$mo3, plugins, _yield$hookRunners$mo4, renderFunction, _yield$hookRunners$mo5, exportStatement, code, entryFile, _yield$hookRunners$mo6, asyncEntryCode, bootstrapFile;
158
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
187
+ _generateEntryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(entrypoint) {
188
+ var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, _yield$hookRunners$mo, routes, _config, ssr, mode, hasPageRoute, _yield$hookRunners$be, _code, routesServerFile, outputRoutesServerFile, _code2, loaderEntryFile, loaderIndexFile, _yield$hookRunners$mo2, importStatements, _yield$hookRunners$mo3, plugins, _yield$hookRunners$mo4, renderFunction, _yield$hookRunners$mo5, exportStatement, code, entryFile, _yield$hookRunners$mo6, asyncEntryCode, bootstrapFile;
189
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
159
190
  while (1) {
160
- switch (_context2.prev = _context2.next) {
191
+ switch (_context3.prev = _context3.next) {
161
192
  case 0:
162
193
  entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
163
194
  if (!isAutoMount) {
164
- _context2.next = 69;
195
+ _context3.next = 85;
165
196
  break;
166
197
  }
167
198
  if (!fileSystemRoutes) {
168
- _context2.next = 39;
199
+ _context3.next = 55;
169
200
  break;
170
201
  }
171
202
  initialRoutes = [];
@@ -180,37 +211,37 @@ export var generateCode = /*#__PURE__*/function () {
180
211
  });
181
212
  }
182
213
  if (!entrypoint.nestedRoutesEntry) {
183
- _context2.next = 16;
214
+ _context3.next = 16;
184
215
  break;
185
216
  }
186
217
  if (islegacy) {
187
- _context2.next = 14;
218
+ _context3.next = 14;
188
219
  break;
189
220
  }
190
- _context2.next = 10;
221
+ _context3.next = 10;
191
222
  return walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
192
223
  name: internalSrcAlias,
193
224
  basename: srcDirectory
194
225
  }, entrypoint.entryName);
195
226
  case 10:
196
- nestedRoute = _context2.sent;
227
+ nestedRoute = _context3.sent;
197
228
  if (nestedRoute) {
198
229
  initialRoutes.unshift(nestedRoute);
199
230
  }
200
- _context2.next = 16;
231
+ _context3.next = 16;
201
232
  break;
202
233
  case 14:
203
234
  logger.error('Nested routes is not supported in legacy mode.');
204
235
  // eslint-disable-next-line no-process-exit
205
236
  process.exit(1);
206
237
  case 16:
207
- _context2.next = 18;
238
+ _context3.next = 18;
208
239
  return hookRunners.modifyFileSystemRoutes({
209
240
  entrypoint: entrypoint,
210
241
  routes: initialRoutes
211
242
  });
212
243
  case 18:
213
- _yield$hookRunners$mo = _context2.sent;
244
+ _yield$hookRunners$mo = _context3.sent;
214
245
  routes = _yield$hookRunners$mo.routes;
215
246
  _config = useResolvedConfigContext();
216
247
  ssr = _config === null || _config === void 0 ? void 0 : _config.server.ssr;
@@ -229,44 +260,69 @@ export var generateCode = /*#__PURE__*/function () {
229
260
  process.exit(1);
230
261
  }
231
262
  }
232
- _context2.next = 26;
233
- return hookRunners.beforeGenerateRoutes({
234
- entrypoint: entrypoint,
235
- code: templates.fileSystemRoutes({
236
- routes: routes,
237
- ssrMode: mode,
238
- nestedRoutesEntry: entrypoint.nestedRoutesEntry,
239
- entryName: entrypoint.entryName
240
- })
263
+ _context3.t0 = hookRunners;
264
+ _context3.t1 = entrypoint;
265
+ _context3.next = 28;
266
+ return templates.fileSystemRoutes({
267
+ routes: routes,
268
+ ssrMode: mode,
269
+ nestedRoutesEntry: entrypoint.nestedRoutesEntry,
270
+ entryName: entrypoint.entryName,
271
+ internalDirectory: internalDirectory
241
272
  });
242
- case 26:
243
- _yield$hookRunners$be = _context2.sent;
273
+ case 28:
274
+ _context3.t2 = _context3.sent;
275
+ _context3.t3 = {
276
+ entrypoint: _context3.t1,
277
+ code: _context3.t2
278
+ };
279
+ _context3.next = 32;
280
+ return _context3.t0.beforeGenerateRoutes.call(_context3.t0, _context3.t3);
281
+ case 32:
282
+ _yield$hookRunners$be = _context3.sent;
244
283
  _code = _yield$hookRunners$be.code;
245
284
  if (!entrypoint.nestedRoutesEntry) {
246
- _context2.next = 38;
285
+ _context3.next = 54;
247
286
  break;
248
287
  }
249
- routesServerFile = path.join(internalDirectory, entryName, 'routes.server.js');
250
- outputRoutesServerFile = path.join(distDirectory, 'loader-routes', entryName, 'index.js');
288
+ routesServerFile = path.join(internalDirectory, entryName, 'route-server-loaders.js');
289
+ outputRoutesServerFile = path.join(distDirectory, LOADER_ROUTES_DIR, entryName, 'index.js');
251
290
  _code2 = templates.routesForServer({
252
291
  routes: routes,
253
- alias: {
254
- name: internalSrcAlias,
255
- basename: srcDirectory
256
- }
292
+ internalDirectory: internalDirectory,
293
+ entryName: entryName
257
294
  });
258
- _context2.next = 34;
295
+ _context3.next = 40;
259
296
  return fs.ensureFile(routesServerFile);
260
- case 34:
261
- _context2.next = 36;
297
+ case 40:
298
+ _context3.next = 42;
262
299
  return fs.writeFile(routesServerFile, _code2);
263
- case 36:
264
- _context2.next = 38;
265
- return buildLoader(routesServerFile, outputRoutesServerFile);
266
- case 38:
300
+ case 42:
301
+ loaderEntryFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, 'entry.js');
302
+ loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, 'index.js');
303
+ _context3.next = 46;
304
+ return fs.pathExists(loaderEntryFile);
305
+ case 46:
306
+ if (!_context3.sent) {
307
+ _context3.next = 49;
308
+ break;
309
+ }
310
+ _context3.next = 49;
311
+ return buildLoader(loaderEntryFile, loaderIndexFile);
312
+ case 49:
313
+ _context3.next = 51;
314
+ return fs.pathExists(routesServerFile);
315
+ case 51:
316
+ if (!_context3.sent) {
317
+ _context3.next = 54;
318
+ break;
319
+ }
320
+ _context3.next = 54;
321
+ return buildServerLoader(routesServerFile, outputRoutesServerFile);
322
+ case 54:
267
323
  fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), _code, 'utf8');
268
- case 39:
269
- _context2.next = 41;
324
+ case 55:
325
+ _context3.next = 57;
270
326
  return hookRunners.modifyEntryImports({
271
327
  entrypoint: entrypoint,
272
328
  imports: getDefaultImports({
@@ -277,18 +333,18 @@ export var generateCode = /*#__PURE__*/function () {
277
333
  internalDirectory: internalDirectory
278
334
  })
279
335
  });
280
- case 41:
281
- _yield$hookRunners$mo2 = _context2.sent;
336
+ case 57:
337
+ _yield$hookRunners$mo2 = _context3.sent;
282
338
  importStatements = _yield$hookRunners$mo2.imports;
283
- _context2.next = 45;
339
+ _context3.next = 61;
284
340
  return hookRunners.modifyEntryRuntimePlugins({
285
341
  entrypoint: entrypoint,
286
342
  plugins: []
287
343
  });
288
- case 45:
289
- _yield$hookRunners$mo3 = _context2.sent;
344
+ case 61:
345
+ _yield$hookRunners$mo3 = _context3.sent;
290
346
  plugins = _yield$hookRunners$mo3.plugins;
291
- _context2.next = 49;
347
+ _context3.next = 65;
292
348
  return hookRunners.modifyEntryRenderFunction({
293
349
  entrypoint: entrypoint,
294
350
  code: templates.renderFunction({
@@ -297,16 +353,16 @@ export var generateCode = /*#__PURE__*/function () {
297
353
  fileSystemRoutes: fileSystemRoutes
298
354
  })
299
355
  });
300
- case 49:
301
- _yield$hookRunners$mo4 = _context2.sent;
356
+ case 65:
357
+ _yield$hookRunners$mo4 = _context3.sent;
302
358
  renderFunction = _yield$hookRunners$mo4.code;
303
- _context2.next = 53;
359
+ _context3.next = 69;
304
360
  return hookRunners.modifyEntryExport({
305
361
  entrypoint: entrypoint,
306
362
  exportStatement: 'export default AppWrapper;'
307
363
  });
308
- case 53:
309
- _yield$hookRunners$mo5 = _context2.sent;
364
+ case 69:
365
+ _yield$hookRunners$mo5 = _context3.sent;
310
366
  exportStatement = _yield$hookRunners$mo5.exportStatement;
311
367
  code = templates.index({
312
368
  mountId: mountId,
@@ -319,34 +375,34 @@ export var generateCode = /*#__PURE__*/function () {
319
375
 
320
376
  // generate entry file.
321
377
  if (!config.source.enableAsyncEntry) {
322
- _context2.next = 68;
378
+ _context3.next = 84;
323
379
  break;
324
380
  }
325
- _context2.next = 61;
381
+ _context3.next = 77;
326
382
  return hookRunners.modifyAsyncEntry({
327
383
  entrypoint: entrypoint,
328
384
  code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
329
385
  });
330
- case 61:
331
- _yield$hookRunners$mo6 = _context2.sent;
386
+ case 77:
387
+ _yield$hookRunners$mo6 = _context3.sent;
332
388
  asyncEntryCode = _yield$hookRunners$mo6.code;
333
389
  fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
334
390
  bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
335
391
  fs.outputFileSync(bootstrapFile, code, 'utf8');
336
- _context2.next = 69;
392
+ _context3.next = 85;
337
393
  break;
338
- case 68:
394
+ case 84:
339
395
  fs.outputFileSync(entryFile, code, 'utf8');
340
- case 69:
396
+ case 85:
341
397
  case "end":
342
- return _context2.stop();
398
+ return _context3.stop();
343
399
  }
344
400
  }
345
- }, _callee2);
401
+ }, _callee3);
346
402
  }));
347
403
  return _generateEntryCode.apply(this, arguments);
348
404
  };
349
- generateEntryCode = function _generateEntryCode2(_x7) {
405
+ generateEntryCode = function _generateEntryCode2(_x9) {
350
406
  return _generateEntryCode.apply(this, arguments);
351
407
  };
352
408
  internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias;
@@ -354,16 +410,16 @@ export var generateCode = /*#__PURE__*/function () {
354
410
  islegacy = Boolean(config === null || config === void 0 ? void 0 : (_config$runtime = config.runtime) === null || _config$runtime === void 0 ? void 0 : (_config$runtime$route = _config$runtime.router) === null || _config$runtime$route === void 0 ? void 0 : _config$runtime$route.legacy);
355
411
  mountId = config.html.mountId;
356
412
  getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
357
- _context3.next = 9;
413
+ _context4.next = 9;
358
414
  return Promise.all(entrypoints.map(generateEntryCode));
359
415
  case 9:
360
416
  case "end":
361
- return _context3.stop();
417
+ return _context4.stop();
362
418
  }
363
419
  }
364
- }, _callee3);
420
+ }, _callee4);
365
421
  }));
366
- return function generateCode(_x3, _x4, _x5, _x6) {
367
- return _ref3.apply(this, arguments);
422
+ return function generateCode(_x5, _x6, _x7, _x8) {
423
+ return _ref4.apply(this, arguments);
368
424
  };
369
425
  }();
@@ -88,9 +88,11 @@ var applyRouteOptions = function applyRouteOptions(original, routeOptions) {
88
88
  */
89
89
  var collectHtmlRoutes = function collectHtmlRoutes(entrypoints, appContext, config) {
90
90
  var disableHtmlFolder = config.html.disableHtmlFolder,
91
- _config$output$distPa = config.output.distPath;
91
+ _config$output = config.output,
92
+ _config$output$distPa = _config$output.distPath;
92
93
  _config$output$distPa = _config$output$distPa === void 0 ? {} : _config$output$distPa;
93
94
  var htmlPath = _config$output$distPa.html,
95
+ enableModernMode = _config$output.enableModernMode,
94
96
  _config$server = config.server,
95
97
  baseUrl = _config$server.baseUrl,
96
98
  routes = _config$server.routes,
@@ -110,8 +112,7 @@ var collectHtmlRoutes = function collectHtmlRoutes(entrypoints, appContext, conf
110
112
  isSPA: true,
111
113
  isSSR: isSSR,
112
114
  responseHeaders: resHeaders,
113
- // FIXME: remove the config.enableModernMode
114
- // enableModernMode: Boolean(enableModernMode),
115
+ enableModernMode: Boolean(enableModernMode),
115
116
  bundle: isSSR ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : undefined
116
117
  };
117
118
  if (routes !== null && routes !== void 0 && routes.hasOwnProperty(entryName)) {