@modern-js/app-tools 2.27.1-alpha.0 → 2.28.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.
- package/CHANGELOG.md +44 -0
- package/dist/cjs/analyze/generateCode.js +2 -2
- package/dist/cjs/analyze/getFileSystemEntry.js +2 -1
- package/dist/cjs/analyze/getServerRoutes.js +5 -4
- package/dist/cjs/analyze/index.js +209 -211
- package/dist/cjs/analyze/nestedRoutes.js +2 -2
- package/dist/cjs/analyze/templates.js +4 -4
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +41 -43
- package/dist/cjs/builder/builder-webpack/adapterModern.js +23 -25
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -15
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +33 -75
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/inspect.js +2 -1
- package/dist/cjs/commands/serve.js +2 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/initialize/index.js +70 -72
- package/dist/esm/analyze/generateCode.js +2 -2
- package/dist/esm/analyze/getFileSystemEntry.js +2 -1
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/analyze/nestedRoutes.js +2 -2
- package/dist/esm/analyze/templates.js +4 -4
- package/dist/esm/builder/builder-rspack/adapterCopy.js +1 -1
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +13 -16
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +41 -101
- package/dist/esm/commands/build.js +2 -2
- package/dist/esm/commands/inspect.js +2 -2
- package/dist/esm/commands/serve.js +2 -2
- package/dist/esm/index.js +3 -2
- package/dist/esm-node/analyze/generateCode.js +2 -2
- package/dist/esm-node/analyze/getFileSystemEntry.js +2 -1
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/analyze/index.js +209 -211
- package/dist/esm-node/analyze/nestedRoutes.js +2 -2
- package/dist/esm-node/analyze/templates.js +4 -4
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +41 -43
- package/dist/esm-node/builder/builder-webpack/adapterModern.js +23 -25
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -15
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +33 -75
- package/dist/esm-node/commands/build.js +2 -1
- package/dist/esm-node/commands/inspect.js +2 -1
- package/dist/esm-node/commands/serve.js +2 -2
- package/dist/esm-node/index.js +3 -2
- package/dist/esm-node/initialize/index.js +70 -72
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +0 -8
- package/package.json +24 -24
|
@@ -47,12 +47,13 @@ export const builderPluginAdapterSSR = (options) => ({
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
const isStreamingSSR = (userConfig) => {
|
|
50
|
+
var _server;
|
|
50
51
|
const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
51
52
|
const { server } = userConfig;
|
|
52
53
|
if (isStreaming(server.ssr)) {
|
|
53
54
|
return true;
|
|
54
55
|
}
|
|
55
|
-
if ((server === null ||
|
|
56
|
+
if (((_server = server) === null || _server === void 0 ? void 0 : _server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
56
57
|
for (const name of Object.keys(server.ssrByEntries)) {
|
|
57
58
|
if (isStreaming(server.ssrByEntries[name])) {
|
|
58
59
|
return true;
|
|
@@ -69,38 +70,33 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
|
|
|
69
70
|
}
|
|
70
71
|
}
|
|
71
72
|
function applyRouterPlugin(chain, options) {
|
|
72
|
-
var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
|
|
73
|
+
var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
|
|
73
74
|
const { appContext, normalizedConfig } = options;
|
|
74
75
|
const { entrypoints } = appContext;
|
|
75
76
|
const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
|
|
76
|
-
const routerConfig = normalizedConfig === null ||
|
|
77
|
-
const routerManifest = Boolean(routerConfig === null ||
|
|
77
|
+
const routerConfig = (_normalizedConfig = normalizedConfig) === null || _normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = _normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
|
78
|
+
const routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
|
|
78
79
|
const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
|
79
|
-
const minimize = !normalizedConfig.output.disableMinimize && process.env.NODE_ENV === "production";
|
|
80
80
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
|
81
|
-
chain.plugin("route-plugin").use(RouterPlugin
|
|
82
|
-
{
|
|
83
|
-
minimize
|
|
84
|
-
}
|
|
85
|
-
]);
|
|
81
|
+
chain.plugin("route-plugin").use(RouterPlugin);
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
89
|
-
var
|
|
85
|
+
var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
|
|
90
86
|
const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
|
|
91
87
|
const entries = chain.entryPoints.entries();
|
|
92
|
-
if (isProd && ((outputConfig === null ||
|
|
88
|
+
if (isProd && (((_outputConfig = outputConfig) === null || _outputConfig === void 0 ? void 0 : _outputConfig.ssg) === true || typeof ((_this = (_outputConfig1 = outputConfig) === null || _outputConfig1 === void 0 ? void 0 : _outputConfig1.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
|
|
93
89
|
return;
|
|
94
90
|
}
|
|
95
91
|
if (typeof entries === "undefined") {
|
|
96
92
|
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
|
97
93
|
}
|
|
98
94
|
const entryNames = Object.keys(entries);
|
|
99
|
-
if (isProd && entryNames.length === 1 && (outputConfig === null ||
|
|
95
|
+
if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
|
|
100
96
|
return;
|
|
101
97
|
}
|
|
102
98
|
const ssgEntries = [];
|
|
103
|
-
if (isProd && (outputConfig === null ||
|
|
99
|
+
if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
|
|
104
100
|
const { ssg } = outputConfig;
|
|
105
101
|
entryNames.forEach((name) => {
|
|
106
102
|
if (ssg[name]) {
|
|
@@ -110,7 +106,8 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
|
110
106
|
}
|
|
111
107
|
const { ssr, ssrByEntries } = serverConfig || {};
|
|
112
108
|
entryNames.forEach((name) => {
|
|
113
|
-
|
|
109
|
+
var _ssrByEntries, _ssrByEntries1;
|
|
110
|
+
if (!ssgEntries.includes(name) && (ssr && ((_ssrByEntries = ssrByEntries) === null || _ssrByEntries === void 0 ? void 0 : _ssrByEntries[name]) === false || !ssr && !((_ssrByEntries1 = ssrByEntries) === null || _ssrByEntries1 === void 0 ? void 0 : _ssrByEntries1[name]))) {
|
|
114
111
|
chain.entryPoints.delete(name);
|
|
115
112
|
}
|
|
116
113
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
|
2
1
|
import path from "path";
|
|
3
2
|
import { mergeWith } from "@modern-js/utils/lodash";
|
|
4
3
|
import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
|
|
@@ -15,22 +14,6 @@ export class RouterPlugin {
|
|
|
15
14
|
}
|
|
16
15
|
return false;
|
|
17
16
|
}
|
|
18
|
-
getEntryChunks(compilation, chunks) {
|
|
19
|
-
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
20
|
-
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
21
|
-
const entryChunks = [
|
|
22
|
-
...chunks
|
|
23
|
-
].filter((chunk) => {
|
|
24
|
-
var _chunk_names;
|
|
25
|
-
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
26
|
-
});
|
|
27
|
-
return entryChunks;
|
|
28
|
-
}
|
|
29
|
-
getEntryChunkFiles(entryChunks) {
|
|
30
|
-
return entryChunks.map((chunk) => [
|
|
31
|
-
...chunk.files || []
|
|
32
|
-
].find((fname) => fname.includes(".js")));
|
|
33
|
-
}
|
|
34
17
|
apply(compiler) {
|
|
35
18
|
const { target } = compiler.options;
|
|
36
19
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
@@ -45,8 +28,7 @@ export class RouterPlugin {
|
|
|
45
28
|
}
|
|
46
29
|
return path2;
|
|
47
30
|
};
|
|
48
|
-
const
|
|
49
|
-
const chunkToMap = /* @__PURE__ */ new Map();
|
|
31
|
+
const chunkToSourceAndMap = /* @__PURE__ */ new Map();
|
|
50
32
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
51
33
|
compilation.hooks.processAssets.tapPromise({
|
|
52
34
|
name: PLUGIN_NAME,
|
|
@@ -62,37 +44,14 @@ export class RouterPlugin {
|
|
|
62
44
|
if (!namedChunkGroups) {
|
|
63
45
|
return;
|
|
64
46
|
}
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const chunkId = entryChunkFileIds[i];
|
|
73
|
-
const asset = compilation.assets[file];
|
|
74
|
-
if (!asset) {
|
|
75
|
-
continue;
|
|
76
|
-
}
|
|
77
|
-
const { map } = asset.sourceAndMap();
|
|
78
|
-
chunkToMap.set(chunkId, map);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
compilation.hooks.processAssets.tapPromise({
|
|
82
|
-
name: PLUGIN_NAME,
|
|
83
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
84
|
-
}, async () => {
|
|
85
|
-
const stats = compilation.getStats().toJson({
|
|
86
|
-
all: false,
|
|
87
|
-
chunkGroups: true,
|
|
88
|
-
chunks: true,
|
|
89
|
-
ids: true
|
|
47
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
48
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
49
|
+
const entryChunks = [
|
|
50
|
+
...chunks
|
|
51
|
+
].filter((chunk) => {
|
|
52
|
+
var _chunk_names;
|
|
53
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
90
54
|
});
|
|
91
|
-
const { chunks = [], namedChunkGroups } = stats;
|
|
92
|
-
if (!namedChunkGroups) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
96
55
|
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
97
56
|
...chunk.files || []
|
|
98
57
|
].find((fname) => fname.includes(".js")));
|
|
@@ -104,8 +63,11 @@ export class RouterPlugin {
|
|
|
104
63
|
if (!asset) {
|
|
105
64
|
continue;
|
|
106
65
|
}
|
|
107
|
-
const { source } = asset.sourceAndMap();
|
|
108
|
-
|
|
66
|
+
const { source, map } = asset.sourceAndMap();
|
|
67
|
+
chunkToSourceAndMap.set(chunkId, {
|
|
68
|
+
source,
|
|
69
|
+
map
|
|
70
|
+
});
|
|
109
71
|
}
|
|
110
72
|
});
|
|
111
73
|
compilation.hooks.processAssets.tapPromise({
|
|
@@ -138,7 +100,6 @@ export class RouterPlugin {
|
|
|
138
100
|
const referenceCssAssets = assets.filter((asset) => /\.css$/.test(asset));
|
|
139
101
|
routeAssets[name] = {
|
|
140
102
|
chunkIds: chunkGroup.chunks,
|
|
141
|
-
chunkName: chunkGroup.name,
|
|
142
103
|
assets,
|
|
143
104
|
referenceCssAssets
|
|
144
105
|
};
|
|
@@ -154,29 +115,31 @@ export class RouterPlugin {
|
|
|
154
115
|
const manifest = {
|
|
155
116
|
routeAssets
|
|
156
117
|
};
|
|
157
|
-
const
|
|
158
|
-
const
|
|
118
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
119
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
120
|
+
const entryChunks = [
|
|
121
|
+
...chunks
|
|
122
|
+
].filter((chunk) => {
|
|
123
|
+
var _chunk_names;
|
|
124
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
125
|
+
});
|
|
126
|
+
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
127
|
+
...chunk.files || []
|
|
128
|
+
].find((fname) => fname.includes(".js")));
|
|
159
129
|
const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
|
|
160
|
-
for (let i = 0; i
|
|
130
|
+
for (let i = 0; i <= entryChunkFiles.length - 1; i++) {
|
|
161
131
|
const file = entryChunkFiles[i];
|
|
162
|
-
const chunkNames = entryChunks[i].names;
|
|
163
132
|
const chunkId = entryChunkFileIds[i];
|
|
164
133
|
const asset = compilation.assets[file];
|
|
165
134
|
if (!asset || !chunkId) {
|
|
166
135
|
continue;
|
|
167
136
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
relatedAssets[routeId] = routeAssets[routeId];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
} else {
|
|
178
|
-
relatedAssets = routeAssets;
|
|
179
|
-
}
|
|
137
|
+
const relatedAssets = {};
|
|
138
|
+
Object.keys(routeAssets).forEach((routeId) => {
|
|
139
|
+
if (routeId.startsWith(`${chunkId}`)) {
|
|
140
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
180
143
|
const manifest2 = {
|
|
181
144
|
routeAssets: relatedAssets
|
|
182
145
|
};
|
|
@@ -192,13 +155,12 @@ export class RouterPlugin {
|
|
|
192
155
|
})};
|
|
193
156
|
})();
|
|
194
157
|
`;
|
|
195
|
-
const source =
|
|
196
|
-
const map = chunkToMap.get(chunkId);
|
|
158
|
+
const { source, map } = chunkToSourceAndMap.get(chunkId);
|
|
197
159
|
const newContent = `${injectedContent}${source.toString()}`;
|
|
198
160
|
const result = await transform(newContent, {
|
|
199
161
|
loader: path.extname(file).slice(1),
|
|
200
162
|
sourcemap: true,
|
|
201
|
-
minify:
|
|
163
|
+
minify: process.env.NODE_ENV === "production"
|
|
202
164
|
});
|
|
203
165
|
const newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
|
|
204
166
|
compilation.updateAsset(
|
|
@@ -221,8 +183,4 @@ export class RouterPlugin {
|
|
|
221
183
|
});
|
|
222
184
|
});
|
|
223
185
|
}
|
|
224
|
-
constructor(options) {
|
|
225
|
-
_define_property(this, "minimize", false);
|
|
226
|
-
this.minimize = options.minimize;
|
|
227
|
-
}
|
|
228
186
|
}
|
|
@@ -3,7 +3,8 @@ import { logger } from "@modern-js/utils";
|
|
|
3
3
|
import { generateRoutes } from "../utils/routes";
|
|
4
4
|
import { buildServerConfig } from "../utils/config";
|
|
5
5
|
export const build = async (api, options) => {
|
|
6
|
-
|
|
6
|
+
var _options;
|
|
7
|
+
if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
|
|
7
8
|
process.env.BUNDLE_ANALYZE = "true";
|
|
8
9
|
}
|
|
9
10
|
let resolvedConfig = api.useResolvedConfigContext();
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
2
|
export const inspect = async (api, options) => {
|
|
3
|
+
var _appContext;
|
|
3
4
|
const appContext = api.useAppContext();
|
|
4
5
|
if (!appContext.builder) {
|
|
5
6
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
@@ -7,7 +8,7 @@ export const inspect = async (api, options) => {
|
|
|
7
8
|
return appContext.builder.inspectConfig({
|
|
8
9
|
env: options.env,
|
|
9
10
|
verbose: options.verbose,
|
|
10
|
-
outputPath: join(appContext === null ||
|
|
11
|
+
outputPath: join((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.builder.context.distPath, options.output),
|
|
11
12
|
writeToDisk: true
|
|
12
13
|
});
|
|
13
14
|
};
|
|
@@ -4,13 +4,13 @@ import { printInstructions } from "../utils/printInstructions";
|
|
|
4
4
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
5
5
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
6
6
|
export const start = async (api) => {
|
|
7
|
-
var _userConfig_source, _userConfig_output_distPath;
|
|
7
|
+
var _userConfig_source, _userConfig, _userConfig_output_distPath;
|
|
8
8
|
const appContext = api.useAppContext();
|
|
9
9
|
const userConfig = api.useResolvedConfigContext();
|
|
10
10
|
const hookRunners = api.useHookRunners();
|
|
11
11
|
const { appDirectory, port, serverConfigFile, metaName } = appContext;
|
|
12
12
|
logger.log(chalk.cyan(`Starting the modern server...`));
|
|
13
|
-
const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null ||
|
|
13
|
+
const apiOnly = await isApiOnly(appContext.appDirectory, (_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_source = _userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
|
|
14
14
|
const serverInternalPlugins = await getServerInternalPlugins(api);
|
|
15
15
|
const app = await server({
|
|
16
16
|
pwd: appDirectory,
|
package/dist/esm-node/index.js
CHANGED
|
@@ -60,6 +60,7 @@ export const buildCommand = async (program, api) => {
|
|
|
60
60
|
export const appTools = (options = {
|
|
61
61
|
bundler: "webpack"
|
|
62
62
|
}) => {
|
|
63
|
+
var _options, _options1;
|
|
63
64
|
return {
|
|
64
65
|
name: "@modern-js/app-tools",
|
|
65
66
|
post: [
|
|
@@ -75,10 +76,10 @@ export const appTools = (options = {
|
|
|
75
76
|
registerHook: hooks,
|
|
76
77
|
usePlugins: [
|
|
77
78
|
initializePlugin({
|
|
78
|
-
bundler: (options === null ||
|
|
79
|
+
bundler: ((_options = options) === null || _options === void 0 ? void 0 : _options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
79
80
|
}),
|
|
80
81
|
analyzePlugin({
|
|
81
|
-
bundler: (options === null ||
|
|
82
|
+
bundler: ((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
82
83
|
}),
|
|
83
84
|
lintPlugin()
|
|
84
85
|
],
|
|
@@ -1,81 +1,79 @@
|
|
|
1
1
|
import { ensureAbsolutePath, getPort, isDev, isDevCommand } from "@modern-js/utils";
|
|
2
2
|
import { legacySchema, schema } from "../schema";
|
|
3
3
|
import { checkIsLegacyConfig, createDefaultConfig, createLegacyDefaultConfig, transformNormalizedConfig } from "../config";
|
|
4
|
-
export default ({ bundler }) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
4
|
+
export default ({ bundler }) => ({
|
|
5
|
+
name: "@modern-js/plugin-initialize",
|
|
6
|
+
post: [
|
|
7
|
+
"@modern-js/plugin-ssr",
|
|
8
|
+
"@modern-js/plugin-document",
|
|
9
|
+
"@modern-js/plugin-state",
|
|
10
|
+
"@modern-js/plugin-router",
|
|
11
|
+
"@modern-js/plugin-router-v5",
|
|
12
|
+
"@modern-js/plugin-polyfill"
|
|
13
|
+
],
|
|
14
|
+
setup(api) {
|
|
15
|
+
const config = () => {
|
|
16
|
+
const appContext = api.useAppContext();
|
|
17
|
+
const userConfig = api.useConfigContext();
|
|
18
|
+
api.setAppContext({
|
|
19
|
+
...appContext,
|
|
20
|
+
bundlerType: bundler
|
|
21
|
+
});
|
|
22
|
+
return checkIsLegacyConfig(userConfig) ? createLegacyDefaultConfig(appContext) : createDefaultConfig(appContext, bundler);
|
|
23
|
+
};
|
|
24
|
+
const validateSchema = () => {
|
|
25
|
+
const userConfig = api.useConfigContext();
|
|
26
|
+
const schemas = checkIsLegacyConfig(userConfig) ? legacySchema : schema;
|
|
27
|
+
return schemas.generate();
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
config,
|
|
31
|
+
validateSchema,
|
|
32
|
+
async resolvedConfig({ resolved }) {
|
|
33
|
+
var _resolved_output_distPath;
|
|
34
|
+
let appContext = api.useAppContext();
|
|
18
35
|
const userConfig = api.useConfigContext();
|
|
19
|
-
|
|
36
|
+
const port = await getServerPort(resolved);
|
|
37
|
+
appContext = {
|
|
20
38
|
...appContext,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
|
52
|
-
stabilizeConfig(resolved, normalizedConfig, [
|
|
53
|
-
"source",
|
|
54
|
-
"bff",
|
|
55
|
-
"dev",
|
|
56
|
-
"html",
|
|
57
|
-
"output",
|
|
58
|
-
"tools",
|
|
59
|
-
"testing",
|
|
60
|
-
"plugins",
|
|
61
|
-
"builderPlugins",
|
|
62
|
-
"runtime",
|
|
63
|
-
"runtimeByEntries",
|
|
64
|
-
"deploy",
|
|
65
|
-
"performance"
|
|
66
|
-
]);
|
|
67
|
-
if (bundler === "webpack") {
|
|
68
|
-
resolved.security = normalizedConfig.security || {};
|
|
69
|
-
resolved.experiments = normalizedConfig.experiments;
|
|
70
|
-
}
|
|
71
|
-
return {
|
|
72
|
-
resolved
|
|
73
|
-
};
|
|
39
|
+
port,
|
|
40
|
+
distDirectory: ensureAbsolutePath(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
|
41
|
+
};
|
|
42
|
+
api.setAppContext(appContext);
|
|
43
|
+
const normalizedConfig = checkIsLegacyConfig(resolved) ? transformNormalizedConfig(resolved) : resolved;
|
|
44
|
+
resolved._raw = userConfig;
|
|
45
|
+
resolved.server = {
|
|
46
|
+
...normalizedConfig.server || {},
|
|
47
|
+
port
|
|
48
|
+
};
|
|
49
|
+
var _normalizedConfig_autoLoadPlugins;
|
|
50
|
+
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
|
51
|
+
stabilizeConfig(resolved, normalizedConfig, [
|
|
52
|
+
"source",
|
|
53
|
+
"bff",
|
|
54
|
+
"dev",
|
|
55
|
+
"html",
|
|
56
|
+
"output",
|
|
57
|
+
"tools",
|
|
58
|
+
"testing",
|
|
59
|
+
"plugins",
|
|
60
|
+
"builderPlugins",
|
|
61
|
+
"runtime",
|
|
62
|
+
"runtimeByEntries",
|
|
63
|
+
"deploy",
|
|
64
|
+
"performance"
|
|
65
|
+
]);
|
|
66
|
+
if (bundler === "webpack") {
|
|
67
|
+
resolved.security = normalizedConfig.security || {};
|
|
68
|
+
resolved.experiments = normalizedConfig.experiments;
|
|
74
69
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
70
|
+
return {
|
|
71
|
+
resolved
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
79
77
|
function stabilizeConfig(resolve, config, keys) {
|
|
80
78
|
keys.forEach((key) => {
|
|
81
79
|
resolve[key] = config[key] || {};
|
|
@@ -3,21 +3,13 @@ import type { Rspack } from '@modern-js/builder-rspack-provider';
|
|
|
3
3
|
export interface RouteAssets {
|
|
4
4
|
[routeId: string]: {
|
|
5
5
|
chunkIds?: (string | number)[];
|
|
6
|
-
chunkName: string;
|
|
7
6
|
assets?: string[];
|
|
8
7
|
referenceCssAssets?: string[];
|
|
9
8
|
};
|
|
10
9
|
}
|
|
11
10
|
type Compiler = webpack.Compiler | Rspack.Compiler;
|
|
12
|
-
type Options = {
|
|
13
|
-
minimize: boolean;
|
|
14
|
-
};
|
|
15
11
|
export declare class RouterPlugin {
|
|
16
|
-
private minimize;
|
|
17
|
-
constructor(options: Options);
|
|
18
12
|
private isTargetNodeOrWebWorker;
|
|
19
|
-
private getEntryChunks;
|
|
20
|
-
private getEntryChunkFiles;
|
|
21
13
|
apply(compiler: Compiler): void;
|
|
22
14
|
}
|
|
23
15
|
export {};
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.28.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -73,24 +73,24 @@
|
|
|
73
73
|
"esbuild": "0.17.19",
|
|
74
74
|
"rspack-plugin-virtual-module": "0.1.0",
|
|
75
75
|
"@swc/helpers": "0.5.1",
|
|
76
|
-
"@modern-js/builder": "2.
|
|
77
|
-
"@modern-js/builder-
|
|
78
|
-
"@modern-js/builder-plugin-
|
|
79
|
-
"@modern-js/
|
|
80
|
-
"@modern-js/
|
|
81
|
-
"@modern-js/
|
|
82
|
-
"@modern-js/
|
|
83
|
-
"@modern-js/
|
|
84
|
-
"@modern-js/plugin
|
|
85
|
-
"@modern-js/
|
|
86
|
-
"@modern-js/plugin-
|
|
87
|
-
"@modern-js/plugin": "2.
|
|
88
|
-
"@modern-js/server": "2.
|
|
89
|
-
"@modern-js/
|
|
90
|
-
"@modern-js/
|
|
91
|
-
"@modern-js/
|
|
92
|
-
"@modern-js/
|
|
93
|
-
"@modern-js/
|
|
76
|
+
"@modern-js/builder": "2.28.0",
|
|
77
|
+
"@modern-js/builder-plugin-esbuild": "2.28.0",
|
|
78
|
+
"@modern-js/builder-plugin-node-polyfill": "2.28.0",
|
|
79
|
+
"@modern-js/builder-shared": "2.28.0",
|
|
80
|
+
"@modern-js/builder-webpack-provider": "2.28.0",
|
|
81
|
+
"@modern-js/core": "2.28.0",
|
|
82
|
+
"@modern-js/new-action": "2.28.0",
|
|
83
|
+
"@modern-js/node-bundle-require": "2.28.0",
|
|
84
|
+
"@modern-js/plugin": "2.28.0",
|
|
85
|
+
"@modern-js/plugin-data-loader": "2.28.0",
|
|
86
|
+
"@modern-js/plugin-i18n": "2.28.0",
|
|
87
|
+
"@modern-js/plugin-lint": "2.28.0",
|
|
88
|
+
"@modern-js/prod-server": "2.28.0",
|
|
89
|
+
"@modern-js/server": "2.28.0",
|
|
90
|
+
"@modern-js/types": "2.28.0",
|
|
91
|
+
"@modern-js/upgrade": "2.28.0",
|
|
92
|
+
"@modern-js/utils": "2.28.0",
|
|
93
|
+
"@modern-js/server-core": "2.28.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@types/babel__traverse": "^7.14.2",
|
|
@@ -99,13 +99,13 @@
|
|
|
99
99
|
"jest": "^29",
|
|
100
100
|
"typescript": "^5",
|
|
101
101
|
"webpack": "^5.88.1",
|
|
102
|
-
"@modern-js/builder-
|
|
103
|
-
"@modern-js/builder-
|
|
104
|
-
"@scripts/
|
|
105
|
-
"@scripts/
|
|
102
|
+
"@modern-js/builder-plugin-swc": "2.28.0",
|
|
103
|
+
"@modern-js/builder-rspack-provider": "2.28.0",
|
|
104
|
+
"@scripts/build": "2.28.0",
|
|
105
|
+
"@scripts/jest-config": "2.28.0"
|
|
106
106
|
},
|
|
107
107
|
"peerDependencies": {
|
|
108
|
-
"@modern-js/builder-rspack-provider": "^2.
|
|
108
|
+
"@modern-js/builder-rspack-provider": "^2.28.0"
|
|
109
109
|
},
|
|
110
110
|
"peerDependenciesMeta": {
|
|
111
111
|
"@modern-js/builder-rspack-provider": {
|