@modern-js/app-tools 2.7.0 → 2.8.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 (76) hide show
  1. package/CHANGELOG.md +53 -2
  2. package/README.md +2 -2
  3. package/dist/cjs/analyze/generateCode.js +16 -2
  4. package/dist/cjs/analyze/index.js +0 -32
  5. package/dist/cjs/analyze/templates.js +26 -2
  6. package/dist/cjs/analyze/utils.js +5 -0
  7. package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
  8. package/dist/cjs/builder/generator/index.js +10 -2
  9. package/dist/cjs/builder/index.js +1 -1
  10. package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +101 -0
  11. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +91 -0
  12. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +164 -0
  13. package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/builderPlugins}/index.js +5 -3
  14. package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
  15. package/dist/cjs/builder/shared/bundlerPlugins/index.js +19 -0
  16. package/dist/cjs/builder/shared/index.js +1 -1
  17. package/dist/cjs/index.js +1 -1
  18. package/dist/cjs/locale/en.js +1 -0
  19. package/dist/cjs/locale/zh.js +1 -0
  20. package/dist/esm/analyze/generateCode.js +34 -19
  21. package/dist/esm/analyze/index.js +2 -25
  22. package/dist/esm/analyze/templates.js +16 -2
  23. package/dist/esm/analyze/utils.js +4 -1
  24. package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +0 -11
  25. package/dist/esm/builder/generator/index.js +6 -4
  26. package/dist/esm/builder/index.js +1 -1
  27. package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +101 -0
  28. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +120 -0
  29. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +350 -0
  30. package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
  31. package/dist/esm/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +10 -6
  32. package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
  33. package/dist/esm/builder/shared/index.js +1 -1
  34. package/dist/esm/index.js +1 -1
  35. package/dist/esm/locale/en.js +1 -0
  36. package/dist/esm/locale/zh.js +1 -0
  37. package/dist/esm-node/analyze/generateCode.js +29 -4
  38. package/dist/esm-node/analyze/index.js +1 -39
  39. package/dist/esm-node/analyze/templates.js +25 -2
  40. package/dist/esm-node/analyze/utils.js +4 -0
  41. package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
  42. package/dist/esm-node/builder/generator/index.js +10 -2
  43. package/dist/esm-node/builder/index.js +1 -1
  44. package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +67 -0
  45. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +67 -0
  46. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +143 -0
  47. package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
  48. package/dist/esm-node/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
  49. package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
  50. package/dist/esm-node/builder/shared/index.js +1 -1
  51. package/dist/esm-node/index.js +1 -1
  52. package/dist/esm-node/locale/en.js +1 -0
  53. package/dist/esm-node/locale/zh.js +1 -0
  54. package/dist/types/analyze/templates.d.ts +3 -2
  55. package/dist/types/analyze/utils.d.ts +2 -1
  56. package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +7 -0
  57. package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +5 -0
  58. package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +4 -0
  59. package/dist/types/builder/shared/builderPlugins/index.d.ts +3 -0
  60. package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +5 -0
  61. package/dist/types/builder/shared/bundlerPlugins/index.d.ts +3 -0
  62. package/dist/types/builder/shared/index.d.ts +1 -1
  63. package/dist/types/builder/shared/types.d.ts +7 -4
  64. package/dist/types/locale/en.d.ts +1 -0
  65. package/dist/types/locale/index.d.ts +2 -0
  66. package/dist/types/locale/zh.d.ts +1 -0
  67. package/dist/types/types/config/output.d.ts +2 -15
  68. package/package.json +26 -26
  69. package/dist/cjs/builder/shared/builderPlugins/adapterModern.js +0 -234
  70. package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +0 -1
  71. package/dist/esm/builder/shared/builderPlugins/adapterModern.js +0 -300
  72. package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +0 -1
  73. package/dist/esm-node/builder/shared/builderPlugins/adapterModern.js +0 -202
  74. package/dist/types/builder/builder-webpack/webpackPlugins/RouterPlugin.d.ts +0 -4
  75. package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +0 -1
  76. package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +0 -13
