@modern-js/app-tools 2.7.0 → 2.8.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 +53 -2
- package/README.md +2 -2
- package/dist/cjs/analyze/generateCode.js +16 -2
- package/dist/cjs/analyze/index.js +0 -32
- package/dist/cjs/analyze/templates.js +26 -2
- package/dist/cjs/analyze/utils.js +5 -0
- package/dist/cjs/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
- package/dist/cjs/builder/generator/index.js +10 -2
- package/dist/cjs/builder/index.js +1 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterBasic.js +101 -0
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +91 -0
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +164 -0
- package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/builderPlugins}/index.js +5 -3
- package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
- package/dist/cjs/builder/shared/bundlerPlugins/index.js +19 -0
- package/dist/cjs/builder/shared/index.js +1 -1
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/locale/en.js +1 -0
- package/dist/cjs/locale/zh.js +1 -0
- package/dist/esm/analyze/generateCode.js +34 -19
- package/dist/esm/analyze/index.js +2 -25
- package/dist/esm/analyze/templates.js +16 -2
- package/dist/esm/analyze/utils.js +4 -1
- package/dist/esm/builder/builder-webpack/builderPlugins/compatModern.js +0 -11
- package/dist/esm/builder/generator/index.js +6 -4
- package/dist/esm/builder/index.js +1 -1
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +101 -0
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +120 -0
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +350 -0
- package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +10 -6
- package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm/builder/shared/index.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/locale/en.js +1 -0
- package/dist/esm/locale/zh.js +1 -0
- package/dist/esm-node/analyze/generateCode.js +29 -4
- package/dist/esm-node/analyze/index.js +1 -39
- package/dist/esm-node/analyze/templates.js +25 -2
- package/dist/esm-node/analyze/utils.js +4 -0
- package/dist/esm-node/builder/builder-webpack/builderPlugins/compatModern.js +2 -13
- package/dist/esm-node/builder/generator/index.js +10 -2
- package/dist/esm-node/builder/index.js +1 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +67 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +67 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +143 -0
- package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm-node/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js +11 -5
- package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/index.js +1 -1
- package/dist/esm-node/index.js +1 -1
- package/dist/esm-node/locale/en.js +1 -0
- package/dist/esm-node/locale/zh.js +1 -0
- package/dist/types/analyze/templates.d.ts +3 -2
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/builder/shared/builderPlugins/adapterBasic.d.ts +7 -0
- package/dist/types/builder/shared/builderPlugins/adapterHtml.d.ts +5 -0
- package/dist/types/builder/shared/builderPlugins/adapterSSR.d.ts +4 -0
- package/dist/types/builder/shared/builderPlugins/index.d.ts +3 -0
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +5 -0
- package/dist/types/builder/shared/bundlerPlugins/index.d.ts +3 -0
- package/dist/types/builder/shared/index.d.ts +1 -1
- package/dist/types/builder/shared/types.d.ts +7 -4
- package/dist/types/locale/en.d.ts +1 -0
- package/dist/types/locale/index.d.ts +2 -0
- package/dist/types/locale/zh.d.ts +1 -0
- package/dist/types/types/config/output.d.ts +2 -15
- package/package.json +26 -26
- package/dist/cjs/builder/shared/builderPlugins/adapterModern.js +0 -234
- package/dist/esm/builder/builder-webpack/webpackPlugins/index.js +0 -1
- package/dist/esm/builder/shared/builderPlugins/adapterModern.js +0 -300
- package/dist/esm-node/builder/builder-webpack/webpackPlugins/index.js +0 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterModern.js +0 -202
- package/dist/types/builder/builder-webpack/webpackPlugins/RouterPlugin.d.ts +0 -4
- package/dist/types/builder/builder-webpack/webpackPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/builderPlugins/adapterModern.d.ts +0 -13
|
@@ -12,6 +12,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
12
12
|
};
|
|
13
13
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
-
var
|
|
16
|
-
module.exports = __toCommonJS(
|
|
17
|
-
__reExport(
|
|
15
|
+
var builderPlugins_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(builderPlugins_exports);
|
|
17
|
+
__reExport(builderPlugins_exports, require("./adapterBasic"), module.exports);
|
|
18
|
+
__reExport(builderPlugins_exports, require("./adapterHtml"), module.exports);
|
|
19
|
+
__reExport(builderPlugins_exports, require("./adapterSSR"), module.exports);
|
package/dist/cjs/builder/{builder-webpack/webpackPlugins → shared/bundlerPlugins}/RouterPlugin.js
RENAMED
|
@@ -65,7 +65,7 @@ class RouterPlugin {
|
|
|
65
65
|
chunkGroups: true,
|
|
66
66
|
chunks: true
|
|
67
67
|
});
|
|
68
|
-
const { publicPath } = stats;
|
|
68
|
+
const { publicPath, chunks = [] } = stats;
|
|
69
69
|
const routeAssets = {};
|
|
70
70
|
const { namedChunkGroups, assetsByChunkName } = stats;
|
|
71
71
|
if (!namedChunkGroups || !assetsByChunkName) {
|
|
@@ -98,17 +98,23 @@ class RouterPlugin {
|
|
|
98
98
|
const entryChunkIds = entrypointsArray.map(
|
|
99
99
|
(entrypoint) => entrypoint[0]
|
|
100
100
|
);
|
|
101
|
-
const entryChunks = [...
|
|
102
|
-
|
|
101
|
+
const entryChunks = [...chunks].filter((chunk) => {
|
|
102
|
+
var _a;
|
|
103
|
+
return (_a = chunk.names) == null ? void 0 : _a.some((name) => entryChunkIds.includes(name));
|
|
103
104
|
});
|
|
104
105
|
const entryChunkFiles = entryChunks.map(
|
|
105
|
-
(chunk) => [...chunk.files].find((fname) => fname.includes(".js"))
|
|
106
|
+
(chunk) => [...chunk.files || []].find((fname) => fname.includes(".js"))
|
|
106
107
|
);
|
|
107
108
|
for (const file of entryChunkFiles) {
|
|
108
109
|
const asset = compilation.assets[file];
|
|
109
110
|
const newContent = `${injectedContent}${asset.source().toString()}`;
|
|
110
111
|
newAssetsMap.set(import_path.default.join(outputPath, file), newContent);
|
|
111
|
-
compilation.updateAsset(
|
|
112
|
+
compilation.updateAsset(
|
|
113
|
+
file,
|
|
114
|
+
new RawSource(newContent),
|
|
115
|
+
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
|
116
|
+
void 0
|
|
117
|
+
);
|
|
112
118
|
}
|
|
113
119
|
const filename = import_path.default.join(outputPath, import_utils.ROUTE_MINIFEST_FILE);
|
|
114
120
|
await import_utils.fs.ensureFile(filename);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var bundlerPlugins_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(bundlerPlugins_exports);
|
|
17
|
+
__reExport(bundlerPlugins_exports, require("./HtmlAsyncChunkPlugin"), module.exports);
|
|
18
|
+
__reExport(bundlerPlugins_exports, require("./HtmlBottomTemplate"), module.exports);
|
|
19
|
+
__reExport(bundlerPlugins_exports, require("./RouterPlugin"), module.exports);
|
|
@@ -16,4 +16,4 @@ var shared_exports = {};
|
|
|
16
16
|
module.exports = __toCommonJS(shared_exports);
|
|
17
17
|
__reExport(shared_exports, require("./createCopyPattern"), module.exports);
|
|
18
18
|
__reExport(shared_exports, require("./types"), module.exports);
|
|
19
|
-
__reExport(shared_exports, require("./builderPlugins
|
|
19
|
+
__reExport(shared_exports, require("./builderPlugins"), module.exports);
|
package/dist/cjs/index.js
CHANGED
|
@@ -53,7 +53,7 @@ const upgradeModel = import_utils.Import.lazy(
|
|
|
53
53
|
const devCommand = async (program, api) => {
|
|
54
54
|
const runner = api.useHookRunners();
|
|
55
55
|
const devToolMetas = await runner.registerDev();
|
|
56
|
-
const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).action(async (options) => {
|
|
56
|
+
const devProgram = program.command("dev").alias("start").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.dev.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("-e --entry [entry...]", import_locale.i18n.t(import_locale.localeKeys.command.dev.entry)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).option("--api-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.apiOnly)).option("--web-only", import_locale.i18n.t(import_locale.localeKeys.command.dev.webOnly)).action(async (options) => {
|
|
57
57
|
const { dev } = await Promise.resolve().then(() => __toESM(require("./commands/dev")));
|
|
58
58
|
await dev(api, options);
|
|
59
59
|
});
|
package/dist/cjs/locale/en.js
CHANGED
|
@@ -30,6 +30,7 @@ const EN_LOCALE = {
|
|
|
30
30
|
describe: "start dev server",
|
|
31
31
|
entry: "compiler by entry",
|
|
32
32
|
apiOnly: "start api server only",
|
|
33
|
+
webOnly: "start web server only",
|
|
33
34
|
selectEntry: "Please select the entry that needs to be built",
|
|
34
35
|
requireEntry: "You must choose at least one entry"
|
|
35
36
|
},
|
package/dist/cjs/locale/zh.js
CHANGED
|
@@ -148,11 +148,11 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
148
148
|
}
|
|
149
149
|
};
|
|
150
150
|
import path from "path";
|
|
151
|
-
import { fs, getEntryOptions, isRouterV5, logger } from "@modern-js/utils";
|
|
151
|
+
import { fs, getEntryOptions, isRouterV5, isSSGEntry, isUseSSRBundle, logger } from "@modern-js/utils";
|
|
152
152
|
import * as templates from "./templates";
|
|
153
153
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
154
154
|
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
155
|
-
import { getDefaultImports, getServerLoadersFile } from "./utils";
|
|
155
|
+
import { getDefaultImports, getServerLoadersFile, getServerCombinedModueFile } from "./utils";
|
|
156
156
|
import { walk } from "./nestedRoutes";
|
|
157
157
|
var createImportSpecifier = function(specifiers) {
|
|
158
158
|
var defaults = "";
|
|
@@ -245,18 +245,18 @@ var generateCode = function() {
|
|
|
245
245
|
}
|
|
246
246
|
function _generateEntryCode() {
|
|
247
247
|
_generateEntryCode = _asyncToGenerator(function(entrypoint) {
|
|
248
|
-
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
|
|
248
|
+
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, useSSG, mode, hasPageRoute, _ref, code2, _, _tmp, routesServerFile, code3, serverLoaderCombined, serverLoaderFile, _ref1, importStatements, plugins, _ref2, renderFunction, exportStatement, code, entryFile, _ref3, asyncEntryCode, bootstrapFile;
|
|
249
249
|
return __generator(this, function(_state) {
|
|
250
250
|
switch(_state.label){
|
|
251
251
|
case 0:
|
|
252
252
|
entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
253
253
|
if (!isAutoMount) return [
|
|
254
254
|
3,
|
|
255
|
-
|
|
255
|
+
18
|
|
256
256
|
];
|
|
257
257
|
if (!fileSystemRoutes) return [
|
|
258
258
|
3,
|
|
259
|
-
|
|
259
|
+
11
|
|
260
260
|
];
|
|
261
261
|
initialRoutes = [];
|
|
262
262
|
nestedRoute = null;
|
|
@@ -298,6 +298,7 @@ var generateCode = function() {
|
|
|
298
298
|
routes = _state.sent().routes;
|
|
299
299
|
config2 = api.useResolvedConfigContext();
|
|
300
300
|
ssr = getEntryOptions(entryName, config2.server.ssr, config2.server.ssrByEntries, packageName);
|
|
301
|
+
useSSG = isSSGEntry(config2, entryName, entrypoints);
|
|
301
302
|
if (ssr) {
|
|
302
303
|
mode = typeof ssr === "object" ? ssr.mode || "string" : "string";
|
|
303
304
|
}
|
|
@@ -318,7 +319,7 @@ var generateCode = function() {
|
|
|
318
319
|
4,
|
|
319
320
|
templates.fileSystemRoutes({
|
|
320
321
|
routes: routes,
|
|
321
|
-
ssrMode: mode,
|
|
322
|
+
ssrMode: useSSG ? "string" : mode,
|
|
322
323
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
323
324
|
entryName: entrypoint.entryName,
|
|
324
325
|
internalDirectory: internalDirectory
|
|
@@ -333,7 +334,7 @@ var generateCode = function() {
|
|
|
333
334
|
];
|
|
334
335
|
case 5:
|
|
335
336
|
_ref = _state.sent(), code2 = _ref.code;
|
|
336
|
-
if (!(entrypoint.nestedRoutesEntry &&
|
|
337
|
+
if (!(entrypoint.nestedRoutesEntry && isUseSSRBundle(config2))) return [
|
|
337
338
|
3,
|
|
338
339
|
8
|
|
339
340
|
];
|
|
@@ -355,9 +356,23 @@ var generateCode = function() {
|
|
|
355
356
|
_state.sent();
|
|
356
357
|
_state.label = 8;
|
|
357
358
|
case 8:
|
|
358
|
-
|
|
359
|
-
|
|
359
|
+
serverLoaderCombined = templates.ssrLoaderCombinedModule(entrypoints, entrypoint, config2, appContext);
|
|
360
|
+
if (!serverLoaderCombined) return [
|
|
361
|
+
3,
|
|
362
|
+
10
|
|
363
|
+
];
|
|
364
|
+
serverLoaderFile = getServerCombinedModueFile(internalDirectory, entryName);
|
|
365
|
+
return [
|
|
366
|
+
4,
|
|
367
|
+
fs.outputFile(serverLoaderFile, serverLoaderCombined)
|
|
368
|
+
];
|
|
360
369
|
case 9:
|
|
370
|
+
_state.sent();
|
|
371
|
+
_state.label = 10;
|
|
372
|
+
case 10:
|
|
373
|
+
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
|
|
374
|
+
_state.label = 11;
|
|
375
|
+
case 11:
|
|
361
376
|
return [
|
|
362
377
|
4,
|
|
363
378
|
hookRunners.modifyEntryImports({
|
|
@@ -371,7 +386,7 @@ var generateCode = function() {
|
|
|
371
386
|
})
|
|
372
387
|
})
|
|
373
388
|
];
|
|
374
|
-
case
|
|
389
|
+
case 12:
|
|
375
390
|
_ref1 = _state.sent(), importStatements = _ref1.imports;
|
|
376
391
|
return [
|
|
377
392
|
4,
|
|
@@ -380,7 +395,7 @@ var generateCode = function() {
|
|
|
380
395
|
plugins: []
|
|
381
396
|
})
|
|
382
397
|
];
|
|
383
|
-
case
|
|
398
|
+
case 13:
|
|
384
399
|
plugins = _state.sent().plugins;
|
|
385
400
|
return [
|
|
386
401
|
4,
|
|
@@ -393,7 +408,7 @@ var generateCode = function() {
|
|
|
393
408
|
})
|
|
394
409
|
})
|
|
395
410
|
];
|
|
396
|
-
case
|
|
411
|
+
case 14:
|
|
397
412
|
_ref2 = _state.sent(), renderFunction = _ref2.code;
|
|
398
413
|
return [
|
|
399
414
|
4,
|
|
@@ -402,7 +417,7 @@ var generateCode = function() {
|
|
|
402
417
|
exportStatement: "export default AppWrapper;"
|
|
403
418
|
})
|
|
404
419
|
];
|
|
405
|
-
case
|
|
420
|
+
case 15:
|
|
406
421
|
exportStatement = _state.sent().exportStatement;
|
|
407
422
|
code = templates.index({
|
|
408
423
|
mountId: mountId,
|
|
@@ -414,7 +429,7 @@ var generateCode = function() {
|
|
|
414
429
|
entrypoint.entry = entryFile;
|
|
415
430
|
if (!config.source.enableAsyncEntry) return [
|
|
416
431
|
3,
|
|
417
|
-
|
|
432
|
+
17
|
|
418
433
|
];
|
|
419
434
|
return [
|
|
420
435
|
4,
|
|
@@ -423,19 +438,19 @@ var generateCode = function() {
|
|
|
423
438
|
code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
|
|
424
439
|
})
|
|
425
440
|
];
|
|
426
|
-
case
|
|
441
|
+
case 16:
|
|
427
442
|
_ref3 = _state.sent(), asyncEntryCode = _ref3.code;
|
|
428
443
|
fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
|
|
429
444
|
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
430
445
|
fs.outputFileSync(bootstrapFile, code, "utf8");
|
|
431
446
|
return [
|
|
432
447
|
3,
|
|
433
|
-
|
|
448
|
+
18
|
|
434
449
|
];
|
|
435
|
-
case
|
|
450
|
+
case 17:
|
|
436
451
|
fs.outputFileSync(entryFile, code, "utf8");
|
|
437
|
-
_state.label =
|
|
438
|
-
case
|
|
452
|
+
_state.label = 18;
|
|
453
|
+
case 18:
|
|
439
454
|
return [
|
|
440
455
|
2
|
|
441
456
|
];
|
|
@@ -221,16 +221,15 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
import * as path from "path";
|
|
224
|
-
import { createDebugger, findExists, fs,
|
|
224
|
+
import { createDebugger, findExists, fs, isApiOnly, minimist, getCommand, isDevCommand } from "@modern-js/utils";
|
|
225
225
|
import { cloneDeep } from "@modern-js/utils/lodash";
|
|
226
|
-
import { createVirtualModule } from "@modern-js/builder-shared";
|
|
227
226
|
import { printInstructions } from "../utils/printInstructions";
|
|
228
227
|
import { generateRoutes } from "../utils/routes";
|
|
229
228
|
import { emitResolvedConfig } from "../utils/config";
|
|
230
229
|
import { getSelectedEntries } from "../utils/getSelectedEntries";
|
|
231
230
|
import { initialNormalizedConfig } from "../config";
|
|
232
231
|
import { createBuilderGenerator } from "../builder";
|
|
233
|
-
import {
|
|
232
|
+
import { isPageComponentFile, parseModule, replaceWithAlias } from "./utils";
|
|
234
233
|
import { APP_CONFIG_NAME, APP_INIT_EXPORTED, APP_INIT_IMPORTED } from "./constants";
|
|
235
234
|
var debug = createDebugger("plugin-analyze");
|
|
236
235
|
var analyze_default = function(param) {
|
|
@@ -543,28 +542,6 @@ var analyze_default = function(param) {
|
|
|
543
542
|
watchFiles: function watchFiles() {
|
|
544
543
|
return pagesDir;
|
|
545
544
|
},
|
|
546
|
-
config: function config() {
|
|
547
|
-
return {
|
|
548
|
-
tools: {
|
|
549
|
-
webpackChain: function(chain, param) {
|
|
550
|
-
var name = param.name;
|
|
551
|
-
var appContext = api.useAppContext();
|
|
552
|
-
var resolvedConfig = api.useResolvedConfigContext();
|
|
553
|
-
var entrypoints = appContext.entrypoints, internalDirectory = appContext.internalDirectory, packageName = appContext.packageName;
|
|
554
|
-
entrypoints.forEach(function(entrypoint) {
|
|
555
|
-
var entryName = entrypoint.entryName;
|
|
556
|
-
var ssr = getEntryOptions(entryName, resolvedConfig.server.ssr, resolvedConfig.server.ssrByEntries, packageName);
|
|
557
|
-
if (entrypoint.nestedRoutesEntry && ssr && name === "server") {
|
|
558
|
-
var serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
559
|
-
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
560
|
-
var combinedModule = createVirtualModule('export * from "'.concat(serverLoaderRuntime, '"; export * from "').concat(serverLoadersFile, '"'));
|
|
561
|
-
chain.entry("".concat(entryName, "-server-loaders")).add(combinedModule);
|
|
562
|
-
}
|
|
563
|
-
});
|
|
564
|
-
}
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
},
|
|
568
545
|
resolvedConfig: function resolvedConfig(param) {
|
|
569
546
|
var resolved = param.resolved;
|
|
570
547
|
var appContext = api.useAppContext();
|
|
@@ -221,8 +221,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
221
221
|
}
|
|
222
222
|
};
|
|
223
223
|
import path from "path";
|
|
224
|
-
import { fs, slash } from "@modern-js/utils";
|
|
224
|
+
import { fs, getEntryOptions, isSSGEntry, slash } from "@modern-js/utils";
|
|
225
225
|
import { APP_CONFIG_NAME, TEMP_LOADERS_DIR } from "./constants";
|
|
226
|
+
import { getServerLoadersFile } from "./utils";
|
|
226
227
|
var index = function(param) {
|
|
227
228
|
var mountId = param.mountId, imports = param.imports, renderFunction2 = param.renderFunction, exportStatement = param.exportStatement;
|
|
228
229
|
return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction2, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
|
|
@@ -462,4 +463,17 @@ var fileSystemRoutes = function() {
|
|
|
462
463
|
return _ref.apply(this, arguments);
|
|
463
464
|
};
|
|
464
465
|
}();
|
|
465
|
-
|
|
466
|
+
function ssrLoaderCombinedModule(entrypoints, entrypoint, config, appContext) {
|
|
467
|
+
var entryName = entrypoint.entryName;
|
|
468
|
+
var packageName = appContext.packageName, internalDirectory = appContext.internalDirectory;
|
|
469
|
+
var ssr = getEntryOptions(entryName, config.server.ssr, config.server.ssrByEntries, packageName);
|
|
470
|
+
var ssg = isSSGEntry(config, entryName, entrypoints);
|
|
471
|
+
if (entrypoint.nestedRoutesEntry && (ssr || ssg)) {
|
|
472
|
+
var serverLoaderRuntime = require.resolve("@modern-js/plugin-data-loader/runtime");
|
|
473
|
+
var serverLoadersFile = getServerLoadersFile(internalDirectory, entryName);
|
|
474
|
+
var combinedModule = 'export * from "'.concat(serverLoaderRuntime, '"; export * from "').concat(serverLoadersFile, '"');
|
|
475
|
+
return combinedModule;
|
|
476
|
+
}
|
|
477
|
+
return null;
|
|
478
|
+
}
|
|
479
|
+
export { fileSystemRoutes, html, index, renderFunction, routesForServer, ssrLoaderCombinedModule };
|
|
@@ -371,4 +371,7 @@ var hasLoader = function() {
|
|
|
371
371
|
var getServerLoadersFile = function(internalDirectory, entryName) {
|
|
372
372
|
return path.join(internalDirectory, entryName, "route-server-loaders.js");
|
|
373
373
|
};
|
|
374
|
-
|
|
374
|
+
var getServerCombinedModueFile = function(internalDirectory, entryName) {
|
|
375
|
+
return path.join(internalDirectory, entryName, "server-loader-combined.js");
|
|
376
|
+
};
|
|
377
|
+
export { getDefaultImports, getServerCombinedModueFile, getServerLoadersFile, hasLoader, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
|
|
@@ -25,7 +25,6 @@ function _unsupportedIterableToArray(o, minLen) {
|
|
|
25
25
|
}
|
|
26
26
|
import { join } from "path";
|
|
27
27
|
import { createCopyPattern } from "../../shared";
|
|
28
|
-
import { RouterPlugin } from "../webpackPlugins";
|
|
29
28
|
var builderPluginCompatModern = function(options) {
|
|
30
29
|
return {
|
|
31
30
|
name: "builder-plugin-compat-modern",
|
|
@@ -33,7 +32,6 @@ var builderPluginCompatModern = function(options) {
|
|
|
33
32
|
var modernConfig = options.normalizedConfig, appContext = options.appContext;
|
|
34
33
|
api.modifyWebpackChain(function(chain, param) {
|
|
35
34
|
var CHAIN_ID = param.CHAIN_ID;
|
|
36
|
-
var _modernConfig_runtime;
|
|
37
35
|
chain.resolve.modules.add("node_modules").add(join(api.context.rootPath, "node_modules"));
|
|
38
36
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
39
37
|
var defaultCopyPattern = createCopyPattern(appContext, modernConfig, "public", chain);
|
|
@@ -48,15 +46,6 @@ var builderPluginCompatModern = function(options) {
|
|
|
48
46
|
];
|
|
49
47
|
});
|
|
50
48
|
}
|
|
51
|
-
var entrypoints = appContext.entrypoints;
|
|
52
|
-
var existNestedRoutes = entrypoints.some(function(entrypoint) {
|
|
53
|
-
return entrypoint.nestedRoutesEntry;
|
|
54
|
-
});
|
|
55
|
-
var routerConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_runtime = modernConfig.runtime) === null || _modernConfig_runtime === void 0 ? void 0 : _modernConfig_runtime.router;
|
|
56
|
-
var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
|
57
|
-
if (existNestedRoutes || routerManifest) {
|
|
58
|
-
chain.plugin("route-plugin").use(RouterPlugin);
|
|
59
|
-
}
|
|
60
49
|
});
|
|
61
50
|
}
|
|
62
51
|
};
|
|
@@ -175,18 +175,20 @@ function applyBuilderPlugins(builder, options) {
|
|
|
175
175
|
}
|
|
176
176
|
function _applyBuilderPlugins() {
|
|
177
177
|
_applyBuilderPlugins = _asyncToGenerator(function(builder, options) {
|
|
178
|
-
var
|
|
178
|
+
var _ref, builderPluginAdapterBasic, builderPluginAdapterHtml, builderPluginAdapterSSR;
|
|
179
179
|
return __generator(this, function(_state) {
|
|
180
180
|
switch(_state.label){
|
|
181
181
|
case 0:
|
|
182
182
|
return [
|
|
183
183
|
4,
|
|
184
|
-
import("../shared/builderPlugins
|
|
184
|
+
import("../shared/builderPlugins")
|
|
185
185
|
];
|
|
186
186
|
case 1:
|
|
187
|
-
|
|
187
|
+
_ref = _state.sent(), builderPluginAdapterBasic = _ref.builderPluginAdapterBasic, builderPluginAdapterHtml = _ref.builderPluginAdapterHtml, builderPluginAdapterSSR = _ref.builderPluginAdapterSSR;
|
|
188
188
|
builder.addPlugins([
|
|
189
|
-
|
|
189
|
+
builderPluginAdapterBasic(options),
|
|
190
|
+
builderPluginAdapterSSR(options),
|
|
191
|
+
builderPluginAdapterHtml(options)
|
|
190
192
|
]);
|
|
191
193
|
return [
|
|
192
194
|
2
|
|
@@ -155,7 +155,7 @@ function _createBuilderGenerator() {
|
|
|
155
155
|
];
|
|
156
156
|
case 3:
|
|
157
157
|
_ = _state.sent();
|
|
158
|
-
throw new Error("Failed to use
|
|
158
|
+
throw new Error("Failed to use Rspack, please check if you have `@modern-js/builder-rspack-provider` installed");
|
|
159
159
|
case 4:
|
|
160
160
|
return [
|
|
161
161
|
4,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var builderPluginAdapterBasic = function(options) {
|
|
2
|
+
return {
|
|
3
|
+
name: "builder-plugin-adapter-modern-basic",
|
|
4
|
+
setup: function setup(api) {
|
|
5
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
6
|
+
var target = param.target, CHAIN_ID = param.CHAIN_ID;
|
|
7
|
+
if (target === "node") {
|
|
8
|
+
chain.name("server");
|
|
9
|
+
} else if (target === "service-worker") {
|
|
10
|
+
chain.name("service-worker");
|
|
11
|
+
} else if (target === "web-worker") {
|
|
12
|
+
chain.name("worker");
|
|
13
|
+
} else if (target === "modern-web") {
|
|
14
|
+
chain.name("modern");
|
|
15
|
+
} else {
|
|
16
|
+
chain.name("client");
|
|
17
|
+
}
|
|
18
|
+
if (target === "node" || target === "service-worker") {
|
|
19
|
+
applyNodeCompat(target, chain);
|
|
20
|
+
}
|
|
21
|
+
if (target === "web" || target === "modern-web") {
|
|
22
|
+
var bareServerModuleReg = /\.(server|node)\.[tj]sx?$/;
|
|
23
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(bareServerModuleReg);
|
|
24
|
+
chain.module.rule("bare-server-module").test(bareServerModuleReg).use("server-module-loader").loader(require.resolve("../loaders/serverModuleLoader"));
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
applyCallbacks(api, options);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
function applyCallbacks(api, options) {
|
|
32
|
+
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
33
|
+
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
34
|
+
options.onAfterStartDevServer && api.onAfterStartDevServer(options.onAfterStartDevServer);
|
|
35
|
+
options.onBeforeBuild && api.onBeforeBuild(options.onBeforeBuild);
|
|
36
|
+
options.onBeforeCreateCompiler && api.onBeforeCreateCompiler(options.onBeforeCreateCompiler);
|
|
37
|
+
options.onBeforeStartDevServer && api.onBeforeStartDevServer(options.onBeforeStartDevServer);
|
|
38
|
+
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
39
|
+
options.onExit && api.onExit(options.onExit);
|
|
40
|
+
}
|
|
41
|
+
function applyNodeCompat(target, chain) {
|
|
42
|
+
var nodeExts = [
|
|
43
|
+
".node.js",
|
|
44
|
+
".node.jsx",
|
|
45
|
+
".node.ts",
|
|
46
|
+
".node.tsx",
|
|
47
|
+
".server.js",
|
|
48
|
+
".server.ts",
|
|
49
|
+
".server.ts",
|
|
50
|
+
".server.tsx"
|
|
51
|
+
];
|
|
52
|
+
var webWorkerExts = [
|
|
53
|
+
".worker.js",
|
|
54
|
+
".worker.jsx",
|
|
55
|
+
".worker.ts",
|
|
56
|
+
".worker.tsx"
|
|
57
|
+
];
|
|
58
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
59
|
+
try {
|
|
60
|
+
for(var _iterator = nodeExts[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
|
|
61
|
+
var ext = _step.value;
|
|
62
|
+
chain.resolve.extensions.prepend(ext);
|
|
63
|
+
}
|
|
64
|
+
} catch (err) {
|
|
65
|
+
_didIteratorError = true;
|
|
66
|
+
_iteratorError = err;
|
|
67
|
+
} finally{
|
|
68
|
+
try {
|
|
69
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
70
|
+
_iterator.return();
|
|
71
|
+
}
|
|
72
|
+
} finally{
|
|
73
|
+
if (_didIteratorError) {
|
|
74
|
+
throw _iteratorError;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (target === "service-worker") {
|
|
79
|
+
var _iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = undefined;
|
|
80
|
+
try {
|
|
81
|
+
for(var _iterator1 = webWorkerExts[Symbol.iterator](), _step1; !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true){
|
|
82
|
+
var ext1 = _step1.value;
|
|
83
|
+
chain.resolve.extensions.prepend(ext1);
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
_didIteratorError1 = true;
|
|
87
|
+
_iteratorError1 = err;
|
|
88
|
+
} finally{
|
|
89
|
+
try {
|
|
90
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
91
|
+
_iterator1.return();
|
|
92
|
+
}
|
|
93
|
+
} finally{
|
|
94
|
+
if (_didIteratorError1) {
|
|
95
|
+
throw _iteratorError1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export { applyCallbacks, builderPluginAdapterBasic };
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _objectSpread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_defineProperty(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
function ownKeys(object, enumerableOnly) {
|
|
30
|
+
var keys = Object.keys(object);
|
|
31
|
+
if (Object.getOwnPropertySymbols) {
|
|
32
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
33
|
+
if (enumerableOnly) {
|
|
34
|
+
symbols = symbols.filter(function(sym) {
|
|
35
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
keys.push.apply(keys, symbols);
|
|
39
|
+
}
|
|
40
|
+
return keys;
|
|
41
|
+
}
|
|
42
|
+
function _objectSpreadProps(target, source) {
|
|
43
|
+
source = source != null ? source : {};
|
|
44
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
45
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
46
|
+
} else {
|
|
47
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
|
+
}
|
|
53
|
+
import { getEntryOptions } from "@modern-js/utils";
|
|
54
|
+
import { template as lodashTemplate } from "@modern-js/utils/lodash";
|
|
55
|
+
import { BottomTemplatePlugin } from "../bundlerPlugins";
|
|
56
|
+
function isHtmlEnabled(config, target) {
|
|
57
|
+
var _config_tools;
|
|
58
|
+
return ((_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.htmlPlugin) !== false && target !== "node" && target !== "service-worker" && target !== "web-worker";
|
|
59
|
+
}
|
|
60
|
+
var builderPluginAdapterHtml = function(options) {
|
|
61
|
+
return {
|
|
62
|
+
name: "builder-plugin-adpater-modern-html",
|
|
63
|
+
setup: function setup(api) {
|
|
64
|
+
api.modifyBundlerChain(function(chain, param) {
|
|
65
|
+
var CHAIN_ID = param.CHAIN_ID, target = param.target, HtmlBundlerPlugin = param.HtmlPlugin;
|
|
66
|
+
var builderConfig = api.getNormalizedConfig();
|
|
67
|
+
if (isHtmlEnabled(builderConfig, target)) {
|
|
68
|
+
applyBottomHtmlPlugin({
|
|
69
|
+
api: api,
|
|
70
|
+
options: options,
|
|
71
|
+
chain: chain,
|
|
72
|
+
CHAIN_ID: CHAIN_ID,
|
|
73
|
+
HtmlBundlerPlugin: HtmlBundlerPlugin
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
function applyBottomHtmlPlugin(param) {
|
|
81
|
+
var api = param.api, chain = param.chain, options = param.options, CHAIN_ID = param.CHAIN_ID, HtmlBundlerPlugin = param.HtmlBundlerPlugin;
|
|
82
|
+
var modernConfig = options.normalizedConfig, appContext = options.appContext;
|
|
83
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
|
|
84
|
+
try {
|
|
85
|
+
var _loop = function() {
|
|
86
|
+
var entryName = _step.value;
|
|
87
|
+
var baseTemplateParams = _objectSpread({
|
|
88
|
+
entryName: entryName,
|
|
89
|
+
title: getEntryOptions(entryName, modernConfig.html.title, modernConfig.html.titleByEntries, appContext.packageName),
|
|
90
|
+
mountId: modernConfig.html.mountId
|
|
91
|
+
}, getEntryOptions(entryName, modernConfig.html.templateParameters, modernConfig.html.templateParametersByEntries, appContext.packageName));
|
|
92
|
+
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function(args) {
|
|
93
|
+
return [
|
|
94
|
+
_objectSpreadProps(_objectSpread({}, args[0] || {}), {
|
|
95
|
+
__internal__: true,
|
|
96
|
+
bottomTemplate: appContext.htmlTemplates["__".concat(entryName, "-bottom__")] && lodashTemplate(appContext.htmlTemplates["__".concat(entryName, "-bottom__")])(baseTemplateParams)
|
|
97
|
+
})
|
|
98
|
+
];
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
for(var _iterator = Object.keys(api.context.entry)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
|
|
102
|
+
} catch (err) {
|
|
103
|
+
_didIteratorError = true;
|
|
104
|
+
_iteratorError = err;
|
|
105
|
+
} finally{
|
|
106
|
+
try {
|
|
107
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
108
|
+
_iterator.return();
|
|
109
|
+
}
|
|
110
|
+
} finally{
|
|
111
|
+
if (_didIteratorError) {
|
|
112
|
+
throw _iteratorError;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [
|
|
117
|
+
HtmlBundlerPlugin
|
|
118
|
+
]);
|
|
119
|
+
}
|
|
120
|
+
export { builderPluginAdapterHtml, isHtmlEnabled };
|