@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
|
@@ -13,52 +13,50 @@ const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
|
13
13
|
const _fsextra = /* @__PURE__ */ _interop_require_default._(require("@modern-js/utils/fs-extra"));
|
|
14
14
|
const _utils = require("@modern-js/utils");
|
|
15
15
|
const _shared = require("../shared");
|
|
16
|
-
const builderPluginAdpaterCopy = (options) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
config.builtins
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
|
|
33
|
-
});
|
|
34
|
-
api.onDevCompileDone(async () => {
|
|
35
|
-
await transformHtmlFiles();
|
|
36
|
-
});
|
|
37
|
-
api.onAfterBuild(async () => {
|
|
38
|
-
await transformHtmlFiles();
|
|
39
|
-
});
|
|
40
|
-
async function transformHtmlFiles() {
|
|
41
|
-
var _normalizedConfig_output_distPath;
|
|
42
|
-
const { normalizedConfig } = options;
|
|
43
|
-
const publicDir = _path.default.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
|
|
44
|
-
if (!_fsextra.default.existsSync(publicDir) || !_fsextra.default.statSync(publicDir).isDirectory()) {
|
|
45
|
-
return;
|
|
16
|
+
const builderPluginAdpaterCopy = (options) => ({
|
|
17
|
+
name: "builder-plugin-adapter-rspack-copy",
|
|
18
|
+
setup(api) {
|
|
19
|
+
let publicPath;
|
|
20
|
+
api.modifyRspackConfig((config) => {
|
|
21
|
+
var _config_builtins_copy, _config_builtins, _config_output;
|
|
22
|
+
config.builtins = {
|
|
23
|
+
...config.builtins || {},
|
|
24
|
+
copy: {
|
|
25
|
+
patterns: [
|
|
26
|
+
...((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns) || [],
|
|
27
|
+
...createConfigBuiltinCopy(options)
|
|
28
|
+
]
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
30
|
+
};
|
|
31
|
+
publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
|
|
32
|
+
});
|
|
33
|
+
api.onDevCompileDone(async () => {
|
|
34
|
+
await transformHtmlFiles();
|
|
35
|
+
});
|
|
36
|
+
api.onAfterBuild(async () => {
|
|
37
|
+
await transformHtmlFiles();
|
|
38
|
+
});
|
|
39
|
+
async function transformHtmlFiles() {
|
|
40
|
+
var _normalizedConfig_output_distPath;
|
|
41
|
+
const { normalizedConfig } = options;
|
|
42
|
+
const publicDir = _path.default.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
|
|
43
|
+
if (!_fsextra.default.existsSync(publicDir) || !_fsextra.default.statSync(publicDir).isDirectory()) {
|
|
44
|
+
return;
|
|
58
45
|
}
|
|
46
|
+
const HTML_REGEXP = /\.html?$/;
|
|
47
|
+
const filepaths = (await _fsextra.default.readdir(publicDir)).map((file) => _path.default.resolve(publicDir, file));
|
|
48
|
+
await Promise.all(filepaths.filter((file) => HTML_REGEXP.test(file)).map(async (file) => {
|
|
49
|
+
const content = await _fsextra.default.readFile(file, "utf-8");
|
|
50
|
+
if (publicPath) {
|
|
51
|
+
await _fsextra.default.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, (0, _utils.removeTailSlash)(publicPath)));
|
|
52
|
+
} else {
|
|
53
|
+
_utils.logger.warn("Expect get a string from `publicPath`, but receive `undefined`.");
|
|
54
|
+
await _fsextra.default.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, (0, _utils.removeTailSlash)("/")));
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
59
57
|
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
62
60
|
function createConfigBuiltinCopy(options) {
|
|
63
61
|
const { normalizedConfig, appContext } = options;
|
|
64
62
|
const { publicDir } = (0, _shared.createCopyInfo)(appContext, normalizedConfig);
|
|
@@ -10,28 +10,26 @@ Object.defineProperty(exports, "builderPluginAdapterModern", {
|
|
|
10
10
|
});
|
|
11
11
|
const _path = require("path");
|
|
12
12
|
const _createCopyPattern = require("./createCopyPattern");
|
|
13
|
-
const builderPluginAdapterModern = (options) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
};
|
|
13
|
+
const builderPluginAdapterModern = (options) => ({
|
|
14
|
+
name: "builder-plugin-adapter-modern",
|
|
15
|
+
setup(api) {
|
|
16
|
+
const { normalizedConfig: modernConfig, appContext } = options;
|
|
17
|
+
api.modifyWebpackChain((chain, { CHAIN_ID }) => {
|
|
18
|
+
chain.resolve.modules.add("node_modules").add((0, _path.join)(api.context.rootPath, "node_modules"));
|
|
19
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
20
|
+
const defaultCopyPattern = (0, _createCopyPattern.createPublicPattern)(appContext, modernConfig, chain);
|
|
21
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
22
|
+
var _args_;
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
patterns: [
|
|
26
|
+
...((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || [],
|
|
27
|
+
defaultCopyPattern
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -10,9 +10,10 @@ Object.defineProperty(exports, "createBuilderProviderConfig", {
|
|
|
10
10
|
});
|
|
11
11
|
const _createCopyPattern = require("../builder-webpack/createCopyPattern");
|
|
12
12
|
function modifyOutputConfig(config, appContext) {
|
|
13
|
+
var _copy;
|
|
13
14
|
const defaultCopyPattern = (0, _createCopyPattern.createUploadPattern)(appContext, config);
|
|
14
15
|
const { copy } = config.output;
|
|
15
|
-
const copyOptions = Array.isArray(copy) ? copy : copy === null ||
|
|
16
|
+
const copyOptions = Array.isArray(copy) ? copy : (_copy = copy) === null || _copy === void 0 ? void 0 : _copy.patterns;
|
|
16
17
|
const builderCopy = [
|
|
17
18
|
...copyOptions || [],
|
|
18
19
|
defaultCopyPattern
|
|
@@ -58,12 +58,13 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
const isStreamingSSR = (userConfig) => {
|
|
61
|
+
var _server;
|
|
61
62
|
const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
62
63
|
const { server } = userConfig;
|
|
63
64
|
if (isStreaming(server.ssr)) {
|
|
64
65
|
return true;
|
|
65
66
|
}
|
|
66
|
-
if ((server === null ||
|
|
67
|
+
if (((_server = server) === null || _server === void 0 ? void 0 : _server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
67
68
|
for (const name of Object.keys(server.ssrByEntries)) {
|
|
68
69
|
if (isStreaming(server.ssrByEntries[name])) {
|
|
69
70
|
return true;
|
|
@@ -80,38 +81,33 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
function applyRouterPlugin(chain, options) {
|
|
83
|
-
var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
|
|
84
|
+
var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
|
|
84
85
|
const { appContext, normalizedConfig } = options;
|
|
85
86
|
const { entrypoints } = appContext;
|
|
86
87
|
const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
|
|
87
|
-
const routerConfig = normalizedConfig === null ||
|
|
88
|
-
const routerManifest = Boolean(routerConfig === null ||
|
|
88
|
+
const routerConfig = (_normalizedConfig = normalizedConfig) === null || _normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = _normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
|
89
|
+
const routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
|
|
89
90
|
const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
|
90
|
-
const minimize = !normalizedConfig.output.disableMinimize && process.env.NODE_ENV === "production";
|
|
91
91
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
|
92
|
-
chain.plugin("route-plugin").use(_bundlerPlugins.RouterPlugin
|
|
93
|
-
{
|
|
94
|
-
minimize
|
|
95
|
-
}
|
|
96
|
-
]);
|
|
92
|
+
chain.plugin("route-plugin").use(_bundlerPlugins.RouterPlugin);
|
|
97
93
|
}
|
|
98
94
|
}
|
|
99
95
|
function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
100
|
-
var
|
|
96
|
+
var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
|
|
101
97
|
const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
|
|
102
98
|
const entries = chain.entryPoints.entries();
|
|
103
|
-
if (isProd && ((outputConfig === null ||
|
|
99
|
+
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")) {
|
|
104
100
|
return;
|
|
105
101
|
}
|
|
106
102
|
if (typeof entries === "undefined") {
|
|
107
103
|
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
|
108
104
|
}
|
|
109
105
|
const entryNames = Object.keys(entries);
|
|
110
|
-
if (isProd && entryNames.length === 1 && (outputConfig === null ||
|
|
106
|
+
if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
|
|
111
107
|
return;
|
|
112
108
|
}
|
|
113
109
|
const ssgEntries = [];
|
|
114
|
-
if (isProd && (outputConfig === null ||
|
|
110
|
+
if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
|
|
115
111
|
const { ssg } = outputConfig;
|
|
116
112
|
entryNames.forEach((name) => {
|
|
117
113
|
if (ssg[name]) {
|
|
@@ -121,7 +117,8 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
|
121
117
|
}
|
|
122
118
|
const { ssr, ssrByEntries } = serverConfig || {};
|
|
123
119
|
entryNames.forEach((name) => {
|
|
124
|
-
|
|
120
|
+
var _ssrByEntries, _ssrByEntries1;
|
|
121
|
+
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]))) {
|
|
125
122
|
chain.entryPoints.delete(name);
|
|
126
123
|
}
|
|
127
124
|
});
|
|
@@ -8,7 +8,6 @@ Object.defineProperty(exports, "RouterPlugin", {
|
|
|
8
8
|
return RouterPlugin;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
const _define_property = require("@swc/helpers/_/_define_property");
|
|
12
11
|
const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
|
|
13
12
|
const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
14
13
|
const _lodash = require("@modern-js/utils/lodash");
|
|
@@ -26,22 +25,6 @@ class RouterPlugin {
|
|
|
26
25
|
}
|
|
27
26
|
return false;
|
|
28
27
|
}
|
|
29
|
-
getEntryChunks(compilation, chunks) {
|
|
30
|
-
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
31
|
-
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
32
|
-
const entryChunks = [
|
|
33
|
-
...chunks
|
|
34
|
-
].filter((chunk) => {
|
|
35
|
-
var _chunk_names;
|
|
36
|
-
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
37
|
-
});
|
|
38
|
-
return entryChunks;
|
|
39
|
-
}
|
|
40
|
-
getEntryChunkFiles(entryChunks) {
|
|
41
|
-
return entryChunks.map((chunk) => [
|
|
42
|
-
...chunk.files || []
|
|
43
|
-
].find((fname) => fname.includes(".js")));
|
|
44
|
-
}
|
|
45
28
|
apply(compiler) {
|
|
46
29
|
const { target } = compiler.options;
|
|
47
30
|
if (this.isTargetNodeOrWebWorker(target)) {
|
|
@@ -56,8 +39,7 @@ class RouterPlugin {
|
|
|
56
39
|
}
|
|
57
40
|
return path;
|
|
58
41
|
};
|
|
59
|
-
const
|
|
60
|
-
const chunkToMap = /* @__PURE__ */ new Map();
|
|
42
|
+
const chunkToSourceAndMap = /* @__PURE__ */ new Map();
|
|
61
43
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
62
44
|
compilation.hooks.processAssets.tapPromise({
|
|
63
45
|
name: PLUGIN_NAME,
|
|
@@ -73,37 +55,14 @@ class RouterPlugin {
|
|
|
73
55
|
if (!namedChunkGroups) {
|
|
74
56
|
return;
|
|
75
57
|
}
|
|
76
|
-
const
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const chunkId = entryChunkFileIds[i];
|
|
84
|
-
const asset = compilation.assets[file];
|
|
85
|
-
if (!asset) {
|
|
86
|
-
continue;
|
|
87
|
-
}
|
|
88
|
-
const { map } = asset.sourceAndMap();
|
|
89
|
-
chunkToMap.set(chunkId, map);
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
compilation.hooks.processAssets.tapPromise({
|
|
93
|
-
name: PLUGIN_NAME,
|
|
94
|
-
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
|
|
95
|
-
}, async () => {
|
|
96
|
-
const stats = compilation.getStats().toJson({
|
|
97
|
-
all: false,
|
|
98
|
-
chunkGroups: true,
|
|
99
|
-
chunks: true,
|
|
100
|
-
ids: true
|
|
58
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
59
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
60
|
+
const entryChunks = [
|
|
61
|
+
...chunks
|
|
62
|
+
].filter((chunk) => {
|
|
63
|
+
var _chunk_names;
|
|
64
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
101
65
|
});
|
|
102
|
-
const { chunks = [], namedChunkGroups } = stats;
|
|
103
|
-
if (!namedChunkGroups) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const entryChunks = this.getEntryChunks(compilation, chunks);
|
|
107
66
|
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
108
67
|
...chunk.files || []
|
|
109
68
|
].find((fname) => fname.includes(".js")));
|
|
@@ -115,8 +74,11 @@ class RouterPlugin {
|
|
|
115
74
|
if (!asset) {
|
|
116
75
|
continue;
|
|
117
76
|
}
|
|
118
|
-
const { source } = asset.sourceAndMap();
|
|
119
|
-
|
|
77
|
+
const { source, map } = asset.sourceAndMap();
|
|
78
|
+
chunkToSourceAndMap.set(chunkId, {
|
|
79
|
+
source,
|
|
80
|
+
map
|
|
81
|
+
});
|
|
120
82
|
}
|
|
121
83
|
});
|
|
122
84
|
compilation.hooks.processAssets.tapPromise({
|
|
@@ -149,7 +111,6 @@ class RouterPlugin {
|
|
|
149
111
|
const referenceCssAssets = assets.filter((asset) => /\.css$/.test(asset));
|
|
150
112
|
routeAssets[name] = {
|
|
151
113
|
chunkIds: chunkGroup.chunks,
|
|
152
|
-
chunkName: chunkGroup.name,
|
|
153
114
|
assets,
|
|
154
115
|
referenceCssAssets
|
|
155
116
|
};
|
|
@@ -165,29 +126,31 @@ class RouterPlugin {
|
|
|
165
126
|
const manifest = {
|
|
166
127
|
routeAssets
|
|
167
128
|
};
|
|
168
|
-
const
|
|
169
|
-
const
|
|
129
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
130
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
131
|
+
const entryChunks = [
|
|
132
|
+
...chunks
|
|
133
|
+
].filter((chunk) => {
|
|
134
|
+
var _chunk_names;
|
|
135
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
136
|
+
});
|
|
137
|
+
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
138
|
+
...chunk.files || []
|
|
139
|
+
].find((fname) => fname.includes(".js")));
|
|
170
140
|
const entryChunkFileIds = entryChunks.map((chunk) => chunk.id);
|
|
171
|
-
for (let i = 0; i
|
|
141
|
+
for (let i = 0; i <= entryChunkFiles.length - 1; i++) {
|
|
172
142
|
const file = entryChunkFiles[i];
|
|
173
|
-
const chunkNames = entryChunks[i].names;
|
|
174
143
|
const chunkId = entryChunkFileIds[i];
|
|
175
144
|
const asset = compilation.assets[file];
|
|
176
145
|
if (!asset || !chunkId) {
|
|
177
146
|
continue;
|
|
178
147
|
}
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
relatedAssets[routeId] = routeAssets[routeId];
|
|
186
|
-
}
|
|
187
|
-
});
|
|
188
|
-
} else {
|
|
189
|
-
relatedAssets = routeAssets;
|
|
190
|
-
}
|
|
148
|
+
const relatedAssets = {};
|
|
149
|
+
Object.keys(routeAssets).forEach((routeId) => {
|
|
150
|
+
if (routeId.startsWith(`${chunkId}`)) {
|
|
151
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
|
152
|
+
}
|
|
153
|
+
});
|
|
191
154
|
const manifest2 = {
|
|
192
155
|
routeAssets: relatedAssets
|
|
193
156
|
};
|
|
@@ -203,13 +166,12 @@ class RouterPlugin {
|
|
|
203
166
|
})};
|
|
204
167
|
})();
|
|
205
168
|
`;
|
|
206
|
-
const source =
|
|
207
|
-
const map = chunkToMap.get(chunkId);
|
|
169
|
+
const { source, map } = chunkToSourceAndMap.get(chunkId);
|
|
208
170
|
const newContent = `${injectedContent}${source.toString()}`;
|
|
209
171
|
const result = await (0, _esbuild.transform)(newContent, {
|
|
210
172
|
loader: _path.default.extname(file).slice(1),
|
|
211
173
|
sourcemap: true,
|
|
212
|
-
minify:
|
|
174
|
+
minify: process.env.NODE_ENV === "production"
|
|
213
175
|
});
|
|
214
176
|
const newSource = new SourceMapSource(result.code, file, result.map, source.toString(), map);
|
|
215
177
|
compilation.updateAsset(
|
|
@@ -232,8 +194,4 @@ class RouterPlugin {
|
|
|
232
194
|
});
|
|
233
195
|
});
|
|
234
196
|
}
|
|
235
|
-
constructor(options) {
|
|
236
|
-
_define_property._(this, "minimize", false);
|
|
237
|
-
this.minimize = options.minimize;
|
|
238
|
-
}
|
|
239
197
|
}
|
|
@@ -13,7 +13,8 @@ const _utils = require("@modern-js/utils");
|
|
|
13
13
|
const _routes = require("../utils/routes");
|
|
14
14
|
const _config = require("../utils/config");
|
|
15
15
|
const build = async (api, options) => {
|
|
16
|
-
|
|
16
|
+
var _options;
|
|
17
|
+
if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
|
|
17
18
|
process.env.BUNDLE_ANALYZE = "true";
|
|
18
19
|
}
|
|
19
20
|
let resolvedConfig = api.useResolvedConfigContext();
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "inspect", {
|
|
|
10
10
|
});
|
|
11
11
|
const _path = require("path");
|
|
12
12
|
const inspect = async (api, options) => {
|
|
13
|
+
var _appContext;
|
|
13
14
|
const appContext = api.useAppContext();
|
|
14
15
|
if (!appContext.builder) {
|
|
15
16
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
@@ -17,7 +18,7 @@ const inspect = async (api, options) => {
|
|
|
17
18
|
return appContext.builder.inspectConfig({
|
|
18
19
|
env: options.env,
|
|
19
20
|
verbose: options.verbose,
|
|
20
|
-
outputPath: (0, _path.join)(appContext === null ||
|
|
21
|
+
outputPath: (0, _path.join)((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.builder.context.distPath, options.output),
|
|
21
22
|
writeToDisk: true
|
|
22
23
|
});
|
|
23
24
|
};
|
|
@@ -15,13 +15,13 @@ const _printInstructions = require("../utils/printInstructions");
|
|
|
15
15
|
const _createServer = require("../utils/createServer");
|
|
16
16
|
const _getServerInternalPlugins = require("../utils/getServerInternalPlugins");
|
|
17
17
|
const start = async (api) => {
|
|
18
|
-
var _userConfig_source, _userConfig_output_distPath;
|
|
18
|
+
var _userConfig_source, _userConfig, _userConfig_output_distPath;
|
|
19
19
|
const appContext = api.useAppContext();
|
|
20
20
|
const userConfig = api.useResolvedConfigContext();
|
|
21
21
|
const hookRunners = api.useHookRunners();
|
|
22
22
|
const { appDirectory, port, serverConfigFile, metaName } = appContext;
|
|
23
23
|
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
|
24
|
-
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, userConfig === null ||
|
|
24
|
+
const apiOnly = await (0, _utils.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);
|
|
25
25
|
const serverInternalPlugins = await (0, _getServerInternalPlugins.getServerInternalPlugins)(api);
|
|
26
26
|
const app = await (0, _prodserver.default)({
|
|
27
27
|
pwd: appDirectory,
|
package/dist/cjs/index.js
CHANGED
|
@@ -94,6 +94,7 @@ const buildCommand = async (program, api) => {
|
|
|
94
94
|
const appTools = (options = {
|
|
95
95
|
bundler: "webpack"
|
|
96
96
|
}) => {
|
|
97
|
+
var _options, _options1;
|
|
97
98
|
return {
|
|
98
99
|
name: "@modern-js/app-tools",
|
|
99
100
|
post: [
|
|
@@ -109,10 +110,10 @@ const appTools = (options = {
|
|
|
109
110
|
registerHook: _hooks.hooks,
|
|
110
111
|
usePlugins: [
|
|
111
112
|
(0, _initialize.default)({
|
|
112
|
-
bundler: (options === null ||
|
|
113
|
+
bundler: ((_options = options) === null || _options === void 0 ? void 0 : _options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
113
114
|
}),
|
|
114
115
|
(0, _analyze.default)({
|
|
115
|
-
bundler: (options === null ||
|
|
116
|
+
bundler: ((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
116
117
|
}),
|
|
117
118
|
(0, _pluginlint.lintPlugin)()
|
|
118
119
|
],
|
|
@@ -11,81 +11,79 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
const _utils = require("@modern-js/utils");
|
|
12
12
|
const _schema = require("../schema");
|
|
13
13
|
const _config = require("../config");
|
|
14
|
-
const _default = ({ bundler }) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
14
|
+
const _default = ({ bundler }) => ({
|
|
15
|
+
name: "@modern-js/plugin-initialize",
|
|
16
|
+
post: [
|
|
17
|
+
"@modern-js/plugin-ssr",
|
|
18
|
+
"@modern-js/plugin-document",
|
|
19
|
+
"@modern-js/plugin-state",
|
|
20
|
+
"@modern-js/plugin-router",
|
|
21
|
+
"@modern-js/plugin-router-v5",
|
|
22
|
+
"@modern-js/plugin-polyfill"
|
|
23
|
+
],
|
|
24
|
+
setup(api) {
|
|
25
|
+
const config = () => {
|
|
26
|
+
const appContext = api.useAppContext();
|
|
27
|
+
const userConfig = api.useConfigContext();
|
|
28
|
+
api.setAppContext({
|
|
29
|
+
...appContext,
|
|
30
|
+
bundlerType: bundler
|
|
31
|
+
});
|
|
32
|
+
return (0, _config.checkIsLegacyConfig)(userConfig) ? (0, _config.createLegacyDefaultConfig)(appContext) : (0, _config.createDefaultConfig)(appContext, bundler);
|
|
33
|
+
};
|
|
34
|
+
const validateSchema = () => {
|
|
35
|
+
const userConfig = api.useConfigContext();
|
|
36
|
+
const schemas = (0, _config.checkIsLegacyConfig)(userConfig) ? _schema.legacySchema : _schema.schema;
|
|
37
|
+
return schemas.generate();
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
config,
|
|
41
|
+
validateSchema,
|
|
42
|
+
async resolvedConfig({ resolved }) {
|
|
43
|
+
var _resolved_output_distPath;
|
|
44
|
+
let appContext = api.useAppContext();
|
|
28
45
|
const userConfig = api.useConfigContext();
|
|
29
|
-
|
|
46
|
+
const port = await getServerPort(resolved);
|
|
47
|
+
appContext = {
|
|
30
48
|
...appContext,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
|
62
|
-
stabilizeConfig(resolved, normalizedConfig, [
|
|
63
|
-
"source",
|
|
64
|
-
"bff",
|
|
65
|
-
"dev",
|
|
66
|
-
"html",
|
|
67
|
-
"output",
|
|
68
|
-
"tools",
|
|
69
|
-
"testing",
|
|
70
|
-
"plugins",
|
|
71
|
-
"builderPlugins",
|
|
72
|
-
"runtime",
|
|
73
|
-
"runtimeByEntries",
|
|
74
|
-
"deploy",
|
|
75
|
-
"performance"
|
|
76
|
-
]);
|
|
77
|
-
if (bundler === "webpack") {
|
|
78
|
-
resolved.security = normalizedConfig.security || {};
|
|
79
|
-
resolved.experiments = normalizedConfig.experiments;
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
resolved
|
|
83
|
-
};
|
|
49
|
+
port,
|
|
50
|
+
distDirectory: (0, _utils.ensureAbsolutePath)(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
|
51
|
+
};
|
|
52
|
+
api.setAppContext(appContext);
|
|
53
|
+
const normalizedConfig = (0, _config.checkIsLegacyConfig)(resolved) ? (0, _config.transformNormalizedConfig)(resolved) : resolved;
|
|
54
|
+
resolved._raw = userConfig;
|
|
55
|
+
resolved.server = {
|
|
56
|
+
...normalizedConfig.server || {},
|
|
57
|
+
port
|
|
58
|
+
};
|
|
59
|
+
var _normalizedConfig_autoLoadPlugins;
|
|
60
|
+
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
|
61
|
+
stabilizeConfig(resolved, normalizedConfig, [
|
|
62
|
+
"source",
|
|
63
|
+
"bff",
|
|
64
|
+
"dev",
|
|
65
|
+
"html",
|
|
66
|
+
"output",
|
|
67
|
+
"tools",
|
|
68
|
+
"testing",
|
|
69
|
+
"plugins",
|
|
70
|
+
"builderPlugins",
|
|
71
|
+
"runtime",
|
|
72
|
+
"runtimeByEntries",
|
|
73
|
+
"deploy",
|
|
74
|
+
"performance"
|
|
75
|
+
]);
|
|
76
|
+
if (bundler === "webpack") {
|
|
77
|
+
resolved.security = normalizedConfig.security || {};
|
|
78
|
+
resolved.experiments = normalizedConfig.experiments;
|
|
84
79
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
80
|
+
return {
|
|
81
|
+
resolved
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
89
87
|
function stabilizeConfig(resolve, config, keys) {
|
|
90
88
|
keys.forEach((key) => {
|
|
91
89
|
resolve[key] = config[key] || {};
|