@modern-js/app-tools 2.42.2 → 2.43.1-alpha.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/dist/cjs/analyze/generateCode.js +3 -3
- package/dist/cjs/analyze/templates.js +5 -1
- package/dist/cjs/analyze/utils.js +2 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +1 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/plugins/serverBuild.js +74 -0
- package/dist/esm/analyze/generateCode.js +4 -4
- package/dist/esm/analyze/templates.js +5 -1
- package/dist/esm/analyze/utils.js +2 -2
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/esm/index.js +2 -0
- package/dist/esm/plugins/serverBuild.js +70 -0
- package/dist/esm-node/analyze/generateCode.js +3 -3
- package/dist/esm-node/analyze/templates.js +5 -1
- package/dist/esm-node/analyze/utils.js +2 -2
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +1 -1
- package/dist/esm-node/index.js +2 -0
- package/dist/esm-node/plugins/serverBuild.js +44 -0
- package/dist/types/analyze/utils.d.ts +2 -2
- package/dist/types/plugins/serverBuild.d.ts +3 -0
- package/package.json +27 -26
@@ -85,7 +85,7 @@ ${initialize || ""}`);
|
|
85
85
|
${initialize || ""}`).join("\n");
|
86
86
|
};
|
87
87
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
88
|
-
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
88
|
+
const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
89
89
|
const hookRunners = api.useHookRunners();
|
90
90
|
const isV5 = (0, import_utils.isRouterV5)(config);
|
91
91
|
const getRoutes = isV5 ? import_getClientRoutes.getClientRoutesLegacy : import_getClientRoutes.getClientRoutes;
|
@@ -176,9 +176,9 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
176
176
|
imports: (0, import_utils2.getDefaultImports)({
|
177
177
|
entrypoint,
|
178
178
|
srcDirectory,
|
179
|
+
appDirectory,
|
179
180
|
internalSrcAlias,
|
180
|
-
internalDirAlias
|
181
|
-
internalDirectory
|
181
|
+
internalDirAlias
|
182
182
|
})
|
183
183
|
});
|
184
184
|
importsStatemets.set(entryName, imports);
|
@@ -277,7 +277,11 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
|
|
277
277
|
}
|
278
278
|
} else {
|
279
279
|
lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
280
|
-
if (
|
280
|
+
if (route.isRoot) {
|
281
|
+
lazyImport = `() => import('${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
282
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
283
|
+
component = `RootLayout`;
|
284
|
+
} else if (ssrMode === "string") {
|
281
285
|
component = `loadable(${lazyImport})`;
|
282
286
|
} else {
|
283
287
|
component = `lazy(${lazyImport})`;
|
@@ -61,7 +61,7 @@ const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previo
|
|
61
61
|
];
|
62
62
|
}
|
63
63
|
}, []);
|
64
|
-
const getDefaultImports = ({ entrypoint, srcDirectory, internalSrcAlias, internalDirAlias
|
64
|
+
const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias }) => {
|
65
65
|
const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
|
66
66
|
const imports = [
|
67
67
|
{
|
@@ -78,7 +78,7 @@ const getDefaultImports = ({ entrypoint, srcDirectory, internalSrcAlias, interna
|
|
78
78
|
local: "ReactDOM"
|
79
79
|
}
|
80
80
|
],
|
81
|
-
value: (0, import_utils.isReact18)(import_path.default.join(
|
81
|
+
value: (0, import_utils.isReact18)(import_path.default.join(appDirectory)) ? "react-dom/client" : "react-dom"
|
82
82
|
},
|
83
83
|
{
|
84
84
|
specifiers: [
|
@@ -73,7 +73,7 @@ function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugi
|
|
73
73
|
}
|
74
74
|
]);
|
75
75
|
}
|
76
|
-
chain.plugin(
|
76
|
+
chain.plugin("bottom-template").use(import_bundlerPlugins.BottomTemplatePlugin, [
|
77
77
|
HtmlBundlerPlugin
|
78
78
|
]);
|
79
79
|
}
|
@@ -53,7 +53,7 @@ const builderPluginAdapterSSR = (options) => ({
|
|
53
53
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
54
54
|
const builderConfig = api.getNormalizedConfig();
|
55
55
|
const { normalizedConfig: normalizedConfig2 } = options;
|
56
|
-
applyRouterPlugin(chain,
|
56
|
+
applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
|
57
57
|
if ((0, import_utils.isSSR)(normalizedConfig2)) {
|
58
58
|
await applySSRLoaderEntry(chain, options, isServer);
|
59
59
|
applySSRDataLoader(chain, options);
|
package/dist/cjs/index.js
CHANGED
@@ -46,6 +46,7 @@ var import_analyze = __toESM(require("./analyze"));
|
|
46
46
|
var import_initialize = __toESM(require("./initialize"));
|
47
47
|
var import_hooks = require("./hooks");
|
48
48
|
var import_locale = require("./locale");
|
49
|
+
var import_serverBuild = __toESM(require("./plugins/serverBuild"));
|
49
50
|
var import_restart = require("./utils/restart");
|
50
51
|
var import_generateWatchFiles = require("./utils/generateWatchFiles");
|
51
52
|
var import_core = require("@modern-js/core");
|
@@ -118,6 +119,7 @@ const appTools = (options = {
|
|
118
119
|
(0, import_analyze.default)({
|
119
120
|
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
120
121
|
}),
|
122
|
+
(0, import_serverBuild.default)(),
|
121
123
|
(0, import_plugin_lint.lintPlugin)()
|
122
124
|
],
|
123
125
|
setup: (api) => {
|
@@ -0,0 +1,74 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var serverBuild_exports = {};
|
30
|
+
__export(serverBuild_exports, {
|
31
|
+
default: () => serverBuild_default
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(serverBuild_exports);
|
34
|
+
var import_path = __toESM(require("path"));
|
35
|
+
var import_fs = __toESM(require("fs"));
|
36
|
+
var import_utils = require("@modern-js/utils");
|
37
|
+
var import_server_utils = require("@modern-js/server-utils");
|
38
|
+
const TS_CONFIG_FILENAME = "tsconfig.json";
|
39
|
+
var serverBuild_default = () => ({
|
40
|
+
name: "@modern-js/server-build",
|
41
|
+
setup(api) {
|
42
|
+
return {
|
43
|
+
async afterBuild() {
|
44
|
+
const { appDirectory, distDirectory } = api.useAppContext();
|
45
|
+
const modernConfig = api.useResolvedConfigContext();
|
46
|
+
const distDir = import_path.default.resolve(distDirectory);
|
47
|
+
const serverDir = import_path.default.resolve(appDirectory, import_utils.SERVER_DIR);
|
48
|
+
const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
|
49
|
+
const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
50
|
+
const sourceDirs = [];
|
51
|
+
if (import_fs.default.existsSync(serverDir)) {
|
52
|
+
sourceDirs.push(serverDir);
|
53
|
+
if (import_fs.default.existsSync(sharedDir)) {
|
54
|
+
sourceDirs.push(sharedDir);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
const { server } = modernConfig;
|
58
|
+
const { alias } = modernConfig.source;
|
59
|
+
const { babel } = modernConfig.tools;
|
60
|
+
if (sourceDirs.length > 0) {
|
61
|
+
await (0, import_server_utils.compile)(appDirectory, {
|
62
|
+
server,
|
63
|
+
alias,
|
64
|
+
babelConfig: babel
|
65
|
+
}, {
|
66
|
+
sourceDirs,
|
67
|
+
distDir,
|
68
|
+
tsconfigPath
|
69
|
+
});
|
70
|
+
}
|
71
|
+
}
|
72
|
+
};
|
73
|
+
}
|
74
|
+
});
|
@@ -94,7 +94,7 @@ var createImportStatements = function(statements) {
|
|
94
94
|
};
|
95
95
|
var generateCode = function() {
|
96
96
|
var _ref = _async_to_generator(function(appContext, config, entrypoints, api) {
|
97
|
-
var internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, getRoutes, importsStatemets, oldVersion;
|
97
|
+
var internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, getRoutes, importsStatemets, oldVersion;
|
98
98
|
function generateEntryCode(entrypoint) {
|
99
99
|
return _generateEntryCode.apply(this, arguments);
|
100
100
|
}
|
@@ -265,9 +265,9 @@ var generateCode = function() {
|
|
265
265
|
imports: getDefaultImports({
|
266
266
|
entrypoint,
|
267
267
|
srcDirectory,
|
268
|
+
appDirectory,
|
268
269
|
internalSrcAlias,
|
269
|
-
internalDirAlias
|
270
|
-
internalDirectory
|
270
|
+
internalDirAlias
|
271
271
|
})
|
272
272
|
})
|
273
273
|
];
|
@@ -289,7 +289,7 @@ var generateCode = function() {
|
|
289
289
|
return _ts_generator(this, function(_state) {
|
290
290
|
switch (_state.label) {
|
291
291
|
case 0:
|
292
|
-
internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
|
292
|
+
internalDirectory = appContext.internalDirectory, srcDirectory = appContext.srcDirectory, appDirectory = appContext.appDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
|
293
293
|
hookRunners = api.useHookRunners();
|
294
294
|
isV5 = isRouterV5(config);
|
295
295
|
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
@@ -222,7 +222,11 @@ var fileSystemRoutes = function() {
|
|
222
222
|
}
|
223
223
|
} else {
|
224
224
|
lazyImport = `() => import(/* webpackMode: "eager" */ '`.concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
|
225
|
-
if (
|
225
|
+
if (route2.isRoot) {
|
226
|
+
lazyImport = "() => import('".concat(route2._component, `').then(routeModule => handleRouteModule(routeModule, "`).concat(route2.id, '")).catch(handleRouteModuleError) ');
|
227
|
+
rootLayoutCode = "import RootLayout from '".concat(route2._component, "'");
|
228
|
+
component2 = "RootLayout";
|
229
|
+
} else if (ssrMode === "string") {
|
226
230
|
component2 = "loadable(".concat(lazyImport, ")");
|
227
231
|
} else {
|
228
232
|
component2 = "lazy(".concat(lazyImport, ")");
|
@@ -21,7 +21,7 @@ var walkDirectory = function(dir) {
|
|
21
21
|
}, []);
|
22
22
|
};
|
23
23
|
var getDefaultImports = function(param) {
|
24
|
-
var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory,
|
24
|
+
var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, appDirectory = param.appDirectory, internalSrcAlias = param.internalSrcAlias, internalDirAlias = param.internalDirAlias;
|
25
25
|
var entryName = entrypoint.entryName, fileSystemRoutes = entrypoint.fileSystemRoutes, customBootstrap = entrypoint.customBootstrap, entry = entrypoint.entry;
|
26
26
|
var imports = [
|
27
27
|
{
|
@@ -38,7 +38,7 @@ var getDefaultImports = function(param) {
|
|
38
38
|
local: "ReactDOM"
|
39
39
|
}
|
40
40
|
],
|
41
|
-
value: isReact18(path.join(
|
41
|
+
value: isReact18(path.join(appDirectory)) ? "react-dom/client" : "react-dom"
|
42
42
|
},
|
43
43
|
{
|
44
44
|
specifiers: [
|
@@ -29,7 +29,7 @@ var builderPluginAdapterSSR = function(options) {
|
|
29
29
|
target = param.target, CHAIN_ID = param.CHAIN_ID, isProd = param.isProd, HtmlBundlerPlugin = param.HtmlPlugin, isServer = param.isServer;
|
30
30
|
builderConfig = api.getNormalizedConfig();
|
31
31
|
normalizedConfig2 = options.normalizedConfig;
|
32
|
-
applyRouterPlugin(chain,
|
32
|
+
applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
|
33
33
|
if (!isSSR(normalizedConfig2))
|
34
34
|
return [
|
35
35
|
3,
|
package/dist/esm/index.js
CHANGED
@@ -11,6 +11,7 @@ import analyzePlugin from "./analyze";
|
|
11
11
|
import initializePlugin from "./initialize";
|
12
12
|
import { hooks } from "./hooks";
|
13
13
|
import { i18n, localeKeys } from "./locale";
|
14
|
+
import serverBuildPlugin from "./plugins/serverBuild";
|
14
15
|
import { restart } from "./utils/restart";
|
15
16
|
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
16
17
|
import { mergeConfig } from "@modern-js/core";
|
@@ -293,6 +294,7 @@ var appTools = function() {
|
|
293
294
|
analyzePlugin({
|
294
295
|
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
295
296
|
}),
|
297
|
+
serverBuildPlugin(),
|
296
298
|
lintPlugin()
|
297
299
|
],
|
298
300
|
setup: function(api) {
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import path from "path";
|
4
|
+
import fs from "fs";
|
5
|
+
import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
|
6
|
+
import { compile } from "@modern-js/server-utils";
|
7
|
+
var TS_CONFIG_FILENAME = "tsconfig.json";
|
8
|
+
function serverBuild_default() {
|
9
|
+
return {
|
10
|
+
name: "@modern-js/server-build",
|
11
|
+
setup: function setup(api) {
|
12
|
+
return {
|
13
|
+
afterBuild: function afterBuild() {
|
14
|
+
return _async_to_generator(function() {
|
15
|
+
var _api_useAppContext, appDirectory, distDirectory, modernConfig, distDir, serverDir, sharedDir, tsconfigPath, sourceDirs, server, alias, babel;
|
16
|
+
return _ts_generator(this, function(_state) {
|
17
|
+
switch (_state.label) {
|
18
|
+
case 0:
|
19
|
+
_api_useAppContext = api.useAppContext(), appDirectory = _api_useAppContext.appDirectory, distDirectory = _api_useAppContext.distDirectory;
|
20
|
+
modernConfig = api.useResolvedConfigContext();
|
21
|
+
distDir = path.resolve(distDirectory);
|
22
|
+
serverDir = path.resolve(appDirectory, SERVER_DIR);
|
23
|
+
sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
24
|
+
tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
25
|
+
sourceDirs = [];
|
26
|
+
if (fs.existsSync(serverDir)) {
|
27
|
+
sourceDirs.push(serverDir);
|
28
|
+
if (fs.existsSync(sharedDir)) {
|
29
|
+
sourceDirs.push(sharedDir);
|
30
|
+
}
|
31
|
+
}
|
32
|
+
server = modernConfig.server;
|
33
|
+
alias = modernConfig.source.alias;
|
34
|
+
babel = modernConfig.tools.babel;
|
35
|
+
if (!(sourceDirs.length > 0))
|
36
|
+
return [
|
37
|
+
3,
|
38
|
+
2
|
39
|
+
];
|
40
|
+
return [
|
41
|
+
4,
|
42
|
+
compile(appDirectory, {
|
43
|
+
server,
|
44
|
+
alias,
|
45
|
+
babelConfig: babel
|
46
|
+
}, {
|
47
|
+
sourceDirs,
|
48
|
+
distDir,
|
49
|
+
tsconfigPath
|
50
|
+
})
|
51
|
+
];
|
52
|
+
case 1:
|
53
|
+
_state.sent();
|
54
|
+
_state.label = 2;
|
55
|
+
case 2:
|
56
|
+
return [
|
57
|
+
2
|
58
|
+
];
|
59
|
+
}
|
60
|
+
});
|
61
|
+
})();
|
62
|
+
}
|
63
|
+
};
|
64
|
+
}
|
65
|
+
};
|
66
|
+
}
|
67
|
+
;
|
68
|
+
export {
|
69
|
+
serverBuild_default as default
|
70
|
+
};
|
@@ -50,7 +50,7 @@ ${initialize || ""}`);
|
|
50
50
|
${initialize || ""}`).join("\n");
|
51
51
|
};
|
52
52
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
53
|
-
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
53
|
+
const { internalDirectory, srcDirectory, appDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
54
54
|
const hookRunners = api.useHookRunners();
|
55
55
|
const isV5 = isRouterV5(config);
|
56
56
|
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
@@ -141,9 +141,9 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
141
141
|
imports: getDefaultImports({
|
142
142
|
entrypoint,
|
143
143
|
srcDirectory,
|
144
|
+
appDirectory,
|
144
145
|
internalSrcAlias,
|
145
|
-
internalDirAlias
|
146
|
-
internalDirectory
|
146
|
+
internalDirAlias
|
147
147
|
})
|
148
148
|
});
|
149
149
|
importsStatemets.set(entryName, imports);
|
@@ -239,7 +239,11 @@ const fileSystemRoutes = async ({ routes, ssrMode, nestedRoutesEntry, entryName,
|
|
239
239
|
}
|
240
240
|
} else {
|
241
241
|
lazyImport = `() => import(/* webpackMode: "eager" */ '${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
242
|
-
if (
|
242
|
+
if (route.isRoot) {
|
243
|
+
lazyImport = `() => import('${route._component}').then(routeModule => handleRouteModule(routeModule, "${route.id}")).catch(handleRouteModuleError) `;
|
244
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
245
|
+
component = `RootLayout`;
|
246
|
+
} else if (ssrMode === "string") {
|
243
247
|
component = `loadable(${lazyImport})`;
|
244
248
|
} else {
|
245
249
|
component = `lazy(${lazyImport})`;
|
@@ -18,7 +18,7 @@ const walkDirectory = (dir) => fs.readdirSync(dir).reduce((previous, filename) =
|
|
18
18
|
];
|
19
19
|
}
|
20
20
|
}, []);
|
21
|
-
const getDefaultImports = ({ entrypoint, srcDirectory, internalSrcAlias, internalDirAlias
|
21
|
+
const getDefaultImports = ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias }) => {
|
22
22
|
const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
|
23
23
|
const imports = [
|
24
24
|
{
|
@@ -35,7 +35,7 @@ const getDefaultImports = ({ entrypoint, srcDirectory, internalSrcAlias, interna
|
|
35
35
|
local: "ReactDOM"
|
36
36
|
}
|
37
37
|
],
|
38
|
-
value: isReact18(path.join(
|
38
|
+
value: isReact18(path.join(appDirectory)) ? "react-dom/client" : "react-dom"
|
39
39
|
},
|
40
40
|
{
|
41
41
|
specifiers: [
|
@@ -50,7 +50,7 @@ function applyBottomHtmlPlugin({ api, chain, options, CHAIN_ID, HtmlBundlerPlugi
|
|
50
50
|
}
|
51
51
|
]);
|
52
52
|
}
|
53
|
-
chain.plugin(
|
53
|
+
chain.plugin("bottom-template").use(BottomTemplatePlugin, [
|
54
54
|
HtmlBundlerPlugin
|
55
55
|
]);
|
56
56
|
}
|
@@ -20,7 +20,7 @@ const builderPluginAdapterSSR = (options) => ({
|
|
20
20
|
api.modifyBundlerChain(async (chain, { target, CHAIN_ID, isProd, HtmlPlugin: HtmlBundlerPlugin, isServer }) => {
|
21
21
|
const builderConfig = api.getNormalizedConfig();
|
22
22
|
const { normalizedConfig: normalizedConfig2 } = options;
|
23
|
-
applyRouterPlugin(chain,
|
23
|
+
applyRouterPlugin(chain, "route-plugin", options, HtmlBundlerPlugin);
|
24
24
|
if (isSSR(normalizedConfig2)) {
|
25
25
|
await applySSRLoaderEntry(chain, options, isServer);
|
26
26
|
applySSRDataLoader(chain, options);
|
package/dist/esm-node/index.js
CHANGED
@@ -7,6 +7,7 @@ import analyzePlugin from "./analyze";
|
|
7
7
|
import initializePlugin from "./initialize";
|
8
8
|
import { hooks } from "./hooks";
|
9
9
|
import { i18n, localeKeys } from "./locale";
|
10
|
+
import serverBuildPlugin from "./plugins/serverBuild";
|
10
11
|
import { restart } from "./utils/restart";
|
11
12
|
import { generateWatchFiles } from "./utils/generateWatchFiles";
|
12
13
|
import { mergeConfig } from "@modern-js/core";
|
@@ -79,6 +80,7 @@ const appTools = (options = {
|
|
79
80
|
analyzePlugin({
|
80
81
|
bundler: (options === null || options === void 0 ? void 0 : options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
81
82
|
}),
|
83
|
+
serverBuildPlugin(),
|
82
84
|
lintPlugin()
|
83
85
|
],
|
84
86
|
setup: (api) => {
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import path from "path";
|
2
|
+
import fs from "fs";
|
3
|
+
import { SERVER_DIR, SHARED_DIR } from "@modern-js/utils";
|
4
|
+
import { compile } from "@modern-js/server-utils";
|
5
|
+
const TS_CONFIG_FILENAME = "tsconfig.json";
|
6
|
+
var serverBuild_default = () => ({
|
7
|
+
name: "@modern-js/server-build",
|
8
|
+
setup(api) {
|
9
|
+
return {
|
10
|
+
async afterBuild() {
|
11
|
+
const { appDirectory, distDirectory } = api.useAppContext();
|
12
|
+
const modernConfig = api.useResolvedConfigContext();
|
13
|
+
const distDir = path.resolve(distDirectory);
|
14
|
+
const serverDir = path.resolve(appDirectory, SERVER_DIR);
|
15
|
+
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
16
|
+
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
17
|
+
const sourceDirs = [];
|
18
|
+
if (fs.existsSync(serverDir)) {
|
19
|
+
sourceDirs.push(serverDir);
|
20
|
+
if (fs.existsSync(sharedDir)) {
|
21
|
+
sourceDirs.push(sharedDir);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
const { server } = modernConfig;
|
25
|
+
const { alias } = modernConfig.source;
|
26
|
+
const { babel } = modernConfig.tools;
|
27
|
+
if (sourceDirs.length > 0) {
|
28
|
+
await compile(appDirectory, {
|
29
|
+
server,
|
30
|
+
alias,
|
31
|
+
babelConfig: babel
|
32
|
+
}, {
|
33
|
+
sourceDirs,
|
34
|
+
distDir,
|
35
|
+
tsconfigPath
|
36
|
+
});
|
37
|
+
}
|
38
|
+
}
|
39
|
+
};
|
40
|
+
}
|
41
|
+
});
|
42
|
+
export {
|
43
|
+
serverBuild_default as default
|
44
|
+
};
|
@@ -1,12 +1,12 @@
|
|
1
1
|
import type { Entrypoint } from '@modern-js/types';
|
2
2
|
import type { ImportStatement } from '../types';
|
3
3
|
export declare const walkDirectory: (dir: string) => string[];
|
4
|
-
export declare const getDefaultImports: ({ entrypoint, srcDirectory, internalSrcAlias, internalDirAlias,
|
4
|
+
export declare const getDefaultImports: ({ entrypoint, srcDirectory, appDirectory, internalSrcAlias, internalDirAlias, }: {
|
5
5
|
entrypoint: Entrypoint;
|
6
6
|
srcDirectory: string;
|
7
|
+
appDirectory: string;
|
7
8
|
internalSrcAlias: string;
|
8
9
|
internalDirAlias: string;
|
9
|
-
internalDirectory: string;
|
10
10
|
}) => ImportStatement[];
|
11
11
|
export declare const isPageComponentFile: (filePath: string) => boolean;
|
12
12
|
export declare const replaceWithAlias: (base: string, filePath: string, alias: string) => string;
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.
|
18
|
+
"version": "2.43.1-alpha.0",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -68,28 +68,29 @@
|
|
68
68
|
"dependencies": {
|
69
69
|
"@babel/parser": "^7.22.15",
|
70
70
|
"@babel/traverse": "^7.23.2",
|
71
|
-
"@babel/types": "^7.
|
71
|
+
"@babel/types": "^7.23.0",
|
72
72
|
"es-module-lexer": "^1.1.0",
|
73
73
|
"esbuild": "0.17.19",
|
74
74
|
"@swc/helpers": "0.5.3",
|
75
|
-
"@modern-js/builder": "2.
|
76
|
-
"@modern-js/builder
|
77
|
-
"@modern-js/builder-plugin-
|
78
|
-
"@modern-js/builder-
|
79
|
-
"@modern-js/
|
80
|
-
"@modern-js/
|
81
|
-
"@modern-js/new-action": "2.
|
82
|
-
"@modern-js/
|
83
|
-
"@modern-js/
|
84
|
-
"@modern-js/
|
85
|
-
"@modern-js/
|
86
|
-
"@modern-js/
|
87
|
-
"@modern-js/
|
88
|
-
"@modern-js/
|
89
|
-
"@modern-js/
|
90
|
-
"@modern-js/
|
91
|
-
"@modern-js/
|
92
|
-
"@modern-js/
|
75
|
+
"@modern-js/builder-plugin-esbuild": "2.43.0",
|
76
|
+
"@modern-js/builder": "2.43.0",
|
77
|
+
"@modern-js/builder-plugin-node-polyfill": "2.43.0",
|
78
|
+
"@modern-js/builder-shared": "2.43.0",
|
79
|
+
"@modern-js/builder-webpack-provider": "2.43.0",
|
80
|
+
"@modern-js/core": "2.43.0",
|
81
|
+
"@modern-js/new-action": "2.43.0",
|
82
|
+
"@modern-js/prod-server": "2.43.0",
|
83
|
+
"@modern-js/server": "2.43.0",
|
84
|
+
"@modern-js/server-utils": "2.43.0",
|
85
|
+
"@modern-js/types": "2.43.0",
|
86
|
+
"@modern-js/upgrade": "2.43.0",
|
87
|
+
"@modern-js/plugin-lint": "2.43.0",
|
88
|
+
"@modern-js/utils": "2.43.0",
|
89
|
+
"@modern-js/server-core": "2.43.0",
|
90
|
+
"@modern-js/node-bundle-require": "2.43.0",
|
91
|
+
"@modern-js/plugin": "2.43.0",
|
92
|
+
"@modern-js/plugin-i18n": "2.43.0",
|
93
|
+
"@modern-js/plugin-data-loader": "2.43.0"
|
93
94
|
},
|
94
95
|
"devDependencies": {
|
95
96
|
"@types/babel__traverse": "7.18.5",
|
@@ -97,14 +98,14 @@
|
|
97
98
|
"@types/node": "^14",
|
98
99
|
"jest": "^29",
|
99
100
|
"typescript": "^5",
|
100
|
-
"webpack": "^5.
|
101
|
-
"@modern-js/builder-
|
102
|
-
"@modern-js/builder-
|
103
|
-
"@scripts/build": "2.
|
104
|
-
"@scripts/jest-config": "2.
|
101
|
+
"webpack": "^5.89.0",
|
102
|
+
"@modern-js/builder-rspack-provider": "2.43.0",
|
103
|
+
"@modern-js/builder-plugin-swc": "2.43.0",
|
104
|
+
"@scripts/build": "2.43.0",
|
105
|
+
"@scripts/jest-config": "2.43.0"
|
105
106
|
},
|
106
107
|
"peerDependencies": {
|
107
|
-
"@modern-js/builder-rspack-provider": "^2.
|
108
|
+
"@modern-js/builder-rspack-provider": "^2.43.0"
|
108
109
|
},
|
109
110
|
"peerDependenciesMeta": {
|
110
111
|
"@modern-js/builder-rspack-provider": {
|