@@ -21,8 +21,16 @@ async function generateBuilder(options, generateProvider, utils) {
21
21
  return builder;
22
22
  }
23
23
  async function applyBuilderPlugins(builder, options) {
24
- const { builderPluginAdapterModern } = await import("../shared/builderPlugins/adapterModern");
25
- builder.addPlugins([builderPluginAdapterModern(options)]);
24
+ const {
25
+ builderPluginAdapterBasic,
26
+ builderPluginAdapterHtml,
27
+ builderPluginAdapterSSR
28
+ } = await import("../shared/builderPlugins");
29
+ builder.addPlugins([
30
+ builderPluginAdapterBasic(options),
31
+ builderPluginAdapterSSR(options),
32
+ builderPluginAdapterHtml(options)
33
+ ]);
26
34
  }
27
35
  export {
28
36
  generateBuilder
@@ -5,7 +5,7 @@ async function createBuilderGenerator(bundler) {
5
5
  return createRspackBuilderForModern;
6
6
  } catch (_) {
7
7
  throw new Error(
8
- "Failed to use rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
8
+ "Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
9
9
  );
10
10
  }
11
11
  }
@@ -0,0 +1,67 @@
1
+ const builderPluginAdapterBasic = (options) => ({
2
+ name: "builder-plugin-adapter-modern-basic",
3
+ setup(api) {
4
+ api.modifyBundlerChain((chain, { target, CHAIN_ID }) => {
5
+ if (target === "node") {
6
+ chain.name("server");
7
+ } else if (target === "service-worker") {
8
+ chain.name("service-worker");
9
+ } else if (target === "web-worker") {
10
+ chain.name("worker");
11
+ } else if (target === "modern-web") {
12
+ chain.name("modern");
13
+ } else {
14
+ chain.name("client");
15
+ }
16
+ if (target === "node" || target === "service-worker") {
17
+ applyNodeCompat(target, chain);
18
+ }
19
+ if (target === "web" || target === "modern-web") {
20
+ const bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
21
+ chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
22
+ chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
23
+ }
24
+ });
25
+ applyCallbacks(api, options);
26
+ }
27
+ });
28
+ function applyCallbacks(api, options) {
29
+ options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
30
+ options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
31
+ options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
32
+ options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
33
+ options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
34
+ options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
35
+ options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
36
+ options.onExit && api.onExit(options.onExit);
37
+ }
38
+ function applyNodeCompat(target, chain) {
39
+ const nodeExts = [
40
+ ".node.js",
41
+ ".node.jsx",
42
+ ".node.ts",
43
+ ".node.tsx",
44
+ ".server.js",
45
+ ".server.ts",
46
+ ".server.ts",
47
+ ".server.tsx"
48
+ ];
49
+ const webWorkerExts = [
50
+ ".worker.js",
51
+ ".worker.jsx",
52
+ ".worker.ts",
53
+ ".worker.tsx"
54
+ ];
55
+ for (const ext of nodeExts) {
56
+ chain.resolve.extensions.prepend(ext);
57
+ }
58
+ if (target === "service-worker") {
59
+ for (const ext of webWorkerExts) {
60
+ chain.resolve.extensions.prepend(ext);
61
+ }
62
+ }
63
+ }
64
+ export {
65
+ applyCallbacks,
66
+ builderPluginAdapterBasic
67
+ };
@@ -0,0 +1,67 @@
1
+ import { getEntryOptions } from "@modern-js/utils";
2
+ import { template as lodashTemplate } from "@modern-js/utils/lodash";
3
+ import { BottomTemplatePlugin } from "../bundlerPlugins";
4
+ function isHtmlEnabled(config, target) {
5
+ var _a;
6
+ return ((_a = config.tools) == null ? void 0 : _a.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
7
+ }
8
+ const builderPluginAdapterHtml = (options) => ({
9
+ name: "builder-plugin-adpater-modern-html",
10
+ setup(api) {
11
+ api.modifyBundlerChain(
12
+ (chain, { CHAIN_ID, target, HtmlPlugin: HtmlBundlerPlugin }) => {
13
+ const builderConfig = api.getNormalizedConfig();
14
+ if (isHtmlEnabled(builderConfig, target)) {
15
+ applyBottomHtmlPlugin({
16
+ api,
17
+ options,
18
+ chain,
19
+ CHAIN_ID,
20
+ HtmlBundlerPlugin
21
+ });
22
+ }
23
+ }
24
+ );
25
+ }
26
+ });
27
+ function applyBottomHtmlPlugin({
28
+ api,
29
+ chain,
30
+ options,
31
+ CHAIN_ID,
32
+ HtmlBundlerPlugin
33
+ }) {
34
+ const { normalizedConfig: modernConfig, appContext } = options;
35
+ for (const entryName of Object.keys(api.context.entry)) {
36
+ const baseTemplateParams = {
37
+ entryName,
38
+ title: getEntryOptions(
39
+ entryName,
40
+ modernConfig.html.title,
41
+ modernConfig.html.titleByEntries,
42
+ appContext.packageName
43
+ ),
44
+ mountId: modernConfig.html.mountId,
45
+ ...getEntryOptions(
46
+ entryName,
47
+ modernConfig.html.templateParameters,
48
+ modernConfig.html.templateParametersByEntries,
49
+ appContext.packageName
50
+ )
51
+ };
52
+ chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
53
+ {
54
+ ...args[0] || {},
55
+ __internal__: true,
56
+ bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(
57
+ baseTemplateParams
58
+ )
59
+ }
60
+ ]);
61
+ }
62
+ chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlBundlerPlugin]);
63
+ }
64
+ export {
65
+ builderPluginAdapterHtml,
66
+ isHtmlEnabled
67
+ };
@@ -0,0 +1,143 @@
1
+ import {
2
+ mergeBuilderConfig
3
+ } from "@modern-js/builder-shared";
4
+ import { fs } from "@modern-js/utils";
5
+ import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
6
+ import { getServerCombinedModueFile } from "../../../analyze/utils";
7
+ import { isHtmlEnabled } from "./adapterHtml";
8
+ const builderPluginAdapterSSR = (options) => ({
9
+ name: "builder-plugin-adapter-modern-ssr",
10
+ setup(api) {
11
+ const { normalizedConfig } = options;
12
+ api.modifyBuilderConfig((config) => {
13
+ if (isStreamingSSR(normalizedConfig)) {
14
+ return mergeBuilderConfig(config, {
15
+ html: {
16
+ inject: "body"
17
+ }
18
+ });
19
+ }
20
+ return config;
21
+ });
22
+ api.modifyBundlerChain(
23
+ async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
24
+ const builderConfig = api.getNormalizedConfig();
25
+ applyRouterPlugin(chain, options);
26
+ await applySSRLoaderEntry(chain, options, isServer);
27
+ if (["node", "service-worker"].includes(target)) {
28
+ applyFilterEntriesBySSRConfig({
29
+ isProd,
30
+ chain,
31
+ appNormalizedConfig: options.normalizedConfig
32
+ });
33
+ }
34
+ if (isHtmlEnabled(builderConfig, target)) {
35
+ applyAsyncChunkHtmlPlugin({
36
+ chain,
37
+ modernConfig: options.normalizedConfig,
38
+ CHAIN_ID,
39
+ HtmlBundlerPlugin
40
+ });
41
+ }
42
+ }
43
+ );
44
+ }
45
+ });
46
+ const isStreamingSSR = (userConfig) => {
47
+ const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
48
+ const { server } = userConfig;
49
+ if (isStreaming(server.ssr)) {
50
+ return true;
51
+ }
52
+ if ((server == null ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
53
+ for (const name of Object.keys(server.ssrByEntries)) {
54
+ if (isStreaming(server.ssrByEntries[name])) {
55
+ return true;
56
+ }
57
+ }
58
+ }
59
+ return false;
60
+ };
61
+ function applyAsyncChunkHtmlPlugin({
62
+ chain,
63
+ modernConfig,
64
+ CHAIN_ID,
65
+ HtmlBundlerPlugin
66
+ }) {
67
+ if (isStreamingSSR(modernConfig)) {
68
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlBundlerPlugin]);
69
+ }
70
+ }
71
+ function applyRouterPlugin(chain, options) {
72
+ var _a;
73
+ const { appContext, normalizedConfig } = options;
74
+ const { entrypoints } = appContext;
75
+ const existNestedRoutes = entrypoints.some(
76
+ (entrypoint) => entrypoint.nestedRoutesEntry
77
+ );
78
+ const routerConfig = (_a = normalizedConfig == null ? void 0 : normalizedConfig.runtime) == null ? void 0 : _a.router;
79
+ const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
80
+ if (existNestedRoutes || routerManifest) {
81
+ chain.plugin("route-plugin").use(RouterPlugin);
82
+ }
83
+ }
84
+ function applyFilterEntriesBySSRConfig({
85
+ isProd,
86
+ chain,
87
+ appNormalizedConfig
88
+ }) {
89
+ var _a;
90
+ const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
91
+ const entries = chain.entryPoints.entries();
92
+ if (isProd && ((outputConfig == null ? void 0 : outputConfig.ssg) === true || typeof ((_a = outputConfig == null ? void 0 : outputConfig.ssg) == null ? void 0 : _a[0]) === "function")) {
93
+ return;
94
+ }
95
+ if (typeof entries === "undefined") {
96
+ throw new Error(
97
+ "No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required"
98
+ );
99
+ }
100
+ const entryNames = Object.keys(entries);
101
+ if (isProd && entryNames.length === 1 && (outputConfig == null ? void 0 : outputConfig.ssg)) {
102
+ return;
103
+ }
104
+ const ssgEntries = [];
105
+ if (isProd && (outputConfig == null ? void 0 : outputConfig.ssg)) {
106
+ const { ssg } = outputConfig;
107
+ entryNames.forEach((name) => {
108
+ if (ssg[name]) {
109
+ ssgEntries.push(name);
110
+ }
111
+ });
112
+ }
113
+ const { ssr, ssrByEntries } = serverConfig || {};
114
+ entryNames.forEach((name) => {
115
+ if (!ssgEntries.includes(name) && (ssr && (ssrByEntries == null ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries == null ? void 0 : ssrByEntries[name]))) {
116
+ chain.entryPoints.delete(name);
117
+ }
118
+ });
119
+ }
120
+ async function applySSRLoaderEntry(chain, optinos, isServer) {
121
+ const { appContext } = optinos;
122
+ const { internalDirectory } = appContext;
123
+ const { entrypoints } = appContext;
124
+ await Promise.all(
125
+ entrypoints.map(async (entrypoint) => {
126
+ const { entryName } = entrypoint;
127
+ const serverLoadersFile = getServerCombinedModueFile(
128
+ internalDirectory,
129
+ entryName
130
+ );
131
+ if (isServer) {
132
+ try {
133
+ await fs.access(serverLoadersFile, fs.constants.F_OK);
134
+ chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
135
+ } catch (err) {
136
+ }
137
+ }
138
+ })
139
+ );
140
+ }
141
+ export {
142
+ builderPluginAdapterSSR
143
+ };
@@ -0,0 +1,3 @@
1
+ export * from "./adapterBasic";
2
+ export * from "./adapterHtml";
3
+ export * from "./adapterSSR";
@@ -38,7 +38,7 @@ class RouterPlugin {
38
38
  chunkGroups: true,
39
39
  chunks: true
40
40
  });
