@mfeflow/rsbuild 0.1.0 → 0.3.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/head-scripts.d.ts +19 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +23 -1
- package/package.json +1 -1
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** An Rsbuild html tag (`html.tags`) that puts an inline script first in `<head>`. */
|
|
2
|
+
export interface HeadScriptTag {
|
|
3
|
+
tag: 'script';
|
|
4
|
+
children: string;
|
|
5
|
+
head: true;
|
|
6
|
+
append: false;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Asks the shell's `<head>` to run `source` before anything else: the first thing the page does, ahead of
|
|
10
|
+
* the app's bundles (a stored theme, for example, so a reload never paints the wrong colours first).
|
|
11
|
+
* Call it from a module that `rsbuild.config.ts` imports, before `createShellConfig` runs. Keyed by
|
|
12
|
+
* `name`, so a config that is loaded again (dev server restart) replaces its script instead of adding a
|
|
13
|
+
* second one. Only the shell uses it; remotes have no page of their own.
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerHeadScript(name: string, source: string): void;
|
|
16
|
+
/** The registered scripts as Rsbuild html tags, in the order they were first registered. */
|
|
17
|
+
export declare function headScriptTags(): HeadScriptTag[];
|
|
18
|
+
/** Only for tests. */
|
|
19
|
+
export declare function resetHeadScriptsForTests(): void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
2
2
|
import { type SharedConfig } from './shared.js';
|
|
3
3
|
export { esmTwin, isMfCjs, pluginMfEsmRuntime } from './esm-runtime.js';
|
|
4
|
+
export { headScriptTags, registerHeadScript } from './head-scripts.js';
|
|
4
5
|
export { RUNTIME_CONFIG_URL, runtimeConfigEnv, runtimeConfigEnvs, runtimeConfigHandler, runtimeConfigSetup, } from './runtime-config.js';
|
|
5
6
|
export { DEFAULT_SINGLETONS, installedVersionFrom, packageNameOf, resolvableFrom, sharedSingletons, type SharedConfig, } from './shared.js';
|
|
6
7
|
export interface RemoteOptions {
|
package/dist/index.js
CHANGED
|
@@ -56,6 +56,20 @@ function pluginMfEsmRuntime() {
|
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
+
const scripts = new Map();
|
|
60
|
+
function registerHeadScript(name, source) {
|
|
61
|
+
scripts.set(name, source);
|
|
62
|
+
}
|
|
63
|
+
function headScriptTags() {
|
|
64
|
+
return [
|
|
65
|
+
...scripts.values()
|
|
66
|
+
].map((children)=>({
|
|
67
|
+
tag: "script",
|
|
68
|
+
children,
|
|
69
|
+
head: true,
|
|
70
|
+
append: false
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
59
73
|
const RUNTIME_CONFIG_URL = '/config/runtime-config.json';
|
|
60
74
|
const ENV_NAME = /^[a-z0-9-]+$/;
|
|
61
75
|
const ENV_FILE = /^runtime-config\.([a-z0-9-]+)\.json$/;
|
|
@@ -113,6 +127,8 @@ const DEFAULT_SINGLETONS = [
|
|
|
113
127
|
'@mfeflow/analytics',
|
|
114
128
|
'@mfeflow/analytics/react',
|
|
115
129
|
'@mfeflow/telemetry',
|
|
130
|
+
'@mfeflow/event-bus',
|
|
131
|
+
'@mfeflow/event-bus/react',
|
|
116
132
|
'@mfeflow/storage',
|
|
117
133
|
'@mfeflow/storage/react',
|
|
118
134
|
'@mfeflow/theme',
|
|
@@ -306,6 +322,7 @@ function createShellConfig(o) {
|
|
|
306
322
|
const require = createRequire(node_path.join(cwd, 'package.json'));
|
|
307
323
|
if (false === o.eager) assertAsyncBoundary(node_path.join(cwd, 'src/index.ts'));
|
|
308
324
|
const setup = runtimeConfigSetup(cwd, o.env ?? process.env);
|
|
325
|
+
const headScripts = headScriptTags();
|
|
309
326
|
return {
|
|
310
327
|
plugins: [
|
|
311
328
|
pluginReact(),
|
|
@@ -314,6 +331,11 @@ function createShellConfig(o) {
|
|
|
314
331
|
],
|
|
315
332
|
pluginModuleFederation(shellFederationOptions(o, resolvableFrom(cwd), (s)=>require.resolve(s)))
|
|
316
333
|
],
|
|
334
|
+
...0 === headScripts.length ? {} : {
|
|
335
|
+
html: {
|
|
336
|
+
tags: headScripts
|
|
337
|
+
}
|
|
338
|
+
},
|
|
317
339
|
source: {
|
|
318
340
|
entry: {
|
|
319
341
|
index: './src/index.ts'
|
|
@@ -334,4 +356,4 @@ function createShellConfig(o) {
|
|
|
334
356
|
}
|
|
335
357
|
};
|
|
336
358
|
}
|
|
337
|
-
export { DEFAULT_SINGLETONS, RUNTIME_CONFIG_URL, appVersion, assertAsyncBoundary, createRemoteConfig, createShellConfig, esmTwin, installedVersionFrom, isMfCjs, packageNameOf, pluginMfEsmRuntime, remoteFederationOptions, resolvableFrom, runtimeConfigEnv, runtimeConfigEnvs, runtimeConfigHandler, runtimeConfigSetup, sharedSingletons, shellFederationOptions, snapshotEnabled };
|
|
359
|
+
export { DEFAULT_SINGLETONS, RUNTIME_CONFIG_URL, appVersion, assertAsyncBoundary, createRemoteConfig, createShellConfig, esmTwin, headScriptTags, installedVersionFrom, isMfCjs, packageNameOf, pluginMfEsmRuntime, registerHeadScript, remoteFederationOptions, resolvableFrom, runtimeConfigEnv, runtimeConfigEnvs, runtimeConfigHandler, runtimeConfigSetup, sharedSingletons, shellFederationOptions, snapshotEnabled };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mfeflow/rsbuild",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Rsbuild presets for Module Federation 2.0 micro-frontends: createShellConfig and createRemoteConfig with shared singletons, external runtime, manifests, types and error reporting set up.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"micro-frontend",
|