@modern-js/app-tools 1.21.2 → 2.0.0-beta.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 (146) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/dist/js/modern/analyze/constants.js +1 -0
  3. package/dist/js/modern/analyze/generateCode.js +118 -16
  4. package/dist/js/modern/analyze/getBundleEntry.js +3 -2
  5. package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +198 -0
  6. package/dist/js/modern/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +8 -28
  7. package/dist/js/modern/analyze/getClientRoutes/index.js +2 -0
  8. package/dist/js/modern/analyze/getClientRoutes/utils.js +21 -0
  9. package/dist/js/modern/analyze/getFileSystemEntry.js +31 -12
  10. package/dist/js/modern/analyze/index.js +2 -1
  11. package/dist/js/modern/analyze/nestedRoutes.js +127 -0
  12. package/dist/js/modern/analyze/templates.js +164 -10
  13. package/dist/js/modern/analyze/utils.js +2 -1
  14. package/dist/js/modern/builder/builderPlugins/compatModern.js +226 -0
  15. package/dist/js/modern/builder/createHtmlConfig.js +58 -0
  16. package/dist/js/modern/builder/createOutputConfig.js +67 -0
  17. package/dist/js/modern/builder/createSourceConfig.js +85 -0
  18. package/dist/js/modern/builder/createToolsConfig.js +94 -0
  19. package/dist/js/modern/builder/index.js +106 -0
  20. package/dist/js/modern/builder/share.js +48 -0
  21. package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +37 -0
  22. package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +44 -0
  23. package/dist/js/modern/commands/build.js +41 -95
  24. package/dist/js/modern/commands/dev.js +15 -19
  25. package/dist/js/modern/commands/inspect.js +17 -58
  26. package/dist/js/modern/commands/start.js +2 -1
  27. package/dist/js/modern/index.js +14 -4
  28. package/dist/js/modern/locale/en.js +0 -1
  29. package/dist/js/modern/locale/zh.js +0 -1
  30. package/dist/js/modern/utils/commands.js +5 -0
  31. package/dist/js/modern/utils/createCompiler.js +37 -40
  32. package/dist/js/modern/utils/createServer.js +16 -0
  33. package/dist/js/modern/utils/printInstructions.js +1 -1
  34. package/dist/js/node/analyze/constants.js +3 -1
  35. package/dist/js/node/analyze/generateCode.js +121 -14
  36. package/dist/js/node/analyze/getBundleEntry.js +3 -2
  37. package/dist/js/node/analyze/getClientRoutes/getRoutes.js +221 -0
  38. package/dist/js/node/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +16 -35
  39. package/dist/js/node/analyze/getClientRoutes/index.js +21 -0
  40. package/dist/js/node/analyze/getClientRoutes/utils.js +42 -0
  41. package/dist/js/node/analyze/getFileSystemEntry.js +30 -11
  42. package/dist/js/node/analyze/index.js +2 -1
  43. package/dist/js/node/analyze/nestedRoutes.js +144 -0
  44. package/dist/js/node/analyze/templates.js +167 -10
  45. package/dist/js/node/analyze/utils.js +6 -2
  46. package/dist/js/node/builder/builderPlugins/compatModern.js +245 -0
  47. package/dist/js/node/builder/createHtmlConfig.js +76 -0
  48. package/dist/js/node/builder/createOutputConfig.js +75 -0
  49. package/dist/js/node/builder/createSourceConfig.js +99 -0
  50. package/dist/js/node/builder/createToolsConfig.js +103 -0
  51. package/dist/js/node/builder/index.js +129 -0
  52. package/dist/js/node/builder/share.js +63 -0
  53. package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +46 -0
  54. package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +53 -0
  55. package/dist/js/node/commands/build.js +44 -98
  56. package/dist/js/node/commands/dev.js +13 -23
  57. package/dist/js/node/commands/inspect.js +18 -74
  58. package/dist/js/node/commands/start.js +3 -1
  59. package/dist/js/node/index.js +19 -2
  60. package/dist/js/node/locale/en.js +0 -1
  61. package/dist/js/node/locale/zh.js +0 -1
  62. package/dist/js/node/utils/commands.js +14 -0
  63. package/dist/js/node/utils/createCompiler.js +43 -49
  64. package/dist/js/node/utils/createServer.js +21 -2
  65. package/dist/js/node/utils/printInstructions.js +1 -1
  66. package/dist/js/treeshaking/analyze/constants.js +16 -0
  67. package/dist/js/treeshaking/analyze/generateCode.js +412 -0
  68. package/dist/js/treeshaking/analyze/getBundleEntry.js +77 -0
  69. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +210 -0
  70. package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +211 -0
  71. package/dist/js/treeshaking/analyze/getClientRoutes/index.js +2 -0
  72. package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +27 -0
  73. package/dist/js/treeshaking/analyze/getFileSystemEntry.js +109 -0
  74. package/dist/js/treeshaking/analyze/getHtmlTemplate.js +153 -0
  75. package/dist/js/treeshaking/analyze/getServerRoutes.js +170 -0
  76. package/dist/js/treeshaking/analyze/index.js +214 -0
  77. package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +32 -0
  78. package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +18 -0
  79. package/dist/js/treeshaking/analyze/nestedRoutes.js +207 -0
  80. package/dist/js/treeshaking/analyze/templates.js +189 -0
  81. package/dist/js/treeshaking/analyze/utils.js +95 -0
  82. package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +231 -0
  83. package/dist/js/treeshaking/builder/createHtmlConfig.js +59 -0
  84. package/dist/js/treeshaking/builder/createOutputConfig.js +67 -0
  85. package/dist/js/treeshaking/builder/createSourceConfig.js +100 -0
  86. package/dist/js/treeshaking/builder/createToolsConfig.js +90 -0
  87. package/dist/js/treeshaking/builder/index.js +172 -0
  88. package/dist/js/treeshaking/builder/share.js +50 -0
  89. package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +58 -0
  90. package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +53 -0
  91. package/dist/js/treeshaking/commands/build.js +168 -0
  92. package/dist/js/treeshaking/commands/deploy.js +29 -0
  93. package/dist/js/treeshaking/commands/dev.js +146 -0
  94. package/dist/js/treeshaking/commands/index.js +3 -0
  95. package/dist/js/treeshaking/commands/inspect.js +52 -0
  96. package/dist/js/treeshaking/commands/start.js +78 -0
  97. package/dist/js/treeshaking/exports/server.js +1 -0
  98. package/dist/js/treeshaking/hooks.js +21 -0
  99. package/dist/js/treeshaking/index.js +304 -0
  100. package/dist/js/treeshaking/locale/en.js +34 -0
  101. package/dist/js/treeshaking/locale/index.js +9 -0
  102. package/dist/js/treeshaking/locale/zh.js +34 -0
  103. package/dist/js/treeshaking/utils/commands.js +5 -0
  104. package/dist/js/treeshaking/utils/config.js +140 -0
  105. package/dist/js/treeshaking/utils/createCompiler.js +117 -0
  106. package/dist/js/treeshaking/utils/createServer.js +83 -0
  107. package/dist/js/treeshaking/utils/getSpecifiedEntries.js +68 -0
  108. package/dist/js/treeshaking/utils/language.js +5 -0
  109. package/dist/js/treeshaking/utils/printInstructions.js +35 -0
  110. package/dist/js/treeshaking/utils/routes.js +33 -0
  111. package/dist/js/treeshaking/utils/types.js +0 -0
  112. package/dist/types/analyze/constants.d.ts +1 -0
  113. package/dist/types/analyze/generateCode.d.ts +1 -1
  114. package/dist/types/analyze/{getClientRoutes.d.ts → getClientRoutes/getRoutes.d.ts} +2 -7
  115. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +15 -0
  116. package/dist/types/analyze/getClientRoutes/index.d.ts +2 -0
  117. package/dist/types/analyze/getClientRoutes/utils.d.ts +5 -0
  118. package/dist/types/analyze/index.d.ts +2 -2
  119. package/dist/types/analyze/nestedRoutes.d.ts +5 -0
  120. package/dist/types/analyze/templates.d.ts +17 -3
  121. package/dist/types/analyze/utils.d.ts +2 -1
  122. package/dist/types/builder/builderPlugins/compatModern.d.ts +14 -0
  123. package/dist/types/builder/createHtmlConfig.d.ts +6 -0
  124. package/dist/types/builder/createOutputConfig.d.ts +3 -0
  125. package/dist/types/builder/createSourceConfig.d.ts +5 -0
  126. package/dist/types/builder/createToolsConfig.d.ts +13 -0
  127. package/dist/types/builder/index.d.ts +19 -0
  128. package/dist/types/builder/share.d.ts +26 -0
  129. package/dist/types/builder/webpackPlugins/htmlAsyncChunkPlugin.d.ts +8 -0
  130. package/dist/types/builder/webpackPlugins/htmlBottomTemplate.d.ts +10 -0
  131. package/dist/types/commands/build.d.ts +2 -1
  132. package/dist/types/commands/deploy.d.ts +2 -1
  133. package/dist/types/commands/dev.d.ts +2 -1
  134. package/dist/types/commands/inspect.d.ts +5 -6
  135. package/dist/types/commands/start.d.ts +2 -1
  136. package/dist/types/hooks.d.ts +15 -10
  137. package/dist/types/index.d.ts +4 -2
  138. package/dist/types/locale/en.d.ts +0 -1
  139. package/dist/types/locale/index.d.ts +0 -2
  140. package/dist/types/locale/zh.d.ts +0 -1
  141. package/dist/types/utils/commands.d.ts +1 -0
  142. package/dist/types/utils/createCompiler.d.ts +9 -10
  143. package/dist/types/utils/createServer.d.ts +8 -1
  144. package/dist/types/utils/printInstructions.d.ts +3 -2
  145. package/dist/types/utils/types.d.ts +2 -3
  146. package/package.json +25 -43
