@modern-js/app-tools 2.15.0 → 2.17.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 +68 -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,34 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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;
|
|
7
11
|
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
export class BottomTemplatePlugin {
|
|
8
15
|
apply(compiler) {
|
|
9
16
|
compiler.hooks.compilation.tap(this.name, (compilation) => {
|
|
10
17
|
this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, (data) => {
|
|
11
|
-
var
|
|
12
|
-
if (!((
|
|
18
|
+
var _data_plugin_options;
|
|
19
|
+
if (!((_data_plugin_options = data.plugin.options) === null || _data_plugin_options === void 0 ? void 0 : _data_plugin_options.__internal__)) {
|
|
13
20
|
return data;
|
|
14
21
|
}
|
|
15
22
|
if (this.bottomTemplateReg.test(data.html)) {
|
|
16
23
|
data.html = data.html.replace(this.bottomTemplateReg, "");
|
|
17
24
|
const { bottomTemplate } = data.plugin.options;
|
|
18
25
|
if (bottomTemplate) {
|
|
19
|
-
data.html = data.html.replace(
|
|
20
|
-
this.bodyRegExp,
|
|
21
|
-
(match) => `
|
|
26
|
+
data.html = data.html.replace(this.bodyRegExp, (match) => `
|
|
22
27
|
${bottomTemplate}
|
|
23
|
-
${match}`
|
|
24
|
-
);
|
|
28
|
+
${match}`);
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
return data;
|
|
28
32
|
});
|
|
29
33
|
});
|
|
30
34
|
}
|
|
35
|
+
constructor(htmlWebpackPlugin) {
|
|
36
|
+
_define_property(this, "htmlWebpackPlugin", void 0);
|
|
37
|
+
_define_property(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
|
|
38
|
+
_define_property(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
|
|
39
|
+
_define_property(this, "name", void 0);
|
|
40
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
41
|
+
this.name = "bottom-template";
|
|
42
|
+
}
|
|
31
43
|
}
|
|
32
|
-
export {
|
|
33
|
-
BottomTemplatePlugin
|
|
34
|
-
};
|
|
@@ -3,7 +3,7 @@ import { fs } from "@modern-js/utils";
|
|
|
3
3
|
import { ROUTE_MANIFEST_FILE } from "@modern-js/utils/constants";
|
|
4
4
|
import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
|
|
5
5
|
const PLUGIN_NAME = "ModernjsRoutePlugin";
|
|
6
|
-
class RouterPlugin {
|
|
6
|
+
export class RouterPlugin {
|
|
7
7
|
apply(compiler) {
|
|
8
8
|
const { target } = compiler.options;
|
|
9
9
|
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
|
@@ -25,89 +25,79 @@ class RouterPlugin {
|
|
|
25
25
|
return path2;
|
|
26
26
|
};
|
|
27
27
|
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
28
|
-
compilation.hooks.processAssets.tapPromise(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
28
|
+
compilation.hooks.processAssets.tapPromise({
|
|
29
|
+
name: PLUGIN_NAME,
|
|
30
|
+
stage: PROCESS_ASSETS_STAGE_REPORT
|
|
31
|
+
}, async () => {
|
|
32
|
+
const stats = compilation.getStats().toJson({
|
|
33
|
+
all: false,
|
|
34
|
+
publicPath: true,
|
|
35
|
+
assets: true,
|
|
36
|
+
chunkGroups: true,
|
|
37
|
+
chunks: true,
|
|
38
|
+
ids: true
|
|
39
|
+
});
|
|
40
|
+
const { publicPath, chunks = [], namedChunkGroups } = stats;
|
|
41
|
+
const routeAssets = {};
|
|
42
|
+
if (!namedChunkGroups) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
|
|
46
|
+
const assets = chunkGroup.assets.map((asset) => {
|
|
47
|
+
const filename2 = asset.name;
|
|
48
|
+
return publicPath ? normalizePath(publicPath) + filename2 : filename2;
|
|
41
49
|
});
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
|
|
48
|
-
const assets = chunkGroup.assets.map((asset) => {
|
|
49
|
-
const filename2 = asset.name;
|
|
50
|
-
return publicPath ? normalizePath(publicPath) + filename2 : filename2;
|
|
51
|
-
});
|
|
52
|
-
const referenceCssAssets = assets.filter(
|
|
53
|
-
(asset) => /\.css$/.test(asset)
|
|
54
|
-
);
|
|
55
|
-
routeAssets[name] = {
|
|
56
|
-
chunkIds: chunkGroup.chunks,
|
|
57
|
-
assets,
|
|
58
|
-
referenceCssAssets
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
const manifest = {
|
|
62
|
-
routeAssets
|
|
50
|
+
const referenceCssAssets = assets.filter((asset) => /\.css$/.test(asset));
|
|
51
|
+
routeAssets[name] = {
|
|
52
|
+
chunkIds: chunkGroup.chunks,
|
|
53
|
+
assets,
|
|
54
|
+
referenceCssAssets
|
|
63
55
|
};
|
|
64
|
-
|
|
56
|
+
}
|
|
57
|
+
const manifest = {
|
|
58
|
+
routeAssets
|
|
59
|
+
};
|
|
60
|
+
const injectedContent = `
|
|
65
61
|
;(function(){
|
|
66
62
|
window.${ROUTE_MANIFEST} = ${JSON.stringify(manifest, (k, v) => {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
63
|
+
if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
|
|
64
|
+
return v.map((item) => {
|
|
65
|
+
return item.replace(publicPath, "");
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
return v;
|
|
69
|
+
})};
|
|
74
70
|
})();
|
|
75
71
|
`;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (!asset) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
const newContent = `${injectedContent}${asset.source().toString()}`;
|
|
95
|
-
newAssetsMap.set(path.join(outputPath, file), newContent);
|
|
96
|
-
compilation.updateAsset(
|
|
97
|
-
file,
|
|
98
|
-
new RawSource(newContent),
|
|
99
|
-
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
|
100
|
-
void 0
|
|
101
|
-
);
|
|
72
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
73
|
+
const entryChunkIds = entrypointsArray.map((entrypoint) => entrypoint[0]);
|
|
74
|
+
const entryChunks = [
|
|
75
|
+
...chunks
|
|
76
|
+
].filter((chunk) => {
|
|
77
|
+
var _chunk_names;
|
|
78
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some((name) => entryChunkIds.includes(name));
|
|
79
|
+
});
|
|
80
|
+
const entryChunkFiles = entryChunks.map((chunk) => [
|
|
81
|
+
...chunk.files || []
|
|
82
|
+
].find((fname) => fname.includes(".js")));
|
|
83
|
+
for (const file of entryChunkFiles) {
|
|
84
|
+
const asset = compilation.assets[file];
|
|
85
|
+
if (!asset) {
|
|
86
|
+
continue;
|
|
102
87
|
}
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
88
|
+
const newContent = `${injectedContent}${asset.source().toString()}`;
|
|
89
|
+
newAssetsMap.set(path.join(outputPath, file), newContent);
|
|
90
|
+
compilation.updateAsset(
|
|
91
|
+
file,
|
|
92
|
+
new RawSource(newContent),
|
|
93
|
+
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
|
94
|
+
void 0
|
|
95
|
+
);
|
|
106
96
|
}
|
|
107
|
-
|
|
97
|
+
const filename = path.join(outputPath, ROUTE_MANIFEST_FILE);
|
|
98
|
+
await fs.ensureFile(filename);
|
|
99
|
+
await fs.writeFile(filename, JSON.stringify(manifest, null, 2));
|
|
100
|
+
});
|
|
108
101
|
});
|
|
109
102
|
}
|
|
110
103
|
}
|
|
111
|
-
export {
|
|
112
|
-
RouterPlugin
|
|
113
|
-
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
function createCopyInfo(appContext, config) {
|
|
3
|
-
const configDir = path.resolve(
|
|
4
|
-
appContext.appDirectory,
|
|
5
|
-
config.source.configDir || "./config"
|
|
6
|
-
);
|
|
2
|
+
export function createCopyInfo(appContext, config) {
|
|
3
|
+
const configDir = path.resolve(appContext.appDirectory, config.source.configDir || "./config");
|
|
7
4
|
const uploadDir = path.posix.join(configDir.replace(/\\/g, "/"), "upload");
|
|
8
5
|
const publicDir = path.posix.join(configDir.replace(/\\/g, "/"), "public");
|
|
9
6
|
return {
|
|
@@ -12,6 +9,3 @@ function createCopyInfo(appContext, config) {
|
|
|
12
9
|
publicDir
|
|
13
10
|
};
|
|
14
11
|
}
|
|
15
|
-
export {
|
|
16
|
-
createCopyInfo
|
|
17
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -2,8 +2,8 @@ import { ResolvedConfigContext } from "@modern-js/core";
|
|
|
2
2
|
import { logger, printBuildError } from "@modern-js/utils";
|
|
3
3
|
import { generateRoutes } from "../utils/routes";
|
|
4
4
|
import { buildServerConfig } from "../utils/config";
|
|
5
|
-
const build = async (api, options) => {
|
|
6
|
-
if (options
|
|
5
|
+
export const build = async (api, options) => {
|
|
6
|
+
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
|
7
7
|
process.env.BUNDLE_ANALYZE = "true";
|
|
8
8
|
}
|
|
9
9
|
let resolvedConfig = api.useResolvedConfigContext();
|
|
@@ -28,7 +28,10 @@ const build = async (api, options) => {
|
|
|
28
28
|
});
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
resolvedConfig = {
|
|
31
|
+
resolvedConfig = {
|
|
32
|
+
...resolvedConfig,
|
|
33
|
+
cliOptions: options
|
|
34
|
+
};
|
|
32
35
|
ResolvedConfigContext.set(resolvedConfig);
|
|
33
36
|
const { distDirectory, appDirectory, serverConfigFile } = appContext;
|
|
34
37
|
await buildServerConfig({
|
|
@@ -39,9 +42,7 @@ const build = async (api, options) => {
|
|
|
39
42
|
try {
|
|
40
43
|
logger.info("Create a production build...\n");
|
|
41
44
|
if (!appContext.builder) {
|
|
42
|
-
throw new Error(
|
|
43
|
-
"Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
|
|
44
|
-
);
|
|
45
|
+
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
45
46
|
}
|
|
46
47
|
await appContext.builder.build();
|
|
47
48
|
} catch (error) {
|
|
@@ -49,6 +50,3 @@ const build = async (api, options) => {
|
|
|
49
50
|
process.exit(1);
|
|
50
51
|
}
|
|
51
52
|
};
|
|
52
|
-
export {
|
|
53
|
-
build
|
|
54
|
-
};
|
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import { ResolvedConfigContext } from "@modern-js/core";
|
|
2
2
|
import { DEFAULT_DEV_HOST } from "@modern-js/utils";
|
|
3
3
|
import { printInstructions } from "../utils/printInstructions";
|
|
4
|
-
import {
|
|
5
|
-
setServer,
|
|
6
|
-
createServer,
|
|
7
|
-
injectDataLoaderPlugin
|
|
8
|
-
} from "../utils/createServer";
|
|
4
|
+
import { setServer, createServer, injectDataLoaderPlugin } from "../utils/createServer";
|
|
9
5
|
import { generateRoutes } from "../utils/routes";
|
|
10
6
|
import { buildServerConfig } from "../utils/config";
|
|
11
7
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
12
|
-
const dev = async (api, options) => {
|
|
13
|
-
var
|
|
8
|
+
export const dev = async (api, options) => {
|
|
9
|
+
var _normalizedConfig_tools;
|
|
14
10
|
if (options.analyze) {
|
|
15
11
|
process.env.BUNDLE_ANALYZE = "true";
|
|
16
12
|
}
|
|
17
13
|
let normalizedConfig = api.useResolvedConfigContext();
|
|
18
14
|
const appContext = api.useAppContext();
|
|
19
15
|
const hookRunners = api.useHookRunners();
|
|
20
|
-
normalizedConfig = {
|
|
16
|
+
normalizedConfig = {
|
|
17
|
+
...normalizedConfig,
|
|
18
|
+
cliOptions: options
|
|
19
|
+
};
|
|
21
20
|
ResolvedConfigContext.set(normalizedConfig);
|
|
22
21
|
const { appDirectory, distDirectory, port, apiOnly, serverConfigFile } = appContext;
|
|
23
22
|
await buildServerConfig({
|
|
@@ -32,9 +31,7 @@ const dev = async (api, options) => {
|
|
|
32
31
|
});
|
|
33
32
|
await hookRunners.beforeDev();
|
|
34
33
|
if (!appContext.builder && !apiOnly) {
|
|
35
|
-
throw new Error(
|
|
36
|
-
"Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
|
|
37
|
-
);
|
|
34
|
+
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
38
35
|
}
|
|
39
36
|
await generateRoutes(appContext);
|
|
40
37
|
const serverInternalPlugins = await getServerInternalPlugins(api);
|
|
@@ -43,7 +40,7 @@ const dev = async (api, options) => {
|
|
|
43
40
|
port,
|
|
44
41
|
https: normalizedConfig.dev.https,
|
|
45
42
|
host: normalizedConfig.dev.host,
|
|
46
|
-
...(
|
|
43
|
+
...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
|
|
47
44
|
},
|
|
48
45
|
appContext: {
|
|
49
46
|
appDirectory: appContext.appDirectory,
|
|
@@ -57,23 +54,21 @@ const dev = async (api, options) => {
|
|
|
57
54
|
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
|
|
58
55
|
};
|
|
59
56
|
if (apiOnly) {
|
|
57
|
+
var _normalizedConfig_dev;
|
|
60
58
|
const app = await createServer({
|
|
61
59
|
...serverOptions,
|
|
62
60
|
compiler: null
|
|
63
61
|
});
|
|
64
|
-
const host = ((
|
|
65
|
-
app.listen(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (err) {
|
|
72
|
-
throw err;
|
|
73
|
-
}
|
|
74
|
-
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
62
|
+
const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
|
|
63
|
+
app.listen({
|
|
64
|
+
port,
|
|
65
|
+
host
|
|
66
|
+
}, async (err) => {
|
|
67
|
+
if (err) {
|
|
68
|
+
throw err;
|
|
75
69
|
}
|
|
76
|
-
|
|
70
|
+
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
71
|
+
});
|
|
77
72
|
} else {
|
|
78
73
|
const { server } = await appContext.builder.startDevServer({
|
|
79
74
|
printURLs: false,
|
|
@@ -82,6 +77,3 @@ const dev = async (api, options) => {
|
|
|
82
77
|
setServer(server);
|
|
83
78
|
}
|
|
84
79
|
};
|
|
85
|
-
export {
|
|
86
|
-
dev
|
|
87
|
-
};
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { join } from "path";
|
|
2
|
-
const inspect = async (api, options) => {
|
|
2
|
+
export const inspect = async (api, options) => {
|
|
3
3
|
const appContext = api.useAppContext();
|
|
4
4
|
if (!appContext.builder) {
|
|
5
|
-
throw new Error(
|
|
6
|
-
"Expect the Builder to have been initialized, But the appContext.builder received `undefined`"
|
|
7
|
-
);
|
|
5
|
+
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
8
6
|
}
|
|
9
7
|
return appContext.builder.inspectConfig({
|
|
10
8
|
env: options.env,
|
|
11
9
|
verbose: options.verbose,
|
|
12
|
-
outputPath: join(appContext
|
|
10
|
+
outputPath: join(appContext === null || appContext === void 0 ? void 0 : appContext.builder.context.distPath, options.output),
|
|
13
11
|
writeToDisk: true
|
|
14
12
|
});
|
|
15
13
|
};
|
|
16
|
-
export {
|
|
17
|
-
inspect
|
|
18
|
-
};
|
|
@@ -3,17 +3,14 @@ import server from "@modern-js/prod-server";
|
|
|
3
3
|
import { printInstructions } from "../utils/printInstructions";
|
|
4
4
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
5
5
|
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
6
|
-
const start = async (api) => {
|
|
7
|
-
var
|
|
6
|
+
export const start = async (api) => {
|
|
7
|
+
var _userConfig_source, _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 } = appContext;
|
|
12
12
|
logger.log(chalk.cyan(`Starting the modern server...`));
|
|
13
|
-
const apiOnly = await isApiOnly(
|
|
14
|
-
appContext.appDirectory,
|
|
15
|
-
(_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.entriesDir
|
|
16
|
-
);
|
|
13
|
+
const apiOnly = await isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir);
|
|
17
14
|
const serverInternalPlugins = await getServerInternalPlugins(api);
|
|
18
15
|
const app = await server({
|
|
19
16
|
pwd: appDirectory,
|
|
@@ -21,26 +18,14 @@ const start = async (api) => {
|
|
|
21
18
|
...userConfig,
|
|
22
19
|
dev: userConfig.dev,
|
|
23
20
|
output: {
|
|
24
|
-
path: (
|
|
21
|
+
path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root,
|
|
25
22
|
...userConfig.output || {}
|
|
26
23
|
}
|
|
27
24
|
},
|
|
28
25
|
appContext: {
|
|
29
|
-
sharedDirectory: getTargetDir(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
appContext.distDirectory
|
|
33
|
-
),
|
|
34
|
-
apiDirectory: getTargetDir(
|
|
35
|
-
appContext.apiDirectory,
|
|
36
|
-
appContext.appDirectory,
|
|
37
|
-
appContext.distDirectory
|
|
38
|
-
),
|
|
39
|
-
lambdaDirectory: getTargetDir(
|
|
40
|
-
appContext.lambdaDirectory,
|
|
41
|
-
appContext.appDirectory,
|
|
42
|
-
appContext.distDirectory
|
|
43
|
-
)
|
|
26
|
+
sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
|
27
|
+
apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
|
28
|
+
lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
|
|
44
29
|
},
|
|
45
30
|
serverConfigFile,
|
|
46
31
|
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
|
|
@@ -53,6 +38,3 @@ const start = async (api) => {
|
|
|
53
38
|
await printInstructions(hookRunners, appContext, userConfig);
|
|
54
39
|
});
|
|
55
40
|
};
|
|
56
|
-
export {
|
|
57
|
-
start
|
|
58
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createDefaultConfig as createDefaultBuilderConfig } from "@modern-js/builder-webpack-provider";
|
|
2
2
|
import { getAutoInjectEnv } from "../utils/env";
|
|
3
|
-
function createDefaultConfig(appContext, bundler) {
|
|
3
|
+
export function createDefaultConfig(appContext, bundler) {
|
|
4
4
|
const defaultBuilderConfig = createDefaultBuilderConfig();
|
|
5
5
|
const dev = {
|
|
6
6
|
...defaultBuilderConfig.dev,
|
|
@@ -31,9 +31,14 @@ function createDefaultConfig(appContext, bundler) {
|
|
|
31
31
|
...defaultBuilderConfig.html,
|
|
32
32
|
title: "",
|
|
33
33
|
meta: {
|
|
34
|
-
charset: {
|
|
34
|
+
charset: {
|
|
35
|
+
charset: "utf-8"
|
|
36
|
+
},
|
|
35
37
|
viewport: "width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
|
|
36
|
-
"http-equiv": {
|
|
38
|
+
"http-equiv": {
|
|
39
|
+
"http-equiv": "x-ua-compatible",
|
|
40
|
+
content: "ie=edge"
|
|
41
|
+
},
|
|
37
42
|
renderer: "webkit",
|
|
38
43
|
layoutmode: "standard",
|
|
39
44
|
imagemode: "force",
|
|
@@ -65,7 +70,7 @@ function createDefaultConfig(appContext, bundler) {
|
|
|
65
70
|
runtimeByEntries: {}
|
|
66
71
|
};
|
|
67
72
|
}
|
|
68
|
-
function createLegacyDefaultConfig(appContext) {
|
|
73
|
+
export function createLegacyDefaultConfig(appContext) {
|
|
69
74
|
const defaultAlias = appContext ? {
|
|
70
75
|
[appContext.internalDirAlias]: appContext.internalDirectory,
|
|
71
76
|
[appContext.internalSrcAlias]: appContext.srcDirectory,
|
|
@@ -95,9 +100,14 @@ function createLegacyDefaultConfig(appContext) {
|
|
|
95
100
|
title: "",
|
|
96
101
|
titleByEntries: void 0,
|
|
97
102
|
meta: {
|
|
98
|
-
charset: {
|
|
103
|
+
charset: {
|
|
104
|
+
charset: "utf-8"
|
|
105
|
+
},
|
|
99
106
|
viewport: "width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
|
|
100
|
-
"http-equiv": {
|
|
107
|
+
"http-equiv": {
|
|
108
|
+
"http-equiv": "x-ua-compatible",
|
|
109
|
+
content: "ie=edge"
|
|
110
|
+
},
|
|
101
111
|
renderer: "webkit",
|
|
102
112
|
layoutmode: "standard",
|
|
103
113
|
imagemode: "force",
|
|
@@ -138,7 +148,10 @@ function createLegacyDefaultConfig(appContext) {
|
|
|
138
148
|
baseUrl: "/",
|
|
139
149
|
port: 8080
|
|
140
150
|
};
|
|
141
|
-
const devDefaults = {
|
|
151
|
+
const devDefaults = {
|
|
152
|
+
assetPrefix: false,
|
|
153
|
+
https: false
|
|
154
|
+
};
|
|
142
155
|
const toolsDefaults = {
|
|
143
156
|
webpack: void 0,
|
|
144
157
|
babel: void 0,
|
|
@@ -160,7 +173,3 @@ function createLegacyDefaultConfig(appContext) {
|
|
|
160
173
|
runtimeByEntries: {}
|
|
161
174
|
};
|
|
162
175
|
}
|
|
163
|
-
export {
|
|
164
|
-
createDefaultConfig,
|
|
165
|
-
createLegacyDefaultConfig
|
|
166
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { initHtmlConfig, initSourceConfig, initToolsConfig } from "./inits";
|
|
2
|
-
function initialNormalizedConfig(config, appContext, bundler) {
|
|
2
|
+
export function initialNormalizedConfig(config, appContext, bundler) {
|
|
3
3
|
initHtmlConfig(config, appContext);
|
|
4
4
|
initSourceConfig(config, appContext, bundler);
|
|
5
5
|
if (bundler === "webpack") {
|
|
@@ -7,6 +7,3 @@ function initialNormalizedConfig(config, appContext, bundler) {
|
|
|
7
7
|
}
|
|
8
8
|
return config;
|
|
9
9
|
}
|
|
10
|
-
export {
|
|
11
|
-
initialNormalizedConfig
|
|
12
|
-
};
|