@modern-js/app-tools 2.15.0 → 2.16.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 +45 -0
- package/dist/cjs/analyze/constants.js +37 -61
- package/dist/cjs/analyze/generateCode.js +102 -127
- package/dist/cjs/analyze/getBundleEntry.js +33 -66
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +61 -117
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +61 -115
- package/dist/cjs/analyze/getClientRoutes/index.js +15 -28
- package/dist/cjs/analyze/getClientRoutes/utils.js +24 -48
- package/dist/cjs/analyze/getFileSystemEntry.js +39 -79
- package/dist/cjs/analyze/getHtmlTemplate.js +88 -98
- package/dist/cjs/analyze/getServerRoutes.js +67 -110
- package/dist/cjs/analyze/index.js +265 -257
- package/dist/cjs/analyze/isDefaultExportFunction.js +66 -44
- package/dist/cjs/analyze/makeLegalIdentifier.js +7 -25
- package/dist/cjs/analyze/nestedRoutes.js +99 -104
- package/dist/cjs/analyze/templates.js +49 -110
- package/dist/cjs/analyze/utils.js +98 -102
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +58 -100
- package/dist/cjs/builder/builder-rspack/index.js +14 -30
- package/dist/cjs/builder/builder-webpack/adapterModern.js +33 -50
- package/dist/cjs/builder/builder-webpack/createCopyPattern.js +16 -32
- package/dist/cjs/builder/builder-webpack/index.js +65 -46
- package/dist/cjs/builder/generator/createBuilderOptions.js +10 -26
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +11 -27
- package/dist/cjs/builder/generator/getBuilderTargets.js +13 -29
- package/dist/cjs/builder/generator/index.js +61 -55
- package/dist/cjs/builder/index.js +53 -43
- package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +13 -36
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +90 -90
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +108 -111
- package/dist/cjs/builder/shared/builderPlugins/index.js +20 -19
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -30
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +32 -38
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +86 -116
- package/dist/cjs/builder/shared/bundlerPlugins/index.js +20 -19
- package/dist/cjs/builder/shared/createCopyInfo.js +16 -42
- package/dist/cjs/builder/shared/index.js +20 -19
- package/dist/cjs/builder/shared/loaders/serverModuleLoader.js +8 -24
- package/dist/cjs/builder/shared/types.js +4 -15
- package/dist/cjs/commands/build.js +23 -40
- package/dist/cjs/commands/deploy.js +7 -25
- package/dist/cjs/commands/dev.js +38 -57
- package/dist/cjs/commands/index.js +20 -19
- package/dist/cjs/commands/inspect.js +10 -30
- package/dist/cjs/commands/serve.js +28 -66
- package/dist/cjs/config/default.js +34 -34
- package/dist/cjs/config/index.js +20 -19
- package/dist/cjs/config/initialize/index.js +11 -29
- package/dist/cjs/config/initialize/inits.js +103 -82
- package/dist/cjs/config/legacy/createHtmlConfig.js +8 -40
- package/dist/cjs/config/legacy/createOutputConfig.js +8 -51
- package/dist/cjs/config/legacy/createSourceConfig.js +8 -38
- package/dist/cjs/config/legacy/createToolsConfig.js +8 -43
- package/dist/cjs/config/legacy/index.js +22 -46
- package/dist/cjs/defineConfig.js +16 -31
- package/dist/cjs/exports/server.js +7 -25
- package/dist/cjs/hooks.js +33 -51
- package/dist/cjs/index.js +185 -166
- package/dist/cjs/initialize/index.js +84 -100
- package/dist/cjs/locale/en.js +13 -27
- package/dist/cjs/locale/index.js +18 -28
- package/dist/cjs/locale/zh.js +13 -27
- package/dist/cjs/schema/Schema.js +27 -31
- package/dist/cjs/schema/index.js +141 -71
- package/dist/cjs/schema/legacy.js +273 -96
- package/dist/cjs/types/config/deploy.js +4 -15
- package/dist/cjs/types/config/dev.js +4 -15
- package/dist/cjs/types/config/experiments.js +4 -15
- package/dist/cjs/types/config/html.js +4 -15
- package/dist/cjs/types/config/index.js +18 -17
- package/dist/cjs/types/config/output.js +4 -15
- package/dist/cjs/types/config/performance.js +4 -15
- package/dist/cjs/types/config/security.js +4 -15
- package/dist/cjs/types/config/source.js +4 -15
- package/dist/cjs/types/config/tools.js +4 -15
- package/dist/cjs/types/hooks.js +4 -15
- package/dist/cjs/types/index.js +20 -19
- package/dist/cjs/types/legacyConfig/deploy.js +4 -15
- package/dist/cjs/types/legacyConfig/dev.js +4 -15
- package/dist/cjs/types/legacyConfig/index.js +4 -15
- package/dist/cjs/types/legacyConfig/output.js +4 -15
- package/dist/cjs/types/legacyConfig/source.js +4 -15
- package/dist/cjs/types/legacyConfig/tools.js +4 -15
- package/dist/cjs/types/utils.js +4 -15
- package/dist/cjs/utils/config.js +74 -79
- package/dist/cjs/utils/createServer.js +16 -42
- package/dist/cjs/utils/env.js +7 -25
- package/dist/cjs/utils/generateWatchFiles.js +31 -52
- package/dist/cjs/utils/getSelectedEntries.js +13 -35
- package/dist/cjs/utils/getServerInternalPlugins.js +8 -29
- package/dist/cjs/utils/printInstructions.js +10 -28
- package/dist/cjs/utils/restart.js +13 -31
- package/dist/cjs/utils/routes.js +18 -39
- package/dist/cjs/utils/types.js +4 -15
- package/dist/esm/analyze/constants.js +40 -41
- package/dist/esm/analyze/generateCode.js +477 -455
- package/dist/esm/analyze/getBundleEntry.js +53 -54
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +201 -202
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +199 -200
- package/dist/esm/analyze/getClientRoutes/index.js +2 -3
- package/dist/esm/analyze/getClientRoutes/utils.js +15 -15
- package/dist/esm/analyze/getFileSystemEntry.js +86 -87
- package/dist/esm/analyze/getHtmlTemplate.js +289 -278
- package/dist/esm/analyze/getServerRoutes.js +203 -190
- package/dist/esm/analyze/index.js +679 -651
- package/dist/esm/analyze/isDefaultExportFunction.js +38 -39
- package/dist/esm/analyze/makeLegalIdentifier.js +8 -9
- package/dist/esm/analyze/nestedRoutes.js +400 -392
- package/dist/esm/analyze/templates.js +536 -509
- package/dist/esm/analyze/utils.js +357 -336
- package/dist/esm/builder/builder-rspack/adapterCopy.js +347 -330
- package/dist/esm/builder/builder-rspack/index.js +8 -9
- package/dist/esm/builder/builder-webpack/adapterModern.js +51 -43
- package/dist/esm/builder/builder-webpack/createCopyPattern.js +31 -32
- package/dist/esm/builder/builder-webpack/index.js +266 -249
- package/dist/esm/builder/generator/createBuilderOptions.js +37 -38
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +62 -63
- package/dist/esm/builder/generator/getBuilderTargets.js +13 -14
- package/dist/esm/builder/generator/index.js +203 -196
- package/dist/esm/builder/index.js +183 -176
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +90 -91
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +300 -291
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +337 -329
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +108 -97
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +66 -64
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +364 -337
- package/dist/esm/builder/shared/createCopyInfo.js +9 -10
- package/dist/esm/builder/shared/loaders/serverModuleLoader.js +2 -3
- package/dist/esm/builder/shared/types.js +1 -1
- package/dist/esm/commands/build.js +279 -272
- package/dist/esm/commands/deploy.js +150 -144
- package/dist/esm/commands/dev.js +296 -289
- package/dist/esm/commands/inspect.js +144 -138
- package/dist/esm/commands/serve.js +241 -235
- package/dist/esm/config/default.js +202 -203
- package/dist/esm/config/initialize/index.js +7 -8
- package/dist/esm/config/initialize/inits.js +189 -181
- package/dist/esm/config/legacy/createHtmlConfig.js +17 -18
- package/dist/esm/config/legacy/createOutputConfig.js +41 -42
- package/dist/esm/config/legacy/createSourceConfig.js +38 -39
- package/dist/esm/config/legacy/createToolsConfig.js +24 -25
- package/dist/esm/config/legacy/index.js +31 -32
- package/dist/esm/defineConfig.js +52 -53
- package/dist/esm/exports/server.js +1 -2
- package/dist/esm/hooks.js +26 -27
- package/dist/esm/index.js +685 -671
- package/dist/esm/initialize/index.js +276 -269
- package/dist/esm/locale/en.js +36 -37
- package/dist/esm/locale/index.js +2 -2
- package/dist/esm/locale/zh.js +36 -37
- package/dist/esm/schema/Schema.js +255 -244
- package/dist/esm/schema/index.js +165 -165
- package/dist/esm/schema/legacy.js +316 -317
- package/dist/esm/types/config/deploy.js +1 -1
- package/dist/esm/types/config/dev.js +1 -1
- package/dist/esm/types/config/experiments.js +1 -1
- package/dist/esm/types/config/html.js +1 -1
- package/dist/esm/types/config/output.js +1 -1
- package/dist/esm/types/config/performance.js +1 -1
- package/dist/esm/types/config/security.js +1 -1
- package/dist/esm/types/config/source.js +1 -1
- package/dist/esm/types/config/tools.js +1 -1
- package/dist/esm/types/hooks.js +1 -1
- package/dist/esm/types/legacyConfig/deploy.js +1 -1
- package/dist/esm/types/legacyConfig/dev.js +1 -1
- package/dist/esm/types/legacyConfig/index.js +1 -1
- package/dist/esm/types/legacyConfig/output.js +1 -1
- package/dist/esm/types/legacyConfig/source.js +1 -1
- package/dist/esm/types/legacyConfig/tools.js +1 -1
- package/dist/esm/types/utils.js +1 -1
- package/dist/esm/utils/config.js +285 -278
- package/dist/esm/utils/createServer.js +242 -234
- package/dist/esm/utils/env.js +11 -12
- package/dist/esm/utils/generateWatchFiles.js +205 -190
- package/dist/esm/utils/getSelectedEntries.js +180 -173
- package/dist/esm/utils/getServerInternalPlugins.js +197 -191
- package/dist/esm/utils/printInstructions.js +147 -141
- package/dist/esm/utils/restart.js +179 -173
- package/dist/esm/utils/routes.js +146 -139
- package/dist/esm/utils/types.js +1 -1
- package/dist/esm-node/analyze/constants.js +31 -46
- package/dist/esm-node/analyze/generateCode.js +28 -94
- package/dist/esm-node/analyze/getBundleEntry.js +8 -27
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +24 -65
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +24 -63
- package/dist/esm-node/analyze/getClientRoutes/index.js +2 -6
- package/dist/esm-node/analyze/getClientRoutes/utils.js +5 -19
- package/dist/esm-node/analyze/getFileSystemEntry.js +10 -37
- package/dist/esm-node/analyze/getHtmlTemplate.js +29 -59
- package/dist/esm-node/analyze/getServerRoutes.js +43 -75
- package/dist/esm-node/analyze/index.js +208 -230
- package/dist/esm-node/analyze/isDefaultExportFunction.js +7 -5
- package/dist/esm-node/analyze/makeLegalIdentifier.js +1 -4
- package/dist/esm-node/analyze/nestedRoutes.js +23 -43
- package/dist/esm-node/analyze/templates.js +22 -69
- package/dist/esm-node/analyze/utils.js +66 -60
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +40 -62
- package/dist/esm-node/builder/builder-rspack/index.js +4 -5
- package/dist/esm-node/builder/builder-webpack/adapterModern.js +24 -26
- package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +3 -10
- package/dist/esm-node/builder/builder-webpack/index.js +13 -11
- package/dist/esm-node/builder/generator/createBuilderOptions.js +4 -5
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +5 -6
- package/dist/esm-node/builder/generator/getBuilderTargets.js +5 -11
- package/dist/esm-node/builder/generator/index.js +7 -16
- package/dist/esm-node/builder/index.js +2 -7
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +2 -6
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +34 -60
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +54 -74
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +23 -8
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +25 -16
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +66 -76
- package/dist/esm-node/builder/shared/createCopyInfo.js +2 -8
- package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +1 -4
- package/dist/esm-node/builder/shared/types.js +1 -0
- package/dist/esm-node/commands/build.js +7 -9
- package/dist/esm-node/commands/deploy.js +1 -4
- package/dist/esm-node/commands/dev.js +19 -27
- package/dist/esm-node/commands/inspect.js +3 -8
- package/dist/esm-node/commands/serve.js +7 -25
- package/dist/esm-node/config/default.js +20 -11
- package/dist/esm-node/config/initialize/index.js +1 -4
- package/dist/esm-node/config/initialize/inits.js +48 -54
- package/dist/esm-node/config/legacy/createHtmlConfig.js +2 -19
- package/dist/esm-node/config/legacy/createOutputConfig.js +2 -30
- package/dist/esm-node/config/legacy/createSourceConfig.js +2 -17
- package/dist/esm-node/config/legacy/createToolsConfig.js +2 -22
- package/dist/esm-node/config/legacy/index.js +3 -18
- package/dist/esm-node/defineConfig.js +7 -13
- package/dist/esm-node/exports/server.js +1 -4
- package/dist/esm-node/hooks.js +2 -9
- package/dist/esm-node/index.js +95 -120
- package/dist/esm-node/initialize/index.js +74 -87
- package/dist/esm-node/locale/en.js +7 -6
- package/dist/esm-node/locale/index.js +5 -5
- package/dist/esm-node/locale/zh.js +7 -6
- package/dist/esm-node/schema/Schema.js +19 -8
- package/dist/esm-node/schema/index.js +121 -36
- package/dist/esm-node/schema/legacy.js +262 -72
- package/dist/esm-node/types/config/deploy.js +1 -0
- package/dist/esm-node/types/config/dev.js +1 -0
- package/dist/esm-node/types/config/experiments.js +1 -0
- package/dist/esm-node/types/config/html.js +1 -0
- package/dist/esm-node/types/config/output.js +1 -0
- package/dist/esm-node/types/config/performance.js +1 -0
- package/dist/esm-node/types/config/security.js +1 -0
- package/dist/esm-node/types/config/source.js +1 -0
- package/dist/esm-node/types/config/tools.js +1 -0
- package/dist/esm-node/types/hooks.js +1 -0
- package/dist/esm-node/types/legacyConfig/deploy.js +1 -0
- package/dist/esm-node/types/legacyConfig/dev.js +1 -0
- package/dist/esm-node/types/legacyConfig/index.js +1 -0
- package/dist/esm-node/types/legacyConfig/output.js +1 -0
- package/dist/esm-node/types/legacyConfig/source.js +1 -0
- package/dist/esm-node/types/legacyConfig/tools.js +1 -0
- package/dist/esm-node/types/utils.js +1 -0
- package/dist/esm-node/utils/config.js +16 -47
- package/dist/esm-node/utils/createServer.js +5 -12
- package/dist/esm-node/utils/env.js +1 -4
- package/dist/esm-node/utils/generateWatchFiles.js +13 -20
- package/dist/esm-node/utils/getSelectedEntries.js +2 -9
- package/dist/esm-node/utils/getServerInternalPlugins.js +2 -8
- package/dist/esm-node/utils/printInstructions.js +1 -4
- package/dist/esm-node/utils/restart.js +2 -11
- package/dist/esm-node/utils/routes.js +4 -4
- package/dist/esm-node/utils/types.js +1 -0
- package/dist/types/index.d.ts +2 -2
- package/package.json +29 -25
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
2
|
import { createPublicPattern } from "./createCopyPattern";
|
|
3
|
-
const builderPluginAdapterModern = (options) =>
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
appContext,
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
builderPluginAdapterModern
|
|
3
|
+
export const builderPluginAdapterModern = (options) => {
|
|
4
|
+
return {
|
|
5
|
+
name: "builder-plugin-adapter-",
|
|
6
|
+
setup(api) {
|
|
7
|
+
const { normalizedConfig: modernConfig, appContext } = options;
|
|
8
|
+
api.modifyWebpackChain((chain, { CHAIN_ID }) => {
|
|
9
|
+
chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
|
|
10
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
11
|
+
const defaultCopyPattern = createPublicPattern(appContext, modernConfig, chain);
|
|
12
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
13
|
+
var _args_;
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
patterns: [
|
|
17
|
+
...((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || [],
|
|
18
|
+
defaultCopyPattern
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
];
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
};
|
|
29
27
|
};
|
|
@@ -7,7 +7,7 @@ const info = (file) => ({
|
|
|
7
7
|
// ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
|
|
8
8
|
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
9
9
|
});
|
|
10
|
-
function createPublicPattern(appContext, config, chain) {
|
|
10
|
+
export function createPublicPattern(appContext, config, chain) {
|
|
11
11
|
const { publicDir } = createCopyInfo(appContext, config);
|
|
12
12
|
return {
|
|
13
13
|
info,
|
|
@@ -20,14 +20,11 @@ function createPublicPattern(appContext, config, chain) {
|
|
|
20
20
|
if (!/\.html?$/.test(absoluteFrom)) {
|
|
21
21
|
return content;
|
|
22
22
|
}
|
|
23
|
-
return content.toString("utf8").replace(
|
|
24
|
-
/<%=\s*assetPrefix\s*%>/g,
|
|
25
|
-
removeTailSlash(chain.output.get("publicPath"))
|
|
26
|
-
);
|
|
23
|
+
return content.toString("utf8").replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(chain.output.get("publicPath")));
|
|
27
24
|
}
|
|
28
25
|
};
|
|
29
26
|
}
|
|
30
|
-
function createUploadPattern(appContext, config) {
|
|
27
|
+
export function createUploadPattern(appContext, config) {
|
|
31
28
|
const { uploadDir } = createCopyInfo(appContext, config);
|
|
32
29
|
return {
|
|
33
30
|
info,
|
|
@@ -37,7 +34,3 @@ function createUploadPattern(appContext, config) {
|
|
|
37
34
|
noErrorOnMissing: true
|
|
38
35
|
};
|
|
39
36
|
}
|
|
40
|
-
export {
|
|
41
|
-
createPublicPattern,
|
|
42
|
-
createUploadPattern
|
|
43
|
-
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
builderWebpackProvider
|
|
3
|
-
} from "@modern-js/builder-webpack-provider";
|
|
1
|
+
import { builderWebpackProvider } from "@modern-js/builder-webpack-provider";
|
|
4
2
|
import { generateBuilder } from "../generator";
|
|
5
3
|
import { builderPluginAdapterModern } from "./adapterModern";
|
|
6
4
|
import { createUploadPattern } from "./createCopyPattern";
|
|
7
|
-
function createWebpackBuilderForModern(options) {
|
|
5
|
+
export function createWebpackBuilderForModern(options) {
|
|
8
6
|
return generateBuilder(options, builderWebpackProvider, {
|
|
9
7
|
modifyBuilderConfig(config) {
|
|
10
8
|
modifyOutputConfig(config, options.appContext);
|
|
@@ -19,8 +17,11 @@ function modifyOutputConfig(config, appContext) {
|
|
|
19
17
|
function createOutputConfig(config2, appContext2) {
|
|
20
18
|
const defaultCopyPattern = createUploadPattern(appContext2, config2);
|
|
21
19
|
const { copy } = config2.output;
|
|
22
|
-
const copyOptions = Array.isArray(copy) ? copy : copy
|
|
23
|
-
const builderCopy = [
|
|
20
|
+
const copyOptions = Array.isArray(copy) ? copy : copy === null || copy === void 0 ? void 0 : copy.patterns;
|
|
21
|
+
const builderCopy = [
|
|
22
|
+
...copyOptions || [],
|
|
23
|
+
defaultCopyPattern
|
|
24
|
+
];
|
|
24
25
|
return {
|
|
25
26
|
...config2.output,
|
|
26
27
|
copy: builderCopy
|
|
@@ -32,10 +33,11 @@ async function applyBuilderPlugins(builder, options) {
|
|
|
32
33
|
if (normalizedConfig.tools.esbuild) {
|
|
33
34
|
const { esbuild: esbuildOptions } = normalizedConfig.tools;
|
|
34
35
|
const { builderPluginEsbuild } = await import("@modern-js/builder-plugin-esbuild");
|
|
35
|
-
builder.addPlugins([
|
|
36
|
+
builder.addPlugins([
|
|
37
|
+
builderPluginEsbuild(esbuildOptions)
|
|
38
|
+
]);
|
|
36
39
|
}
|
|
37
|
-
builder.addPlugins([
|
|
40
|
+
builder.addPlugins([
|
|
41
|
+
builderPluginAdapterModern(options)
|
|
42
|
+
]);
|
|
38
43
|
}
|
|
39
|
-
export {
|
|
40
|
-
createWebpackBuilderForModern
|
|
41
|
-
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function createBuilderOptions(target, appContext) {
|
|
1
|
+
export function createBuilderOptions(target, appContext) {
|
|
2
2
|
const entries = {};
|
|
3
3
|
const { entrypoints = [], checkedEntries } = appContext;
|
|
4
4
|
for (const { entryName, entry } of entrypoints) {
|
|
@@ -8,7 +8,9 @@ function createBuilderOptions(target, appContext) {
|
|
|
8
8
|
if (entryName in entries) {
|
|
9
9
|
entries[entryName].push(entry);
|
|
10
10
|
} else {
|
|
11
|
-
entries[entryName] = [
|
|
11
|
+
entries[entryName] = [
|
|
12
|
+
entry
|
|
13
|
+
];
|
|
12
14
|
}
|
|
13
15
|
}
|
|
14
16
|
return {
|
|
@@ -19,6 +21,3 @@ function createBuilderOptions(target, appContext) {
|
|
|
19
21
|
framework: appContext.metaName
|
|
20
22
|
};
|
|
21
23
|
}
|
|
22
|
-
export {
|
|
23
|
-
createBuilderOptions
|
|
24
|
-
};
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
function createBuilderProviderConfig(resolveConfig, appContext, modifyBuilderConfig) {
|
|
2
|
-
const htmlConfig = {
|
|
1
|
+
export function createBuilderProviderConfig(resolveConfig, appContext, modifyBuilderConfig) {
|
|
2
|
+
const htmlConfig = {
|
|
3
|
+
...resolveConfig.html
|
|
4
|
+
};
|
|
3
5
|
if (!htmlConfig.template) {
|
|
4
6
|
htmlConfig.templateByEntries = {
|
|
5
7
|
...htmlConfig.templateByEntries,
|
|
@@ -19,9 +21,6 @@ function createBuilderProviderConfig(resolveConfig, appContext, modifyBuilderCon
|
|
|
19
21
|
cleanDistPath: false
|
|
20
22
|
}
|
|
21
23
|
};
|
|
22
|
-
modifyBuilderConfig
|
|
24
|
+
modifyBuilderConfig === null || modifyBuilderConfig === void 0 ? void 0 : modifyBuilderConfig(config);
|
|
23
25
|
return config;
|
|
24
26
|
}
|
|
25
|
-
export {
|
|
26
|
-
createBuilderProviderConfig
|
|
27
|
-
};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "@modern-js/utils";
|
|
7
|
-
function getBuilderTargets(normalizedConfig) {
|
|
8
|
-
const targets = ["web"];
|
|
1
|
+
import { isProd, isServiceWorker, isSSR, isUseSSRBundle } from "@modern-js/utils";
|
|
2
|
+
export function getBuilderTargets(normalizedConfig) {
|
|
3
|
+
const targets = [
|
|
4
|
+
"web"
|
|
5
|
+
];
|
|
9
6
|
const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
|
|
10
7
|
if (useNodeTarget) {
|
|
11
8
|
targets.push("node");
|
|
@@ -16,6 +13,3 @@ function getBuilderTargets(normalizedConfig) {
|
|
|
16
13
|
}
|
|
17
14
|
return targets;
|
|
18
15
|
}
|
|
19
|
-
export {
|
|
20
|
-
getBuilderTargets
|
|
21
|
-
};
|
|
@@ -2,14 +2,10 @@ import { createBuilder } from "@modern-js/builder";
|
|
|
2
2
|
import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
|
|
3
3
|
import { getBuilderTargets } from "./getBuilderTargets";
|
|
4
4
|
import { createBuilderOptions } from "./createBuilderOptions";
|
|
5
|
-
async function generateBuilder(options, generateProvider, utils) {
|
|
5
|
+
export async function generateBuilder(options, generateProvider, utils) {
|
|
6
6
|
const { normalizedConfig, appContext } = options;
|
|
7
7
|
const { modifyBuilderConfig, modifyBuilderInstance } = utils || {};
|
|
8
|
-
const builderConfig = createBuilderProviderConfig(
|
|
9
|
-
normalizedConfig,
|
|
10
|
-
appContext,
|
|
11
|
-
modifyBuilderConfig
|
|
12
|
-
);
|
|
8
|
+
const builderConfig = createBuilderProviderConfig(normalizedConfig, appContext, modifyBuilderConfig);
|
|
13
9
|
const provider = generateProvider({
|
|
14
10
|
builderConfig
|
|
15
11
|
});
|
|
@@ -17,15 +13,11 @@ async function generateBuilder(options, generateProvider, utils) {
|
|
|
17
13
|
const builderOptions = createBuilderOptions(target, appContext);
|
|
18
14
|
const builder = await createBuilder(provider, builderOptions);
|
|
19
15
|
await applyBuilderPlugins(builder, options);
|
|
20
|
-
await (modifyBuilderInstance
|
|
16
|
+
await (modifyBuilderInstance === null || modifyBuilderInstance === void 0 ? void 0 : modifyBuilderInstance(builder));
|
|
21
17
|
return builder;
|
|
22
18
|
}
|
|
23
19
|
async function applyBuilderPlugins(builder, options) {
|
|
24
|
-
const {
|
|
25
|
-
builderPluginAdapterBasic,
|
|
26
|
-
builderPluginAdapterHtml,
|
|
27
|
-
builderPluginAdapterSSR
|
|
28
|
-
} = await import("../shared/builderPlugins");
|
|
20
|
+
const { builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR } = await import("../shared/builderPlugins");
|
|
29
21
|
builder.addPlugins([
|
|
30
22
|
builderPluginAdapterBasic(options),
|
|
31
23
|
builderPluginAdapterSSR(options),
|
|
@@ -34,9 +26,8 @@ async function applyBuilderPlugins(builder, options) {
|
|
|
34
26
|
const { normalizedConfig } = options;
|
|
35
27
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
36
28
|
const { builderPluginNodePolyfill } = await import("@modern-js/builder-plugin-node-polyfill");
|
|
37
|
-
builder.addPlugins([
|
|
29
|
+
builder.addPlugins([
|
|
30
|
+
builderPluginNodePolyfill()
|
|
31
|
+
]);
|
|
38
32
|
}
|
|
39
33
|
}
|
|
40
|
-
export {
|
|
41
|
-
generateBuilder
|
|
42
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { logger } from "@modern-js/utils";
|
|
2
|
-
async function createBuilderGenerator(bundler) {
|
|
2
|
+
export async function createBuilderGenerator(bundler) {
|
|
3
3
|
if (bundler === "rspack") {
|
|
4
4
|
try {
|
|
5
5
|
const { createRspackBuilderForModern } = await import("./builder-rspack");
|
|
@@ -8,14 +8,9 @@ async function createBuilderGenerator(bundler) {
|
|
|
8
8
|
logger.info(`Using Rspack v${version} 🦀`);
|
|
9
9
|
return createRspackBuilderForModern;
|
|
10
10
|
} catch (_) {
|
|
11
|
-
throw new Error(
|
|
12
|
-
"Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed"
|
|
13
|
-
);
|
|
11
|
+
throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
|
|
14
12
|
}
|
|
15
13
|
}
|
|
16
14
|
const { createWebpackBuilderForModern } = await import("./builder-webpack");
|
|
17
15
|
return createWebpackBuilderForModern;
|
|
18
16
|
}
|
|
19
|
-
export {
|
|
20
|
-
createBuilderGenerator
|
|
21
|
-
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const builderPluginAdapterBasic = (options) => ({
|
|
1
|
+
export const builderPluginAdapterBasic = (options) => ({
|
|
2
2
|
name: "builder-plugin-adapter-modern-basic",
|
|
3
3
|
setup(api) {
|
|
4
4
|
api.modifyBundlerChain((chain, { target, CHAIN_ID }) => {
|
|
@@ -25,7 +25,7 @@ const builderPluginAdapterBasic = (options) => ({
|
|
|
25
25
|
applyCallbacks(api, options);
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
function applyCallbacks(api, options) {
|
|
28
|
+
export function applyCallbacks(api, options) {
|
|
29
29
|
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
30
30
|
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
31
31
|
options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
|
|
@@ -61,7 +61,3 @@ function applyNodeCompat(target, chain) {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
export {
|
|
65
|
-
applyCallbacks,
|
|
66
|
-
builderPluginAdapterBasic
|
|
67
|
-
};
|
|
@@ -1,43 +1,33 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "@modern-js/builder-shared";
|
|
4
|
-
import {
|
|
5
|
-
getEntryOptions,
|
|
6
|
-
removeTailSlash
|
|
7
|
-
} from "@modern-js/utils";
|
|
1
|
+
import { createVirtualModule } from "@modern-js/builder-shared";
|
|
2
|
+
import { getEntryOptions, removeTailSlash } from "@modern-js/utils";
|
|
8
3
|
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
9
4
|
import { BottomTemplatePlugin } from "../bundlerPlugins";
|
|
10
|
-
function isHtmlEnabled(config, target) {
|
|
11
|
-
var
|
|
12
|
-
return ((
|
|
5
|
+
export function isHtmlEnabled(config, target) {
|
|
6
|
+
var _config_tools;
|
|
7
|
+
return ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
|
|
13
8
|
}
|
|
14
|
-
const builderPluginAdapterHtml = (options) => ({
|
|
9
|
+
export const builderPluginAdapterHtml = (options) => ({
|
|
15
10
|
name: "builder-plugin-adapter-modern-html",
|
|
16
11
|
setup(api) {
|
|
17
|
-
api.modifyBundlerChain(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
}
|
|
12
|
+
api.modifyBundlerChain(async (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
|
+
await injectAssetPrefix({
|
|
23
|
+
api,
|
|
24
|
+
chain
|
|
25
|
+
});
|
|
33
26
|
}
|
|
34
|
-
);
|
|
27
|
+
});
|
|
35
28
|
}
|
|
36
29
|
});
|
|
37
|
-
async function injectAssetPrefix({
|
|
38
|
-
api,
|
|
39
|
-
chain
|
|
40
|
-
}) {
|
|
30
|
+
async function injectAssetPrefix({ api, chain }) {
|
|
41
31
|
const entries = chain.entryPoints.entries() || {};
|
|
42
32
|
const entryNames = Object.keys(entries);
|
|
43
33
|
const assetPrefix = removeTailSlash(chain.output.get("publicPath") || "");
|
|
@@ -48,7 +38,11 @@ async function injectAssetPrefix({
|
|
|
48
38
|
const { default: RspackVirtualModulePlugin } = await import("rspack-plugin-virtual-module");
|
|
49
39
|
entryNames.forEach((entryName) => {
|
|
50
40
|
entries[entryName].prepend(fileName);
|
|
51
|
-
chain.plugin("rspack-asset-prefix").use(RspackVirtualModulePlugin, [
|
|
41
|
+
chain.plugin("rspack-asset-prefix").use(RspackVirtualModulePlugin, [
|
|
42
|
+
{
|
|
43
|
+
[fileName]: code
|
|
44
|
+
}
|
|
45
|
+
]);
|
|
52
46
|
});
|
|
53
47
|
} else {
|
|
54
48
|
entryNames.forEach((entryName) => {
|
|
@@ -56,44 +50,24 @@ async function injectAssetPrefix({
|
|
|
56
50
|
});
|
|
57
51
|
}
|
|
58
52
|
}
|
|
59
|
-
function applyBottomHtmlPlugin({
|
|
60
|
-
api,
|
|
61
|
-
chain,
|
|
62
|
-
options,
|
|
63
|
-
CHAIN_ID,
|
|
64
|
-
HtmlBundlerPlugin
|
|
65
|
-
}) {
|
|
53
|
+
function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugin }) {
|
|
66
54
|
const { normalizedConfig: modernConfig, appContext } = options;
|
|
67
55
|
for (const entryName of Object.keys(api.context.entry)) {
|
|
68
56
|
const baseTemplateParams = {
|
|
69
57
|
entryName,
|
|
70
|
-
title: getEntryOptions(
|
|
71
|
-
entryName,
|
|
72
|
-
modernConfig.html.title,
|
|
73
|
-
modernConfig.html.titleByEntries,
|
|
74
|
-
appContext.packageName
|
|
75
|
-
),
|
|
58
|
+
title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
|
76
59
|
mountId: modernConfig.html.mountId,
|
|
77
|
-
...getEntryOptions(
|
|
78
|
-
entryName,
|
|
79
|
-
modernConfig.html.templateParameters,
|
|
80
|
-
modernConfig.html.templateParametersByEntries,
|
|
81
|
-
appContext.packageName
|
|
82
|
-
)
|
|
60
|
+
...getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName)
|
|
83
61
|
};
|
|
84
62
|
chain.plugin(`${CHAIN_ID.PLUGIN.HTML}-${entryName}`).tap((args) => [
|
|
85
63
|
{
|
|
86
64
|
...args[0] || {},
|
|
87
65
|
__internal__: true,
|
|
88
|
-
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(
|
|
89
|
-
baseTemplateParams
|
|
90
|
-
)
|
|
66
|
+
bottomTemplate: appContext.htmlTemplates[`__${entryName}-bottom__`] && lodashTemplate(appContext.htmlTemplates[`__${entryName}-bottom__`])(baseTemplateParams)
|
|
91
67
|
}
|
|
92
68
|
]);
|
|
93
69
|
}
|
|
94
|
-
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [
|
|
70
|
+
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [
|
|
71
|
+
HtmlBundlerPlugin
|
|
72
|
+
]);
|
|
95
73
|
}
|
|
96
|
-
export {
|
|
97
|
-
builderPluginAdapterHtml,
|
|
98
|
-
isHtmlEnabled
|
|
99
|
-
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import * as path from "path";
|
|
2
|
-
import {
|
|
3
|
-
mergeBuilderConfig
|
|
4
|
-
} from "@modern-js/builder-shared";
|
|
2
|
+
import { mergeBuilderConfig } from "@modern-js/builder-shared";
|
|
5
3
|
import { isSSR, fs } from "@modern-js/utils";
|
|
6
4
|
import { HtmlAsyncChunkPlugin, RouterPlugin } from "../bundlerPlugins";
|
|
7
5
|
import { getServerCombinedModueFile } from "../../../analyze/utils";
|
|
8
6
|
import { isHtmlEnabled } from "./adapterHtml";
|
|
9
|
-
const builderPluginAdapterSSR = (options) => ({
|
|
7
|
+
export const builderPluginAdapterSSR = (options) => ({
|
|
10
8
|
name: "builder-plugin-adapter-modern-ssr",
|
|
11
9
|
setup(api) {
|
|
12
10
|
const { normalizedConfig } = options;
|
|
@@ -20,32 +18,33 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
20
18
|
}
|
|
21
19
|
return config;
|
|
22
20
|
});
|
|
23
|
-
api.modifyBundlerChain(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
applySSRDataLoader(chain, options);
|
|
31
|
-
}
|
|
32
|
-
if (["node", "service-worker"].includes(target)) {
|
|
33
|
-
applyFilterEntriesBySSRConfig({
|
|
34
|
-
isProd,
|
|
35
|
-
chain,
|
|
36
|
-
appNormalizedConfig: normalizedConfig2
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (isHtmlEnabled(builderConfig, target)) {
|
|
40
|
-
applyAsyncChunkHtmlPlugin({
|
|
41
|
-
chain,
|
|
42
|
-
modernConfig: options.normalizedConfig,
|
|
43
|
-
CHAIN_ID,
|
|
44
|
-
HtmlBundlerPlugin
|
|
45
|
-
});
|
|
46
|
-
}
|
|
21
|
+
api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
|
22
|
+
const builderConfig = api.getNormalizedConfig();
|
|
23
|
+
const { normalizedConfig: normalizedConfig2 } = options;
|
|
24
|
+
applyRouterPlugin(chain, options);
|
|
25
|
+
if (isSSR(normalizedConfig2)) {
|
|
26
|
+
await applySSRLoaderEntry(chain, options, isServer);
|
|
27
|
+
applySSRDataLoader(chain, options);
|
|
47
28
|
}
|
|
48
|
-
|
|
29
|
+
if ([
|
|
30
|
+
"node",
|
|
31
|
+
"service-worker"
|
|
32
|
+
].includes(target)) {
|
|
33
|
+
applyFilterEntriesBySSRConfig({
|
|
34
|
+
isProd,
|
|
35
|
+
chain,
|
|
36
|
+
appNormalizedConfig: normalizedConfig2
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (isHtmlEnabled(builderConfig, target)) {
|
|
40
|
+
applyAsyncChunkHtmlPlugin({
|
|
41
|
+
chain,
|
|
42
|
+
modernConfig: options.normalizedConfig,
|
|
43
|
+
CHAIN_ID,
|
|
44
|
+
HtmlBundlerPlugin
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
});
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
50
|
const isStreamingSSR = (userConfig) => {
|
|
@@ -54,7 +53,7 @@ const isStreamingSSR = (userConfig) => {
|
|
|
54
53
|
if (isStreaming(server.ssr)) {
|
|
55
54
|
return true;
|
|
56
55
|
}
|
|
57
|
-
if ((server
|
|
56
|
+
if ((server === null || server === void 0 ? void 0 : server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
58
57
|
for (const name of Object.keys(server.ssrByEntries)) {
|
|
59
58
|
if (isStreaming(server.ssrByEntries[name])) {
|
|
60
59
|
return true;
|
|
@@ -63,51 +62,40 @@ const isStreamingSSR = (userConfig) => {
|
|
|
63
62
|
}
|
|
64
63
|
return false;
|
|
65
64
|
};
|
|
66
|
-
function applyAsyncChunkHtmlPlugin({
|
|
67
|
-
chain,
|
|
68
|
-
modernConfig,
|
|
69
|
-
CHAIN_ID,
|
|
70
|
-
HtmlBundlerPlugin
|
|
71
|
-
}) {
|
|
65
|
+
function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerPlugin }) {
|
|
72
66
|
if (isStreamingSSR(modernConfig)) {
|
|
73
|
-
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [
|
|
67
|
+
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [
|
|
68
|
+
HtmlBundlerPlugin
|
|
69
|
+
]);
|
|
74
70
|
}
|
|
75
71
|
}
|
|
76
72
|
function applyRouterPlugin(chain, options) {
|
|
77
|
-
var
|
|
73
|
+
var _normalizedConfig_runtime;
|
|
78
74
|
const { appContext, normalizedConfig } = options;
|
|
79
75
|
const { entrypoints } = appContext;
|
|
80
|
-
const existNestedRoutes = entrypoints.some(
|
|
81
|
-
|
|
82
|
-
);
|
|
83
|
-
const routerConfig = (_a = normalizedConfig == null ? void 0 : normalizedConfig.runtime) == null ? void 0 : _a.router;
|
|
84
|
-
const routerManifest = Boolean(routerConfig == null ? void 0 : routerConfig.manifest);
|
|
76
|
+
const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
|
|
77
|
+
const routerConfig = 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 === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
|
85
79
|
if (existNestedRoutes || routerManifest) {
|
|
86
80
|
chain.plugin("route-plugin").use(RouterPlugin);
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
|
-
function applyFilterEntriesBySSRConfig({
|
|
90
|
-
|
|
91
|
-
chain,
|
|
92
|
-
appNormalizedConfig
|
|
93
|
-
}) {
|
|
94
|
-
var _a;
|
|
83
|
+
function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
84
|
+
var _ref;
|
|
95
85
|
const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
|
|
96
86
|
const entries = chain.entryPoints.entries();
|
|
97
|
-
if (isProd && ((outputConfig
|
|
87
|
+
if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof ((_ref = outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === null || _ref === void 0 ? void 0 : _ref[0]) === "function")) {
|
|
98
88
|
return;
|
|
99
89
|
}
|
|
100
90
|
if (typeof entries === "undefined") {
|
|
101
|
-
throw new Error(
|
|
102
|
-
"No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required"
|
|
103
|
-
);
|
|
91
|
+
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
|
104
92
|
}
|
|
105
93
|
const entryNames = Object.keys(entries);
|
|
106
|
-
if (isProd && entryNames.length === 1 && (outputConfig
|
|
94
|
+
if (isProd && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
|
107
95
|
return;
|
|
108
96
|
}
|
|
109
97
|
const ssgEntries = [];
|
|
110
|
-
if (isProd && (outputConfig
|
|
98
|
+
if (isProd && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
|
111
99
|
const { ssg } = outputConfig;
|
|
112
100
|
entryNames.forEach((name) => {
|
|
113
101
|
if (ssg[name]) {
|
|
@@ -117,7 +105,7 @@ function applyFilterEntriesBySSRConfig({
|
|
|
117
105
|
}
|
|
118
106
|
const { ssr, ssrByEntries } = serverConfig || {};
|
|
119
107
|
entryNames.forEach((name) => {
|
|
120
|
-
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries
|
|
108
|
+
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]))) {
|
|
121
109
|
chain.entryPoints.delete(name);
|
|
122
110
|
}
|
|
123
111
|
});
|
|
@@ -126,22 +114,17 @@ async function applySSRLoaderEntry(chain, optinos, isServer) {
|
|
|
126
114
|
const { appContext } = optinos;
|
|
127
115
|
const { internalDirectory } = appContext;
|
|
128
116
|
const { entrypoints } = appContext;
|
|
129
|
-
await Promise.all(
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
try {
|
|
138
|
-
await fs.access(serverLoadersFile, fs.constants.F_OK);
|
|
139
|
-
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
140
|
-
} catch (err) {
|
|
141
|
-
}
|
|
117
|
+
await Promise.all(entrypoints.map(async (entrypoint) => {
|
|
118
|
+
const { entryName } = entrypoint;
|
|
119
|
+
const serverLoadersFile = getServerCombinedModueFile(internalDirectory, entryName);
|
|
120
|
+
if (isServer) {
|
|
121
|
+
try {
|
|
122
|
+
await fs.access(serverLoadersFile, fs.constants.F_OK);
|
|
123
|
+
chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
|
|
124
|
+
} catch (err) {
|
|
142
125
|
}
|
|
143
|
-
}
|
|
144
|
-
);
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
145
128
|
}
|
|
146
129
|
function applySSRDataLoader(chain, options) {
|
|
147
130
|
const { normalizedConfig, appContext } = options;
|
|
@@ -151,6 +134,3 @@ function applySSRDataLoader(chain, options) {
|
|
|
151
134
|
const reg = new RegExp(`${absolutePath}.*\\.loader\\.[t|j]s$`);
|
|
152
135
|
chain.module.rule("ssr-data-loader").test(reg).use("data-loader").loader(require.resolve("@modern-js/plugin-data-loader/loader")).end();
|
|
153
136
|
}
|
|
154
|
-
export {
|
|
155
|
-
builderPluginAdapterSSR
|
|
156
|
-
};
|
|
@@ -1,13 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
5
11
|
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
export class HtmlAsyncChunkPlugin {
|
|
6
15
|
apply(compiler) {
|
|
7
16
|
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
8
17
|
const hooks = this.htmlWebpackPlugin.getHooks(compilation);
|
|
9
18
|
hooks.alterAssetTagGroups.tap(this.name, (assets) => {
|
|
10
|
-
const tags = [
|
|
19
|
+
const tags = [
|
|
20
|
+
...assets.headTags,
|
|
21
|
+
...assets.bodyTags
|
|
22
|
+
];
|
|
11
23
|
for (const tag of tags) {
|
|
12
24
|
if (tag.tagName === "script") {
|
|
13
25
|
const { attributes } = tag;
|
|
@@ -21,7 +33,10 @@ class HtmlAsyncChunkPlugin {
|
|
|
21
33
|
});
|
|
22
34
|
});
|
|
23
35
|
}
|
|
36
|
+
constructor(htmlWebpackPlugin) {
|
|
37
|
+
_define_property(this, "name", void 0);
|
|
38
|
+
_define_property(this, "htmlWebpackPlugin", void 0);
|
|
39
|
+
this.name = "HtmlAsyncChunkPlugin";
|
|
40
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
41
|
+
}
|
|
24
42
|
}
|
|
25
|
-
export {
|
|
26
|
-
HtmlAsyncChunkPlugin
|
|
27
|
-
};
|