@@ -9,22 +9,18 @@ var _utils = require("@modern-js/utils");
9
9
 
10
10
  var _core = require("@modern-js/core");
11
11
 
12
+ var _printInstructions = require("../utils/printInstructions");
13
+
12
14
  var _createCompiler = require("../utils/createCompiler");
13
15
 
14
16
  var _createServer = require("../utils/createServer");
15
17
 
16
18
  var _routes = require("../utils/routes");
17
19
 
18
- var _printInstructions = require("../utils/printInstructions");
19
-
20
20
  var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
21
21
 
22
22
  var _config = require("../utils/config");
23
23
 
24
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
-
26
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
-
28
24
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
29
25
 
30
26
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -47,16 +43,14 @@ const dev = async (api, options) => {
47
43
  port,
48
44
  apiOnly,
49
45
  entrypoints,
50
- serverConfigFile
46
+ serverConfigFile,
47
+ serverInternalPlugins
51
48
  } = appContext;
52
49
  const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
53
50
  api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
54
51
  checkedEntries
55
52
  }));
56
53
  appContext.checkedEntries = checkedEntries;
57
-
58
- _utils.fs.emptyDirSync(distDirectory);
59
-
60
54
  await (0, _config.buildServerConfig)({
61
55
  appDirectory,
62
56
  distDirectory,
@@ -71,15 +65,11 @@ const dev = async (api, options) => {
71
65
  let compiler = null;
72
66
 
73
67
  if (!apiOnly) {
74
- const {
75
- getWebpackConfig,
76
- WebpackConfigTarget
77
- } = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/webpack')));
78
- const webpackConfigs = [(0, _utils.isSSR)(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE, appContext, userConfig), getWebpackConfig(WebpackConfigTarget.CLIENT, appContext, userConfig)].filter(Boolean);
79
- compiler = await (0, _createCompiler.createCompiler)({
68
+ const target = (0, _utils.isSSR)(userConfig) ? ['web', 'node'] : ['web'];
69
+ compiler = await (0, _createCompiler.createDevCompiler)({
70
+ target,
80
71
  api,
81
- webpackConfigs,
82
- userConfig,
72
+ normalizedConfig: userConfig,
83
73
  appContext
84
74
  });
85
75
  }
@@ -102,18 +92,18 @@ const dev = async (api, options) => {
102
92
  pwd: appDirectory,
103
93
  config: userConfig,
104
94
  serverConfigFile,
105
- plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
95
+ internalPlugins: (0, _createServer.injectDataLoaderPlugin)(serverInternalPlugins)
106
96
  });
107
97
  app.listen(port, async err => {
108
98
  if (err) {
109
99
  throw err;
110
100
  }
111
101
 
112
- if (apiOnly) {
113
- return (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
102
+ if (!apiOnly) {
103
+ _utils.logger.info(`Starting dev server...`);
104
+ } else {
105
+ (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
114
106
  }
115
-
116
- return _utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
117
107
  });
118
108
  };
119
109
 
@@ -3,96 +3,40 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.printInspectResult = exports.inspect = exports.getTagByWebpackTarget = exports.formatWebpackConfig = void 0;
6
+ exports.inspect = void 0;
7
7
 
8
- var _path = _interopRequireDefault(require("path"));
9
-
10
- var _webpack = require("@modern-js/webpack");
8
+ var _path = require("path");
11
9
 
12
10
  var _utils = require("@modern-js/utils");
13
11
 
14
- var _webpackChain = _interopRequireDefault(require("@modern-js/utils/webpack-chain"));
12
+ var _builder = _interopRequireDefault(require("../builder"));
15
13
 
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
18
- const formatWebpackConfig = (config, verbose) => {
19
- const stringify = _webpackChain.default.toString;
20
- return `module.exports = ${stringify(config, {
21
- verbose
22
- })};`;
23
- };
24
-
25
- exports.formatWebpackConfig = formatWebpackConfig;
26
-
27
- const inspect = (api, options) => {
28
- process.env.NODE_ENV = options.env;
16
+ const inspect = async (api, options) => {
29
17
  const resolvedConfig = api.useResolvedConfigContext();
30
18
  const appContext = api.useAppContext();
31
- const outputFiles = [];
32
- outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.CLIENT, appContext, resolvedConfig, options));
19
+ const targets = ['web'];
33
20
 
34
21
  if (resolvedConfig.output.enableModernMode) {
35
- outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.MODERN, appContext, resolvedConfig, options));
22
+ targets.push('modern-web');
36
23
  }
37
24
 
38
25
  if ((0, _utils.isUseSSRBundle)(resolvedConfig)) {
39
- outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.NODE, appContext, resolvedConfig, options));
26
+ targets.push('node');
40
27
  }
41
28
 
42
- _utils.logger.success('Inspect succeed, you can open following files to view the full webpack config: \n');
43
-
44
- outputFiles.forEach(file => {
45
- _utils.logger.log(` - ${_utils.chalk.yellow(_path.default.relative(appContext.appDirectory, file))}`);
29
+ const builder = await (0, _builder.default)({
30
+ target: targets,
31
+ appContext,
32
+ normalizedConfig: resolvedConfig
33
+ });
34
+ return builder.inspectConfig({
35
+ env: options.env,
36
+ verbose: options.verbose,
37
+ outputPath: (0, _path.join)(builder.context.distPath, options.output),
38
+ writeToDisk: true
46
39
  });
47
-
48
- _utils.logger.log();
49
- };
50
-
51
- exports.inspect = inspect;
52
-
53
- const getTagByWebpackTarget = webpackTarget => {
54
- switch (webpackTarget) {
55
- case _webpack.WebpackConfigTarget.CLIENT:
56
- return 'client';
57
-
58
- case _webpack.WebpackConfigTarget.MODERN:
59
- return 'modern';
60
-
61
- case _webpack.WebpackConfigTarget.NODE:
62
- return 'ssr';
63
-
64
- default:
65
- throw Error(`Unsupported webpack target: ${webpackTarget}`);
66
- }
67
- };
68
-
69
- exports.getTagByWebpackTarget = getTagByWebpackTarget;
70
-
71
- const printInspectResult = (webpackTarget, appContext, resolvedConfig, options) => {
72
- const webpackConfig = (0, _webpack.getWebpackConfig)(webpackTarget, appContext, resolvedConfig);
73
- const {
74
- output,
75
- verbose,
76
- console = true
77
- } = options;
78
- const outputPath = output ? _path.default.posix.join(appContext.distDirectory, output) : appContext.distDirectory;
79
- const tag = getTagByWebpackTarget(webpackTarget);
80
- const outputFile = `webpack.${tag}.inspect.js`;
81
-
82
- const outputFilePath = _path.default.posix.join(outputPath, outputFile);
83
-
84
- const rawWebpackConfig = formatWebpackConfig(webpackConfig, verbose);
85
-
86
- _utils.fs.outputFileSync(outputFilePath, rawWebpackConfig);
87
-
88
- if (console) {
89
- _utils.logger.log(`
90
- webpack config for ${tag} build:
91
- ${rawWebpackConfig}
92
- `);
93
- }
94
-
95
- return outputFilePath;
96
40
  };
97
41
 
98
- exports.printInspectResult = printInspectResult;
42
+ exports.inspect = inspect;
@@ -11,6 +11,8 @@ var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
11
11
 
12
12
  var _printInstructions = require("../utils/printInstructions");
13
13
 
14
+ var _createServer = require("../utils/createServer");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
18
  const start = async api => {
@@ -31,8 +33,8 @@ const start = async api => {
31
33
  const app = await (0, _prodServer.default)({
32
34
  pwd: appDirectory,
33
35
  config: userConfig,
34
- plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
35
36
  serverConfigFile,
37
+ internalPlugins: (0, _createServer.injectDataLoaderPlugin)(appContext.serverInternalPlugins),
36
38
  apiOnly
37
39
  });
38
40
  app.listen(port, async err => {
@@ -10,6 +10,12 @@ Object.defineProperty(exports, "defineConfig", {
10
10
  return _core.defineConfig;
11
11
  }
12
12
  });
13
+ Object.defineProperty(exports, "hooks", {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _hooks.hooks;
17
+ }
18
+ });
13
19
 
14
20
  var _path = _interopRequireDefault(require("path"));
15
21
 
@@ -27,6 +33,8 @@ var _locale = require("./locale");
27
33
 
28
34
  var _language = require("./utils/language");
29
35
 
36
+ var _commands = require("./utils/commands");
37
+
30
38
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
39
 
32
40
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -43,7 +51,7 @@ const upgradeModel = _utils.Import.lazy('@modern-js/upgrade', require);
43
51
 
44
52
  var _default = () => ({
45
53
  name: '@modern-js/app-tools',
46
- post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-polyfill'],
54
+ post: ['@modern-js/plugin-analyze', '@modern-js/plugin-ssr', '@modern-js/plugin-state', '@modern-js/plugin-router', '@modern-js/plugin-router-legacy', '@modern-js/plugin-polyfill'],
47
55
  registerHook: _hooks.hooks,
48
56
  usePlugins: [(0, _analyze.default)(), (0, _pluginJarvis.default)()],
49
57
  setup: api => {
@@ -98,7 +106,7 @@ var _default = () => ({
98
106
  locale
99
107
  }));
100
108
  });
101
- program.command('inspect').description('inspect internal webpack config').option(`--env <env>`, _locale.i18n.t(_locale.localeKeys.command.inspect.env), 'development').option('--output <output>', _locale.i18n.t(_locale.localeKeys.command.inspect.output), '/').option('--no-console', _locale.i18n.t(_locale.localeKeys.command.inspect.noConsole)).option('--verbose', _locale.i18n.t(_locale.localeKeys.command.inspect.verbose)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async options => {
109
+ program.command('inspect').description('inspect internal webpack config').option(`--env <env>`, _locale.i18n.t(_locale.localeKeys.command.inspect.env), 'development').option('--output <output>', _locale.i18n.t(_locale.localeKeys.command.inspect.output), '/').option('--verbose', _locale.i18n.t(_locale.localeKeys.command.inspect.verbose)).option('-c --config <config>', _locale.i18n.t(_locale.localeKeys.command.shared.config)).action(async options => {
102
110
  const {
103
111
  inspect
104
112
  } = await Promise.resolve().then(() => _interopRequireWildcard(require("./commands/inspect")));
@@ -107,6 +115,15 @@ var _default = () => ({
107
115
  upgradeModel.defineCommand(program.command('upgrade'));
108
116
  },
109
117
 
118
+ async prepare() {
119
+ const command = (0, _commands.getCommand)();
120
+
121
+ if (command === 'dev' || command === 'build') {
122
+ const appContext = api.useAppContext();
123
+ await (0, _utils.emptyDir)(appContext.distDirectory);
124
+ }
125
+ },
126
+
110
127
  // 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
111
128
  async fileChange(e) {
112
129
  const {
@@ -34,7 +34,6 @@ const EN_LOCALE = {
34
34
  inspect: {
35
35
  env: 'specify env mode',
36
36
  output: 'specify inspect content output path',
37
- noConsole: 'do not log the result in terminal',
38
37
  verbose: 'show full function definitions in output'
39
38
  }
40
39
  }
@@ -34,7 +34,6 @@ const ZH_LOCALE = {
34
34
  inspect: {
35
35
  env: '查看指定环境下的配置',
36
36
  output: '指定在 dist 目录下输出的路径',
37
- noConsole: '不在终端中输出完整结果',
38
37
  verbose: '在结果中展示函数的完整内容'
39
38
  }
40
39
  }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getCommand = void 0;
7
+
8
+ const getCommand = () => {
9
+ const args = process.argv.slice(2);
10
+ const command = args[0];
11
+ return command;
12
+ };
13
+
14
+ exports.getCommand = getCommand;
@@ -3,68 +3,62 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.createCompiler = void 0;
7
-
8
- var _webpack = require("@modern-js/webpack");
6
+ exports.createDevCompiler = void 0;
9
7
 
10
8
  var _utils = require("@modern-js/utils");
11
9
 
10
+ var _builder = _interopRequireDefault(require("../builder"));
11
+
12
12
  var _printInstructions = require("./printInstructions");
13
13
 
14
- const createCompiler = async ({
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
16
+ const createDevCompiler = async ({
15
17
  api,
16
- webpackConfigs,
17
- // TODO: params
18
- userConfig,
18
+ target,
19
+ normalizedConfig,
19
20
  appContext
20
21
  }) => {
21
22
  try {
22
23
  const hookRunners = api.useHookRunners();
23
- await hookRunners.beforeCreateCompiler({
24
- webpackConfigs
25
- });
26
- const compiler = (0, _webpack.webpack)(webpackConfigs);
27
- await hookRunners.afterCreateCompiler({
28
- compiler
29
- });
30
- let isFirstCompile = true;
31
- compiler.hooks.invalid.tap('invalid', () => {
32
- (0, _utils.clearConsole)();
33
-
34
- _utils.logger.log('Compiling...');
35
- });
36
- compiler.hooks.done.tap('done', async stats => {
37
- const statsData = stats.toJson({
38
- preset: 'errors-warnings'
39
- });
40
- const {
41
- errors,
42
- warnings
43
- } = (0, _utils.formatWebpackMessages)(statsData);
44
-
45
- if (errors.length) {
46
- _utils.logger.log(_utils.chalk.red(`Failed to compile.\n`));
47
-
48
- _utils.logger.log(errors.join('\n\n'));
49
-
50
- _utils.logger.log();
51
- } else if (process.stdout.isTTY || isFirstCompile) {
52
- await hookRunners.afterDev();
53
-
54
- if (warnings.length) {
55
- _utils.logger.log(_utils.chalk.yellow(`Compiled with warnings.\n`));
56
-
57
- _utils.logger.log(warnings.join('\n\n'));
58
-
59
- _utils.logger.log();
24
+ const builder = await (0, _builder.default)({
25
+ target,
26
+ normalizedConfig,
27
+ appContext,
28
+ compatPluginConfig: {
29
+ async onDevCompileDone({
30
+ isFirstCompile
31
+ }) {
32
+ if (process.stdout.isTTY || isFirstCompile) {
33
+ hookRunners.afterDev();
34
+
35
+ if (isFirstCompile) {
36
+ (0, _printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
37
+ }
38
+ }
39
+ },
40
+
41
+ async onBeforeCreateCompiler({
42
+ bundlerConfigs
43
+ }) {
44
+ // run modernjs framework `beforeCreateCompiler` hook
45
+ await hookRunners.beforeCreateCompiler({
46
+ bundlerConfigs
47
+ });
48
+ },
49
+
50
+ async onAfterCreateCompiler({
51
+ compiler
52
+ }) {
53
+ // run modernjs framework afterCreateCompiler hooks
54
+ await hookRunners.afterCreateCompiler({
55
+ compiler
56
+ });
60
57
  }
61
58
 
62
- await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
63
59
  }
64
-
65
- isFirstCompile = false;
66
60
  });
67
- return compiler;
61
+ return builder.createCompiler();
68
62
  } catch (err) {
69
63
  _utils.logger.log(_utils.chalk.red(`Failed to compile.`));
70
64
 
@@ -78,4 +72,4 @@ const createCompiler = async ({
78
72
  }
79
73
  };
80
74
 
81
- exports.createCompiler = createCompiler;
75
+ exports.createDevCompiler = createDevCompiler;
@@ -3,10 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getServer = exports.createServer = exports.closeServer = void 0;
6
+ exports.injectDataLoaderPlugin = exports.getServer = exports.createServer = exports.closeServer = void 0;
7
7
 
8
8
  var _server = require("@modern-js/server");
9
9
 
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
11
+
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
13
+
14
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
+
10
16
  let server = null;
11
17
 
12
18
  const getServer = () => server;
@@ -32,4 +38,17 @@ const createServer = async options => {
32
38
  return app;
33
39
  };
34
40
 
35
- exports.createServer = createServer;
41
+ exports.createServer = createServer;
42
+
43
+ const injectDataLoaderPlugin = internalPlugins => {
44
+ const DataLoaderPlugin = require.resolve('@modern-js/plugin-data-loader/server');
45
+
46
+ return _objectSpread(_objectSpread({}, internalPlugins), {}, {
47
+ '@modern-js/plugin-data-loader': {
48
+ path: DataLoaderPlugin,
49
+ forced: true
50
+ }
51
+ });
52
+ };
53
+
54
+ exports.injectDataLoaderPlugin = injectDataLoaderPlugin;
@@ -16,7 +16,7 @@ const printInstructions = async (hookRunners, appContext, config) => {
16
16
  instructions: message
17
17
  });
18
18
 
19
- _utils.logger.log(instructions);
19
+ _utils.logger.info(instructions);
20
20
  };
21
21
 
22
22
  exports.printInstructions = printInstructions;
@@ -0,0 +1,16 @@
1
+ export var JS_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
2
+ export var INDEX_FILE_NAME = 'index';
3
+ export var APP_FILE_NAME = 'App';
4
+ export var PAGES_DIR_NAME = 'pages';
5
+ export var NESTED_ROUTES_DIR = 'routes';
6
+ export var FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
7
+ export var ENTRY_POINT_FILE_NAME = 'index.js';
8
+ export var ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
9
+ export var FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
10
+ export var FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
11
+ export var FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = '_app';
12
+ export var FILE_SYSTEM_ROUTES_INDEX = 'index';
13
+ export var FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
14
+ export var HTML_PARTIALS_FOLDER = 'html';
15
+ export var HTML_PARTIALS_EXTENSIONS = ['.htm', '.html', '.ejs'];
16
+ export var FILE_SYSTEM_ROUTES_COMPONENTS_DIR = 'internal_components';