@modern-js/runtime 2.63.2 → 2.63.4
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/cli/code.js +2 -2
- package/dist/cjs/cli/index.js +102 -108
- package/dist/cjs/cli/ssr/index.js +49 -52
- package/dist/cjs/core/server/string/loadable.js +13 -3
- package/dist/cjs/document/cli/index.js +32 -34
- package/dist/cjs/router/cli/code/index.js +5 -5
- package/dist/cjs/router/cli/handler.js +6 -6
- package/dist/cjs/router/cli/index.js +76 -78
- package/dist/cjs/router/runtime/plugin.js +1 -4
- package/dist/cjs/state/cli/index.js +22 -24
- package/dist/esm/cli/code.js +3 -3
- package/dist/esm/cli/index.js +120 -130
- package/dist/esm/cli/ssr/index.js +50 -53
- package/dist/esm/core/server/string/loadable.js +17 -5
- package/dist/esm/document/cli/index.js +28 -30
- package/dist/esm/router/cli/code/index.js +8 -8
- package/dist/esm/router/cli/handler.js +6 -6
- package/dist/esm/router/cli/index.js +161 -157
- package/dist/esm/router/runtime/plugin.js +1 -4
- package/dist/esm/state/cli/index.js +23 -25
- package/dist/esm-node/cli/code.js +2 -2
- package/dist/esm-node/cli/index.js +102 -108
- package/dist/esm-node/cli/ssr/index.js +49 -52
- package/dist/esm-node/core/server/string/loadable.js +13 -3
- package/dist/esm-node/document/cli/index.js +32 -34
- package/dist/esm-node/router/cli/code/index.js +5 -5
- package/dist/esm-node/router/cli/handler.js +6 -6
- package/dist/esm-node/router/cli/index.js +76 -78
- package/dist/esm-node/router/runtime/plugin.js +1 -4
- package/dist/esm-node/state/cli/index.js +22 -24
- package/dist/types/cli/code.d.ts +2 -9
- package/dist/types/cli/index.d.ts +3 -3
- package/dist/types/cli/ssr/index.d.ts +2 -2
- package/dist/types/core/server/string/loadable.d.ts +3 -2
- package/dist/types/document/cli/index.d.ts +2 -2
- package/dist/types/router/cli/code/index.d.ts +3 -3
- package/dist/types/router/cli/code/templates.d.ts +2 -2
- package/dist/types/router/cli/handler.d.ts +4 -4
- package/dist/types/router/cli/index.d.ts +2 -2
- package/dist/types/router/runtime/types.d.ts +0 -10
- package/dist/types/state/cli/index.d.ts +2 -2
- package/package.json +11 -11
|
@@ -24,7 +24,7 @@ const ssrBuilderPlugin = (modernAPI) => ({
|
|
|
24
24
|
setup(api) {
|
|
25
25
|
api.modifyEnvironmentConfig((config, { name, mergeEnvironmentConfig }) => {
|
|
26
26
|
const isServerEnvironment = config.output.target === "node" || name === "workerSSR";
|
|
27
|
-
const userConfig = modernAPI.
|
|
27
|
+
const userConfig = modernAPI.getNormalizedConfig();
|
|
28
28
|
const useLoadablePlugin = isUseSSRBundle(userConfig) && !isServerEnvironment && checkUseStringSSR(userConfig);
|
|
29
29
|
return mergeEnvironmentConfig(config, {
|
|
30
30
|
source: {
|
|
@@ -52,61 +52,58 @@ const ssrPlugin = () => ({
|
|
|
52
52
|
"@modern-js/runtime"
|
|
53
53
|
],
|
|
54
54
|
setup: (api) => {
|
|
55
|
-
const appContext = api.
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
const appContext = api.getAppContext();
|
|
56
|
+
api.config(() => {
|
|
57
|
+
const { bundlerType = "webpack" } = api.getAppContext();
|
|
58
|
+
const babelHandler = (() => {
|
|
59
|
+
if (bundlerType === "webpack") {
|
|
60
|
+
return (config) => {
|
|
61
|
+
var _config_plugins;
|
|
62
|
+
const userConfig = api.getNormalizedConfig();
|
|
63
|
+
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
64
|
+
if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
|
|
65
|
+
var _config_plugins1;
|
|
66
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
} else if (bundlerType === "rspack") {
|
|
70
|
+
return (config) => {
|
|
71
|
+
const userConfig = api.useResolvedConfigContext();
|
|
72
|
+
if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
|
|
73
|
+
var _config_plugins, _config_plugins1;
|
|
65
74
|
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
66
|
-
|
|
67
|
-
var _config_plugins1;
|
|
68
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
} else if (bundlerType === "rspack") {
|
|
72
|
-
return (config) => {
|
|
73
|
-
const userConfig = api.useResolvedConfigContext();
|
|
74
|
-
if (isUseSSRBundle(userConfig) && checkUseStringSSR(userConfig)) {
|
|
75
|
-
var _config_plugins, _config_plugins1;
|
|
76
|
-
(_config_plugins = config.plugins) === null || _config_plugins === void 0 ? void 0 : _config_plugins.push(path.join(__dirname, "./babel-plugin-ssr-loader-id"));
|
|
77
|
-
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
})();
|
|
82
|
-
return {
|
|
83
|
-
builderPlugins: [
|
|
84
|
-
ssrBuilderPlugin(api)
|
|
85
|
-
],
|
|
86
|
-
source: {
|
|
87
|
-
alias: {
|
|
88
|
-
// ensure that all packages use the same storage in @modern-js/runtime-utils/node
|
|
89
|
-
"@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
|
|
75
|
+
(_config_plugins1 = config.plugins) === null || _config_plugins1 === void 0 ? void 0 : _config_plugins1.push(require.resolve("@loadable/babel-plugin"));
|
|
90
76
|
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
80
|
+
return {
|
|
81
|
+
builderPlugins: [
|
|
82
|
+
ssrBuilderPlugin(api)
|
|
83
|
+
],
|
|
84
|
+
source: {
|
|
85
|
+
alias: {
|
|
86
|
+
// ensure that all packages use the same storage in @modern-js/runtime-utils/node
|
|
87
|
+
"@modern-js/runtime-utils/node$": require.resolve("@modern-js/runtime-utils/node")
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
tools: {
|
|
91
|
+
babel: babelHandler,
|
|
92
|
+
bundlerChain: (chain, { isServer }) => {
|
|
93
|
+
if (isServer && appContext.moduleType === "module") {
|
|
94
|
+
chain.output.libraryTarget("module").set("chunkFormat", "module");
|
|
95
|
+
chain.output.library({
|
|
96
|
+
type: "module"
|
|
97
|
+
});
|
|
98
|
+
chain.experiments({
|
|
99
|
+
...chain.get("experiments"),
|
|
100
|
+
outputModule: true
|
|
101
|
+
});
|
|
105
102
|
}
|
|
106
103
|
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
};
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
});
|
|
110
107
|
}
|
|
111
108
|
});
|
|
112
109
|
var ssr_default = ssrPlugin;
|
|
@@ -47,8 +47,18 @@ class LoadableCollector {
|
|
|
47
47
|
if (!this.extractor) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
|
-
const { extractor } = this;
|
|
51
|
-
const
|
|
50
|
+
const { extractor, options } = this;
|
|
51
|
+
const { entryName, config } = options;
|
|
52
|
+
const asyncChunks = [];
|
|
53
|
+
if (config.enableAsyncEntry) {
|
|
54
|
+
try {
|
|
55
|
+
asyncChunks.push(...extractor.getChunkAssets([
|
|
56
|
+
`async-${entryName}`
|
|
57
|
+
]));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const chunks = [].concat(asyncChunks).concat(extractor.getChunkAssets(extractor.chunks));
|
|
52
62
|
const scriptChunks = generateChunks(chunks, "js");
|
|
53
63
|
const styleChunks = generateChunks(chunks, "css");
|
|
54
64
|
this.emitLoadableScripts(extractor);
|
|
@@ -99,7 +109,7 @@ class LoadableCollector {
|
|
|
99
109
|
chunkSet.jsChunk += scripts.filter((script) => Boolean(script)).join("");
|
|
100
110
|
}
|
|
101
111
|
async emitStyleAssets(chunks) {
|
|
102
|
-
const { template, chunkSet, config } = this.options;
|
|
112
|
+
const { template, chunkSet, config, entryName } = this.options;
|
|
103
113
|
const { enableInlineStyles } = config;
|
|
104
114
|
const atrributes = attributesToString(this.generateAttributes());
|
|
105
115
|
const linkRegExp = /<link .*?href="([^"]+)".*?>/g;
|
|
@@ -39,13 +39,13 @@ const documentPlugin = () => ({
|
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
41
|
const documentEntry = (entryName, templateParameters) => {
|
|
42
|
-
const { entrypoints, internalDirectory, appDirectory } = api.
|
|
42
|
+
const { entrypoints, internalDirectory, appDirectory } = api.getAppContext();
|
|
43
43
|
const documentFilePath = getDocumenByEntryName(entrypoints, entryName, appDirectory);
|
|
44
44
|
if (!documentFilePath) {
|
|
45
45
|
return null;
|
|
46
46
|
}
|
|
47
47
|
return async ({ htmlWebpackPlugin }) => {
|
|
48
|
-
const config = api.
|
|
48
|
+
const config = api.getNormalizedConfig();
|
|
49
49
|
const documentParams = getDocParams({
|
|
50
50
|
config,
|
|
51
51
|
entryName,
|
|
@@ -109,7 +109,7 @@ const documentPlugin = () => ({
|
|
|
109
109
|
}, React.createElement(Document, null));
|
|
110
110
|
let html = ReactDomServer.renderToStaticMarkup(HTMLElement);
|
|
111
111
|
debug("entry %s's document jsx rendered html: %o", entryName, html);
|
|
112
|
-
const { partialsByEntrypoint } = api.
|
|
112
|
+
const { partialsByEntrypoint } = api.getAppContext();
|
|
113
113
|
const scripts = [
|
|
114
114
|
htmlWebpackPlugin.tags.headTags.filter((item) => item.tagName === "script").join(""),
|
|
115
115
|
htmlWebpackPlugin.tags.bodyTags.toString()
|
|
@@ -148,38 +148,36 @@ const documentPlugin = () => ({
|
|
|
148
148
|
return finalHtml;
|
|
149
149
|
};
|
|
150
150
|
};
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
return {};
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
tools: {
|
|
160
|
-
htmlPlugin: (options, entry) => {
|
|
161
|
-
const hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : {
|
|
162
|
-
...options === null || options === void 0 ? void 0 : options.templateParameters
|
|
163
|
-
};
|
|
164
|
-
const templateContent = documentEntry(
|
|
165
|
-
entry.entryName,
|
|
166
|
-
// options,
|
|
167
|
-
hackParameters
|
|
168
|
-
);
|
|
169
|
-
const documentHtmlOptions = templateContent ? {
|
|
170
|
-
templateContent,
|
|
171
|
-
// Note: the behavior of inject/modify tags in afterTemplateExecution hook will not take effect
|
|
172
|
-
inject: false
|
|
173
|
-
} : {};
|
|
174
|
-
return {
|
|
175
|
-
...options,
|
|
176
|
-
...documentHtmlOptions
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
};
|
|
151
|
+
api.config(() => {
|
|
152
|
+
var _userConfig_tools;
|
|
153
|
+
const userConfig = api.getConfig();
|
|
154
|
+
if (((_userConfig_tools = userConfig.tools) === null || _userConfig_tools === void 0 ? void 0 : _userConfig_tools.htmlPlugin) === false) {
|
|
155
|
+
return {};
|
|
181
156
|
}
|
|
182
|
-
|
|
157
|
+
return {
|
|
158
|
+
tools: {
|
|
159
|
+
htmlPlugin: (options, entry) => {
|
|
160
|
+
const hackParameters = typeof (options === null || options === void 0 ? void 0 : options.templateParameters) === "function" ? options === null || options === void 0 ? void 0 : options.templateParameters({}, {}, {}, {}) : {
|
|
161
|
+
...options === null || options === void 0 ? void 0 : options.templateParameters
|
|
162
|
+
};
|
|
163
|
+
const templateContent = documentEntry(
|
|
164
|
+
entry.entryName,
|
|
165
|
+
// options,
|
|
166
|
+
hackParameters
|
|
167
|
+
);
|
|
168
|
+
const documentHtmlOptions = templateContent ? {
|
|
169
|
+
templateContent,
|
|
170
|
+
// Note: the behavior of inject/modify tags in afterTemplateExecution hook will not take effect
|
|
171
|
+
inject: false
|
|
172
|
+
} : {};
|
|
173
|
+
return {
|
|
174
|
+
...options,
|
|
175
|
+
...documentHtmlOptions
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
});
|
|
183
181
|
}
|
|
184
182
|
});
|
|
185
183
|
var cli_default = documentPlugin;
|
|
@@ -10,14 +10,14 @@ import * as templates from "./templates";
|
|
|
10
10
|
import { getServerCombinedModueFile, getServerLoadersFile } from "./utils";
|
|
11
11
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
12
12
|
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
|
13
|
-
const
|
|
13
|
+
const hooks = api.getHooks();
|
|
14
14
|
const isV5 = isRouterV5(config);
|
|
15
15
|
const getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
16
16
|
const oldVersion = typeof (config === null || config === void 0 ? void 0 : config.runtime.router) === "object" ? Boolean((config === null || config === void 0 ? void 0 : config.runtime.router).oldVersion) : false;
|
|
17
17
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
18
18
|
async function generateEntryCode(entrypoint) {
|
|
19
19
|
const { entryName, isMainEntry, isAutoMount, pageRoutesEntry, nestedRoutesEntry } = entrypoint;
|
|
20
|
-
const { metaName } = api.
|
|
20
|
+
const { metaName } = api.getAppContext();
|
|
21
21
|
if (isAutoMount) {
|
|
22
22
|
if (pageRoutesEntry || nestedRoutesEntry) {
|
|
23
23
|
var _config_output;
|
|
@@ -48,11 +48,11 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
const config2 = api.
|
|
51
|
+
const config2 = api.getNormalizedConfig();
|
|
52
52
|
const ssrByRouteIds = config2.server.ssrByRouteIds || [];
|
|
53
53
|
const clonedRoutes = cloneDeep(initialRoutes);
|
|
54
54
|
const markedRoutes = ssrByRouteIds.length > 0 ? markRoutes(clonedRoutes, ssrByRouteIds) : initialRoutes;
|
|
55
|
-
const { routes } = await
|
|
55
|
+
const { routes } = await hooks.modifyFileSystemRoutes.call({
|
|
56
56
|
entrypoint,
|
|
57
57
|
routes: markedRoutes
|
|
58
58
|
});
|
|
@@ -69,7 +69,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
69
69
|
process.exit(1);
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
const { code } = await
|
|
72
|
+
const { code } = await hooks.onBeforeGenerateRoutes.call({
|
|
73
73
|
entrypoint,
|
|
74
74
|
code: await templates.fileSystemRoutes({
|
|
75
75
|
metaName,
|
|
@@ -5,13 +5,13 @@ import { isPageComponentFile } from "./code/utils";
|
|
|
5
5
|
import { modifyEntrypoints } from "./entry";
|
|
6
6
|
let originEntrypoints = [];
|
|
7
7
|
async function handleModifyEntrypoints(api, entrypoints) {
|
|
8
|
-
const config = api.
|
|
8
|
+
const config = api.getNormalizedConfig();
|
|
9
9
|
return modifyEntrypoints(entrypoints, config);
|
|
10
10
|
}
|
|
11
11
|
async function handleGeneratorEntryCode(api, entrypoints) {
|
|
12
|
-
const appContext = api.
|
|
13
|
-
const { internalDirectory } =
|
|
14
|
-
const resolvedConfig = api.
|
|
12
|
+
const appContext = api.getAppContext();
|
|
13
|
+
const { internalDirectory } = appContext;
|
|
14
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
15
15
|
const { generatorRegisterCode, generateCode } = await import("./code");
|
|
16
16
|
originEntrypoints = cloneDeep(entrypoints);
|
|
17
17
|
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
@@ -30,7 +30,7 @@ async function handleGeneratorEntryCode(api, entrypoints) {
|
|
|
30
30
|
return entrypoints;
|
|
31
31
|
}
|
|
32
32
|
async function handleFileChange(api, e) {
|
|
33
|
-
const appContext = api.
|
|
33
|
+
const appContext = api.getAppContext();
|
|
34
34
|
const { appDirectory, entrypoints } = appContext;
|
|
35
35
|
const { filename, eventType } = e;
|
|
36
36
|
const nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
@@ -39,7 +39,7 @@ async function handleFileChange(api, e) {
|
|
|
39
39
|
const absoluteFilePath = path.resolve(appDirectory, filename);
|
|
40
40
|
const isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
|
|
41
41
|
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
42
|
-
const resolvedConfig = api.
|
|
42
|
+
const resolvedConfig = api.getNormalizedConfig();
|
|
43
43
|
const { generateCode } = await import("./code");
|
|
44
44
|
const entrypoints2 = cloneDeep(originEntrypoints);
|
|
45
45
|
await generateCode(appContext, resolvedConfig, entrypoints2, api);
|
|
@@ -13,87 +13,85 @@ const routerPlugin = () => ({
|
|
|
13
13
|
setup: (api) => {
|
|
14
14
|
const nestedRoutes = {};
|
|
15
15
|
const nestedRoutesForServer = {};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
serverBase
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return {
|
|
36
|
-
entrypoint,
|
|
37
|
-
plugins
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
checkEntryPoint({ path: path2, entry }) {
|
|
41
|
-
return {
|
|
42
|
-
path: path2,
|
|
43
|
-
entry: entry || isRouteEntry(path2)
|
|
44
|
-
};
|
|
45
|
-
},
|
|
46
|
-
config() {
|
|
47
|
-
return {
|
|
48
|
-
source: {
|
|
49
|
-
include: [
|
|
50
|
-
// react-router v6 is no longer support ie 11
|
|
51
|
-
// so we need to compile these packages to ensure the compatibility
|
|
52
|
-
// https://github.com/remix-run/react-router/commit/f6df0697e1b2064a2b3a12e8b39577326fdd945b
|
|
53
|
-
/node_modules\/react-router/,
|
|
54
|
-
/node_modules\/react-router-dom/,
|
|
55
|
-
/node_modules\/@remix-run\/router/
|
|
56
|
-
]
|
|
16
|
+
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
|
17
|
+
var _getEntryOptions;
|
|
18
|
+
const { packageName, serverRoutes, metaName } = api.getAppContext();
|
|
19
|
+
const serverBase = serverRoutes.filter((route) => route.entryName === entrypoint.entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
|
|
20
|
+
const userConfig = api.getNormalizedConfig();
|
|
21
|
+
const routerConfig = (_getEntryOptions = getEntryOptions(entrypoint.entryName, entrypoint.isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.router;
|
|
22
|
+
if (routerConfig && !isV5(userConfig)) {
|
|
23
|
+
plugins.push({
|
|
24
|
+
name: "router",
|
|
25
|
+
path: `@${metaName}/runtime/router`,
|
|
26
|
+
config: typeof routerConfig === "boolean" ? {
|
|
27
|
+
serverBase
|
|
28
|
+
} : {
|
|
29
|
+
...routerConfig,
|
|
30
|
+
serverBase
|
|
57
31
|
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return {
|
|
35
|
+
entrypoint,
|
|
36
|
+
plugins
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
api.checkEntryPoint(({ path: path2, entry }) => {
|
|
40
|
+
return {
|
|
41
|
+
path: path2,
|
|
42
|
+
entry: entry || isRouteEntry(path2)
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
api.config(() => {
|
|
46
|
+
return {
|
|
47
|
+
source: {
|
|
48
|
+
include: [
|
|
49
|
+
// react-router v6 is no longer support ie 11
|
|
50
|
+
// so we need to compile these packages to ensure the compatibility
|
|
51
|
+
// https://github.com/remix-run/react-router/commit/f6df0697e1b2064a2b3a12e8b39577326fdd945b
|
|
52
|
+
/node_modules\/react-router/,
|
|
53
|
+
/node_modules\/react-router-dom/,
|
|
54
|
+
/node_modules\/@remix-run\/router/
|
|
55
|
+
]
|
|
75
56
|
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
code
|
|
94
|
-
};
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
api.modifyEntrypoints(async ({ entrypoints }) => {
|
|
60
|
+
const newEntryPoints = await handleModifyEntrypoints(api, entrypoints);
|
|
61
|
+
return {
|
|
62
|
+
entrypoints: newEntryPoints
|
|
63
|
+
};
|
|
64
|
+
});
|
|
65
|
+
api.generateEntryCode(async ({ entrypoints }) => {
|
|
66
|
+
await handleGeneratorEntryCode(api, entrypoints);
|
|
67
|
+
});
|
|
68
|
+
api.addRuntimeExports(() => {
|
|
69
|
+
const userConfig = api.useResolvedConfigContext();
|
|
70
|
+
const { internalDirectory, metaName } = api.useAppContext();
|
|
71
|
+
const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
72
|
+
if (!isV5(userConfig)) {
|
|
73
|
+
pluginsExportsUtils.addExport(`export { default as router } from '@${metaName}/runtime/router'`);
|
|
95
74
|
}
|
|
96
|
-
};
|
|
75
|
+
});
|
|
76
|
+
api.onFileChanged(async (e) => {
|
|
77
|
+
await handleFileChange(api, e);
|
|
78
|
+
});
|
|
79
|
+
api.modifyFileSystemRoutes(({ entrypoint, routes }) => {
|
|
80
|
+
nestedRoutes[entrypoint.entryName] = routes;
|
|
81
|
+
nestedRoutesForServer[entrypoint.entryName] = filterRoutesForServer(routes);
|
|
82
|
+
return {
|
|
83
|
+
entrypoint,
|
|
84
|
+
routes
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
api.onBeforeGenerateRoutes(async ({ entrypoint, code }) => {
|
|
88
|
+
const { distDirectory } = api.getAppContext();
|
|
89
|
+
await fs.outputJSON(path.resolve(distDirectory, NESTED_ROUTE_SPEC_FILE), nestedRoutesForServer);
|
|
90
|
+
return {
|
|
91
|
+
entrypoint,
|
|
92
|
+
code
|
|
93
|
+
};
|
|
94
|
+
});
|
|
97
95
|
}
|
|
98
96
|
});
|
|
99
97
|
var cli_default = routerPlugin;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { merge } from "@modern-js/runtime-utils/merge";
|
|
3
|
-
import { parsedJSONFromElement } from "@modern-js/runtime-utils/parsed";
|
|
4
3
|
import { RouterProvider, createBrowserRouter, createHashRouter, createRoutesFromElements, useHref, useLocation, useMatches } from "@modern-js/runtime-utils/router";
|
|
5
4
|
import { useContext, useMemo } from "react";
|
|
6
5
|
import { RuntimeReactContext } from "../../core";
|
|
@@ -28,7 +27,6 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
28
27
|
},
|
|
29
28
|
setup: (api) => {
|
|
30
29
|
let routes = [];
|
|
31
|
-
window._SERVER_DATA = parsedJSONFromElement("__MODERN_SERVER_DATA__");
|
|
32
30
|
return {
|
|
33
31
|
beforeRender(context) {
|
|
34
32
|
context.router = {
|
|
@@ -56,9 +54,8 @@ const routerPlugin = (userConfig = {}) => {
|
|
|
56
54
|
}
|
|
57
55
|
const getRouteApp = () => {
|
|
58
56
|
const useCreateRouter = (props) => {
|
|
59
|
-
var _window__SERVER_DATA;
|
|
60
57
|
const runtimeContext = useContext(RuntimeReactContext);
|
|
61
|
-
const baseUrl =
|
|
58
|
+
const baseUrl = select(location.pathname).replace(/^\/*/, "/");
|
|
62
59
|
const _basename = baseUrl === "/" ? urlJoin(baseUrl, runtimeContext._internalRouterBaseName || basename) : baseUrl;
|
|
63
60
|
let hydrationData = window._ROUTER_DATA;
|
|
64
61
|
const { unstable_getBlockNavState: getBlockNavState } = runtimeContext;
|
|
@@ -6,31 +6,29 @@ const statePlugin = () => ({
|
|
|
6
6
|
"@modern-js/runtime"
|
|
7
7
|
],
|
|
8
8
|
setup: (api) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
entrypoint,
|
|
25
|
-
plugins
|
|
26
|
-
};
|
|
27
|
-
},
|
|
28
|
-
addRuntimeExports() {
|
|
29
|
-
const { internalDirectory, metaName } = api.useAppContext();
|
|
30
|
-
const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
31
|
-
pluginsExportsUtils.addExport(`export { default as state } from '@${metaName}/runtime/model'`);
|
|
9
|
+
api._internalRuntimePlugins(({ entrypoint, plugins }) => {
|
|
10
|
+
var _getEntryOptions;
|
|
11
|
+
const { entryName, isMainEntry } = entrypoint;
|
|
12
|
+
const userConfig = api.useResolvedConfigContext();
|
|
13
|
+
const { packageName, metaName } = api.useAppContext();
|
|
14
|
+
const stateConfig = (_getEntryOptions = getEntryOptions(entryName, isMainEntry, userConfig.runtime, userConfig.runtimeByEntries, packageName)) === null || _getEntryOptions === void 0 ? void 0 : _getEntryOptions.state;
|
|
15
|
+
if (stateConfig) {
|
|
16
|
+
plugins.push({
|
|
17
|
+
name: PLUGIN_IDENTIFIER,
|
|
18
|
+
path: `@${metaName}/runtime/model`,
|
|
19
|
+
config: typeof stateConfig === "boolean" ? {} : stateConfig
|
|
20
|
+
});
|
|
32
21
|
}
|
|
33
|
-
|
|
22
|
+
return {
|
|
23
|
+
entrypoint,
|
|
24
|
+
plugins
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
api.addRuntimeExports(() => {
|
|
28
|
+
const { internalDirectory, metaName } = api.useAppContext();
|
|
29
|
+
const pluginsExportsUtils = createRuntimeExportsUtils(internalDirectory, "plugins");
|
|
30
|
+
pluginsExportsUtils.addExport(`export { default as state } from '@${metaName}/runtime/model'`);
|
|
31
|
+
});
|
|
34
32
|
}
|
|
35
33
|
});
|
|
36
34
|
var cli_default = statePlugin;
|
package/dist/types/cli/code.d.ts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { MaybeAsync } from '@modern-js/plugin';
|
|
1
|
+
import type { AppToolsContext, AppToolsFeatureHooks, AppToolsNormalizedConfig } from '@modern-js/app-tools';
|
|
3
2
|
import type { Entrypoint } from '@modern-js/types';
|
|
4
|
-
export declare const generateCode: (entrypoints: Entrypoint[], appContext:
|
|
5
|
-
entrypoint: Entrypoint;
|
|
6
|
-
plugins: RuntimePlugin[];
|
|
7
|
-
}) => MaybeAsync<{
|
|
8
|
-
entrypoint: Entrypoint;
|
|
9
|
-
plugins: RuntimePlugin[];
|
|
10
|
-
}>) => Promise<void>;
|
|
3
|
+
export declare const generateCode: (entrypoints: Entrypoint[], appContext: AppToolsContext<'shared'>, config: AppToolsNormalizedConfig, hooks: AppToolsFeatureHooks<'shared'>) => Promise<void>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AppTools,
|
|
1
|
+
import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
|
|
2
2
|
import { documentPlugin } from '../document/cli';
|
|
3
3
|
import { routerPlugin } from '../router/cli';
|
|
4
4
|
import { statePlugin } from '../state/cli';
|
|
@@ -6,6 +6,6 @@ import { ssrPlugin } from './ssr';
|
|
|
6
6
|
export { isRuntimeEntry } from './entry';
|
|
7
7
|
export { statePlugin, ssrPlugin, routerPlugin, documentPlugin };
|
|
8
8
|
export declare const runtimePlugin: (params?: {
|
|
9
|
-
plugins?:
|
|
10
|
-
}) =>
|
|
9
|
+
plugins?: CliPluginFuture<AppTools<'shared'>>[];
|
|
10
|
+
}) => CliPluginFuture<AppTools<'shared'>>;
|
|
11
11
|
export default runtimePlugin;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { AppTools,
|
|
2
|
-
export declare const ssrPlugin: () =>
|
|
1
|
+
import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
|
|
2
|
+
export declare const ssrPlugin: () => CliPluginFuture<AppTools<'shared'>>;
|
|
3
3
|
export default ssrPlugin;
|
|
@@ -2,8 +2,8 @@ import type { ReactElement } from 'react';
|
|
|
2
2
|
import type { ChunkSet, Collector } from './types';
|
|
3
3
|
declare module '@loadable/server' {
|
|
4
4
|
interface ChunkExtractor {
|
|
5
|
-
chunks:
|
|
6
|
-
getChunkAssets: (chunks:
|
|
5
|
+
chunks: string[];
|
|
6
|
+
getChunkAssets: (chunks: string[]) => Chunk[];
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
export interface LoadableCollectorOptions {
|
|
@@ -20,6 +20,7 @@ export interface LoadableCollectorConfig {
|
|
|
20
20
|
enableInlineStyles?: boolean | RegExp;
|
|
21
21
|
enableInlineScripts?: boolean | RegExp;
|
|
22
22
|
crossorigin?: boolean | 'anonymous' | 'use-credentials';
|
|
23
|
+
enableAsyncEntry?: boolean;
|
|
23
24
|
}
|
|
24
25
|
export declare class LoadableCollector implements Collector {
|
|
25
26
|
private options;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AppTools,
|
|
1
|
+
import type { AppTools, CliPluginFuture } from '@modern-js/app-tools';
|
|
2
2
|
import type { Entrypoint } from '@modern-js/types/cli';
|
|
3
3
|
export declare const getDocumenByEntryName: (entrypoints: Entrypoint[], entryName: string, fallbackDir?: string) => string | undefined;
|
|
4
|
-
export declare const documentPlugin: () =>
|
|
4
|
+
export declare const documentPlugin: () => CliPluginFuture<AppTools<'shared'>>;
|
|
5
5
|
export default documentPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AppNormalizedConfig, AppTools } from '@modern-js/app-tools';
|
|
2
|
-
import type {
|
|
1
|
+
import type { AppNormalizedConfig, AppTools, AppToolsContext } from '@modern-js/app-tools';
|
|
2
|
+
import type { CLIPluginAPI } from '@modern-js/plugin-v2';
|
|
3
3
|
import type { Entrypoint } from '@modern-js/types';
|
|
4
|
-
export declare const generateCode: (appContext:
|
|
4
|
+
export declare const generateCode: (appContext: AppToolsContext<'shared'>, config: AppNormalizedConfig<'shared'>, entrypoints: Entrypoint[], api: CLIPluginAPI<AppTools<'shared'>>) => Promise<void>;
|
|
5
5
|
export declare function generatorRegisterCode(internalDirectory: string, entryName: string, code: string): void;
|