41
- const { publicPath } = stats;
41
+ const { publicPath, chunks = [] } = stats;
42
42
  const routeAssets = {};
43
43
  const { namedChunkGroups, assetsByChunkName } = stats;
44
44
  if (!namedChunkGroups || !assetsByChunkName) {
@@ -71,17 +71,23 @@ class RouterPlugin {
71
71
  const entryChunkIds = entrypointsArray.map(
72
72
  (entrypoint) => entrypoint[0]
73
73
  );
74
- const entryChunks = [...compilation.chunks].filter((chunk) => {
75
- return entryChunkIds.includes(chunk.name);
74
+ const entryChunks = [...chunks].filter((chunk) => {
75
+ var _a;
76
+ return (_a = chunk.names) == null ? void 0 : _a.some((name) => entryChunkIds.includes(name));
76
77
  });
77
78
  const entryChunkFiles = entryChunks.map(
78
- (chunk) => [...chunk.files].find((fname) => fname.includes(".js"))
79
+ (chunk) => [...chunk.files || []].find((fname) => fname.includes(".js"))
79
80
  );
80
81
  for (const file of entryChunkFiles) {
81
82
  const asset = compilation.assets[file];
82
83
  const newContent = `${injectedContent}${asset.source().toString()}`;
83
84
  newAssetsMap.set(path.join(outputPath, file), newContent);
84
- compilation.updateAsset(file, new RawSource(newContent));
85
+ compilation.updateAsset(
86
+ file,
87
+ new RawSource(newContent),
88
+ // FIXME: The arguments third of updatgeAsset is a optional function in webpack.
89
+ void 0
90
+ );
85
91
  }
86
92
  const filename = path.join(outputPath, ROUTE_MINIFEST_FILE);
87
93
  await fs.ensureFile(filename);
@@ -0,0 +1,3 @@
1
+ export * from "./HtmlAsyncChunkPlugin";
2
+ export * from "./HtmlBottomTemplate";
3
+ export * from "./RouterPlugin";
@@ -1,3 +1,3 @@
1
1
  export * from "./createCopyPattern";
2
2
  export * from "./types";
3
- export * from "./builderPlugins/adapterModern";
3
+ export * from "./builderPlugins";
@@ -23,7 +23,7 @@ const upgradeModel = Import.lazy(
23
23
  const devCommand = async (program, api) => {
24
24
  const runner = api.useHookRunners();
25
25
  const devToolMetas = await runner.registerDev();
26
- const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).action(async (options) => {
26
+ const devProgram = program.command("dev").alias("start").usage("[options]").description(i18n.t(localeKeys.command.dev.describe)).option("-c --config <config>", i18n.t(localeKeys.command.shared.config)).option("-e --entry [entry...]", i18n.t(localeKeys.command.dev.entry)).option("--analyze", i18n.t(localeKeys.command.shared.analyze)).option("--api-only", i18n.t(localeKeys.command.dev.apiOnly)).option("--web-only", i18n.t(localeKeys.command.dev.webOnly)).action(async (options) => {
27
27
  const { dev } = await import("./commands/dev");
28
28
  await dev(api, options);
29
29
  });
@@ -8,6 +8,7 @@ const EN_LOCALE = {
8
8
  describe: "start dev server",
9
9
  entry: "compiler by entry",
10
10
  apiOnly: "start api server only",
11
+ webOnly: "start web server only",
11
12
  selectEntry: "Please select the entry that needs to be built",
12
13
  requireEntry: "You must choose at least one entry"
13
14
  },
@@ -8,6 +8,7 @@ const ZH_LOCALE = {
8
8
  describe: "本地开发命令",
9
9
  entry: "指定入口,编译特定的页面",
10
10
  apiOnly: "仅启动 API 接口服务",
11
+ webOnly: "仅启动 Web 服务",
11
12
  selectEntry: "请选择需要构建的入口",
12
13
  requireEntry: "请至少选择一个入口"
13
14
  },
@@ -1,5 +1,5 @@
1
1
  import type { Entrypoint, NestedRoute, PageRoute, RouteLegacy, SSRMode } from '@modern-js/types';
2
- import type { RuntimePlugin } from '../types';
2
+ import type { AppNormalizedConfig, IAppContext, RuntimePlugin } from '../types';
3
3
  export declare const index: ({
4
4
  mountId,
5
5
  imports,
@@ -42,4 +42,5 @@ export declare const fileSystemRoutes: ({
42
42
  nestedRoutesEntry?: string | undefined;
43
43
  entryName: string;
44
44
  internalDirectory: string;
45
- }) => Promise<string>;
45
+ }) => Promise<string>;
46
+ export declare function ssrLoaderCombinedModule(entrypoints: Entrypoint[], entrypoint: Entrypoint, config: AppNormalizedConfig<'shared'>, appContext: IAppContext): string | null;
@@ -24,4 +24,5 @@ export declare const parseModule: ({
24
24
  filename: string;
25
25
  }) => Promise<readonly [imports: readonly import("es-module-lexer").ImportSpecifier[], exports: readonly import("es-module-lexer").ExportSpecifier[], facade: boolean]>;
26
26
  export declare const hasLoader: (filename: string) => Promise<boolean>;
27
- export declare const getServerLoadersFile: (internalDirectory: string, entryName: string) => string;
27
+ export declare const getServerLoadersFile: (internalDirectory: string, entryName: string) => string;
28
+ export declare const getServerCombinedModueFile: (internalDirectory: string, entryName: string) => string;
@@ -0,0 +1,7 @@
1
+ import { BuilderPlugin } from '@modern-js/builder-shared';
2
+ import type { BuilderOptions, BuilderPluginAPI } from '../types';
3
+ import type { Bundler } from '../../../types';
4
+ export declare const builderPluginAdapterBasic: <B extends Bundler>(options: BuilderOptions<B>) => BuilderPlugin<BuilderPluginAPI>;
5
+ /** register builder hooks callback */
6
+
7
+ export declare function applyCallbacks<B extends Bundler>(api: BuilderPluginAPI, options: BuilderOptions<B>): void;
@@ -0,0 +1,5 @@
1
+ import type { BuilderPlugin, BuilderTarget } from '@modern-js/builder-shared';
2
+ import { Bundler } from '../../../types';
3
+ import type { BuilderNormalizedConfig, BuilderOptions, BuilderPluginAPI } from '../types';
4
+ export declare function isHtmlEnabled(config: BuilderNormalizedConfig, target: BuilderTarget): boolean;
5
+ export declare const builderPluginAdapterHtml: <B extends Bundler>(options: BuilderOptions<B>) => BuilderPlugin<BuilderPluginAPI>;
@@ -0,0 +1,4 @@
1
+ import { BuilderPlugin } from '@modern-js/builder-shared';
2
+ import type { Bundler } from '../../../types';
3
+ import type { BuilderOptions, BuilderPluginAPI } from '../types';
4
+ export declare const builderPluginAdapterSSR: <B extends Bundler>(options: BuilderOptions<B>) => BuilderPlugin<BuilderPluginAPI>;
@@ -0,0 +1,3 @@
1
+ export * from './adapterBasic';
2
+ export * from './adapterHtml';
3
+ export * from './adapterSSR';
@@ -0,0 +1,5 @@
1
+ import type { webpack } from '@modern-js/builder-webpack-provider';
2
+ import type { Rspack } from '@modern-js/builder-rspack-provider';
3
+ export declare class RouterPlugin {
4
+ apply(compiler: Rspack.Compiler | webpack.Compiler): void;
5
+ }
@@ -0,0 +1,3 @@
1
+ export * from './HtmlAsyncChunkPlugin';
2
+ export * from './HtmlBottomTemplate';
3
+ export * from './RouterPlugin';
@@ -1,3 +1,3 @@
1
1
  export * from './createCopyPattern';
2
2
  export * from './types';
3
- export * from './builderPlugins/adapterModern';
3
+ export * from './builderPlugins';
@@ -1,7 +1,7 @@
1
- import type { BuilderPluginAPI as WebpackBuilderPluginAPI } from '@modern-js/builder-webpack-provider';
2
- import type { BuilderPluginAPI as RspackBuilderPluginAPI } from '@modern-js/builder-rspack-provider';
3
- import { BuilderInstance } from '@modern-js/builder-shared';
4
- import { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
1
+ import type { BuilderPluginAPI as WebpackBuilderPluginAPI, BuilderConfig as WebpackBuilderConfig, NormalizedConfig as WebpackNormalizedConfig } from '@modern-js/builder-webpack-provider';
2
+ import type { BuilderPluginAPI as RspackBuilderPluginAPI, BuilderConfig as RspackBuilderConfig, NormalizedConfig as RspackNormalizedConfig } from '@modern-js/builder-rspack-provider';
3
+ import type { BuilderInstance, DefaultBuilderPluginAPI } from '@modern-js/builder-shared';
4
+ import type { AppNormalizedConfig, Bundler, IAppContext } from '../../types';
5
5
  type Parameter<T extends (arg: any) => void> = Parameters<T>[0];
6
6
  type FnParameter<T extends {
7
7
  [p: string]: (arg: any) => void;
@@ -13,4 +13,7 @@ export type BuilderOptions<B extends Bundler> = {
13
13
  } & BuilderPluginCallbacks<B>;
14
14
  export type ModifyBuilderConfig<B extends Bundler> = (config: AppNormalizedConfig<B>) => Promise<void> | void;
15
15
  export type ModifyBuilderInstance = (builder: BuilderInstance) => Promise<void> | void;
16
+ export type BuilderConfig = RspackBuilderConfig | WebpackBuilderConfig;
17
+ export type BuilderNormalizedConfig = RspackNormalizedConfig | WebpackNormalizedConfig;
18
+ export type BuilderPluginAPI = DefaultBuilderPluginAPI<BuilderConfig, BuilderNormalizedConfig>;
16
19
  export {};
@@ -8,6 +8,7 @@ export declare const EN_LOCALE: {
8
8
  describe: string;
9
9
  entry: string;
10
10
  apiOnly: string;
11
+ webOnly: string;
11
12
  selectEntry: string;
12
13
  requireEntry: string;
13
14
  };
@@ -10,6 +10,7 @@ declare const localeKeys: {
10
10
  describe: string;
11
11
  entry: string;
12
12
  apiOnly: string;
13
+ webOnly: string;
13
14
  selectEntry: string;
14
15
  requireEntry: string;
15
16
  };
@@ -46,6 +47,7 @@ declare const localeKeys: {
46
47
  describe: string;
47
48
  entry: string;
48
49
  apiOnly: string;
50
+ webOnly: string;
49
51
  selectEntry: string;
50
52
  requireEntry: string;
51
53
  };
@@ -8,6 +8,7 @@ export declare const ZH_LOCALE: {
8
8
  describe: string;
9
9
  entry: string;
10
10
  apiOnly: string;
11
+ webOnly: string;
11
12
  selectEntry: string;
12
13
  requireEntry: string;
13
14
  };
@@ -1,6 +1,7 @@
1
1
  import type { BuilderConfig } from '@modern-js/builder-webpack-provider';
2
2
  import type { BuilderConfig as RsBuilderConfig } from '@modern-js/builder-rspack-provider';
3
3
  import type { SharedOutputConfig as BuilderSharedOutputConfig } from '@modern-js/builder-shared';
4
+ import type { SSGConfig } from '@modern-js/types';
4
5
  import { UnwrapBuilderConfig } from '../utils';
5
6
  export type BuilderOutputConfig = UnwrapBuilderConfig<BuilderConfig, 'output'>;
6
7
  export type RsBuilderOutputConfig = UnwrapBuilderConfig<RsBuilderConfig, 'output'>;
@@ -10,18 +11,4 @@ export interface SharedOutputConfig extends BuilderSharedOutputConfig {
10
11
  }
11
12
  export interface OutputUserConfig extends BuilderOutputConfig, SharedOutputConfig {}
12
13
  export interface RsOutputUserConfig extends RsBuilderOutputConfig, SharedOutputConfig {}
13
- export type SSGRouteOptions = string | {
14
- url: string;
15
- output?: string;
16
- params?: Record<string, any>[];
17
- headers?: Record<string, any>;
18
- };
19
- export type SSGSingleEntryOptions = boolean | {
20
- preventDefault?: string[];
21
- headers?: Record<string, any>;
22
- routes?: SSGRouteOptions[];
23
- };
24
- export type SSGMultiEntryOptions = Record<string, SSGSingleEntryOptions>;
25
- export type SSGConfig = boolean | SSGSingleEntryOptions | SSGMultiEntryOptions | ((entryName: string, payload: {
26
- baseUrl?: string;
27
- }) => SSGSingleEntryOptions);
14
+ export type { SSGRouteOptions, SSGSingleEntryOptions, SSGMultiEntryOptions, SSGConfig } from '@modern-js/types';
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@modern-js/app-tools",
3
3
  "description": "A Progressive React Framework for modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
- "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
- "repository": "modern-js-dev/modern.js",
5
+ "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
+ "repository": "web-infra-dev/modern.js",
7
7
  "license": "MIT",
8
8
  "keywords": [
9
9
  "react",
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.7.0",
14
+ "version": "2.8.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -64,23 +64,23 @@
64
64
  "@babel/types": "^7.18.0",
65
65
  "es-module-lexer": "^1.1.0",
66
66
  "esbuild": "0.15.7",
67
- "@modern-js/builder": "2.7.0",
68
- "@modern-js/builder-plugin-esbuild": "2.7.0",
69
- "@modern-js/builder-plugin-node-polyfill": "2.7.0",
70
- "@modern-js/builder-shared": "2.7.0",
71
- "@modern-js/builder-webpack-provider": "2.7.0",
72
- "@modern-js/core": "2.7.0",
73
- "@modern-js/new-action": "2.7.0",
74
- "@modern-js/node-bundle-require": "2.7.0",
75
- "@modern-js/plugin": "2.7.0",
76
- "@modern-js/plugin-data-loader": "2.7.0",
77
- "@modern-js/plugin-i18n": "2.7.0",
78
- "@modern-js/plugin-lint": "2.7.0",
79
- "@modern-js/prod-server": "2.7.0",
80
- "@modern-js/server": "2.7.0",
81
- "@modern-js/types": "2.7.0",
82
- "@modern-js/upgrade": "2.7.0",
83
- "@modern-js/utils": "2.7.0"
67
+ "@modern-js/builder": "2.8.0",
68
+ "@modern-js/builder-plugin-esbuild": "2.8.0",
69
+ "@modern-js/builder-plugin-node-polyfill": "2.8.0",
70
+ "@modern-js/builder-shared": "2.8.0",
71
+ "@modern-js/builder-webpack-provider": "2.8.0",
72
+ "@modern-js/core": "2.8.0",
73
+ "@modern-js/new-action": "2.8.0",
74
+ "@modern-js/node-bundle-require": "2.8.0",
75
+ "@modern-js/plugin": "2.8.0",
76
+ "@modern-js/plugin-data-loader": "2.8.0",
77
+ "@modern-js/plugin-i18n": "2.8.0",
78
+ "@modern-js/plugin-lint": "2.8.0",
79
+ "@modern-js/prod-server": "2.8.0",
80
+ "@modern-js/server": "2.8.0",
81
+ "@modern-js/types": "2.8.0",
82
+ "@modern-js/upgrade": "2.8.0",
83
+ "@modern-js/utils": "2.8.0"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@types/babel__traverse": "^7.14.2",
@@ -89,14 +89,14 @@
89
89
  "jest": "^27",
90
90
  "typescript": "^4",
91
91
  "webpack": "^5.75.0",
92
- "@modern-js/builder-plugin-swc": "2.7.0",
93
- "@modern-js/builder-rspack-provider": "2.7.0",
94
- "@modern-js/server-core": "2.7.0",
95
- "@scripts/jest-config": "2.7.0",
96
- "@scripts/build": "2.7.0"
92
+ "@modern-js/builder-plugin-swc": "2.8.0",
93
+ "@modern-js/builder-rspack-provider": "2.8.0",
94
+ "@modern-js/server-core": "2.8.0",
95
+ "@scripts/jest-config": "2.8.0",
96
+ "@scripts/build": "2.8.0"
97
97
  },
98
98
  "peerDependencies": {
99
- "@modern-js/builder-rspack-provider": "^2.7.0"
99
+ "@modern-js/builder-rspack-provider": "^2.8.0"
100
100
  },
101
101
  "peerDependenciesMeta": {
102
102
  "@modern-js/builder-rspack-provider": {