@module-federation/esbuild 0.0.0-feat-support-bridge-react-router-v7-20251015102312
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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/adapters/lib/collect-exports.d.ts +3 -0
- package/dist/adapters/lib/commonjs.d.ts +101 -0
- package/dist/adapters/lib/containerPlugin.d.ts +6 -0
- package/dist/adapters/lib/containerReference.d.ts +6 -0
- package/dist/adapters/lib/lexer.d.ts +9 -0
- package/dist/adapters/lib/linkRemotesPlugin.d.ts +6 -0
- package/dist/adapters/lib/manifest.d.ts +2 -0
- package/dist/adapters/lib/plugin.d.ts +8 -0
- package/dist/adapters/lib/react-replacements.d.ts +9 -0
- package/dist/adapters/lib/transform.d.ts +8 -0
- package/dist/adapters/lib/utils.d.ts +3 -0
- package/dist/build.d.ts +5 -0
- package/dist/build.js +481 -0
- package/dist/build.mjs +380 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +36 -0
- package/dist/index.mjs +2 -0
- package/dist/lib/config/configuration-context.d.ts +7 -0
- package/dist/lib/config/federation-config.d.ts +30 -0
- package/dist/lib/config/share-utils.d.ts +29 -0
- package/dist/lib/config/with-native-federation.d.ts +23 -0
- package/dist/lib/core/build-adapter.d.ts +4 -0
- package/dist/lib/core/createContainerTemplate.d.ts +1 -0
- package/dist/lib/core/default-skip-list.d.ts +12 -0
- package/dist/lib/core/federation-options.d.ts +10 -0
- package/dist/lib/core/get-externals.d.ts +2 -0
- package/dist/lib/core/load-federation-config.d.ts +6 -0
- package/dist/lib/core/write-federation-info.d.ts +9 -0
- package/dist/lib/utils/logger.d.ts +11 -0
- package/dist/lib/utils/mapped-paths.d.ts +10 -0
- package/dist/lib/utils/normalize.d.ts +1 -0
- package/dist/lib/utils/package-info.d.ts +18 -0
- package/dist/plugin.js +1247 -0
- package/dist/plugin.mjs +1190 -0
- package/dist/resolve/esm-resolver.mjs +26 -0
- package/dist/resolve/package.json +3 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-present zhouxiao(zhoushaw)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# @module-federation/esbuild
|
|
2
|
+
|
|
3
|
+
This package provides an esbuild plugin for Module Federation, enabling you to easily share code between independently built and deployed applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Install the package using npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @module-federation/esbuild
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
To use the Module Federation plugin with esbuild, add it to your esbuild configuration:
|
|
16
|
+
|
|
17
|
+
```js
|
|
18
|
+
const esbuild = require('esbuild');
|
|
19
|
+
const path = require('path');
|
|
20
|
+
const { moduleFederationPlugin } = require('@module-federation/esbuild/plugin');
|
|
21
|
+
const federationConfig = require('./federation.config.js');
|
|
22
|
+
|
|
23
|
+
async function buildApp() {
|
|
24
|
+
const tsConfig = 'tsconfig.json';
|
|
25
|
+
const outputPath = path.join('dist', 'host');
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
await esbuild.build({
|
|
29
|
+
entryPoints: [path.join('host', 'main.ts')],
|
|
30
|
+
outdir: outputPath,
|
|
31
|
+
bundle: true,
|
|
32
|
+
platform: 'browser',
|
|
33
|
+
format: 'esm',
|
|
34
|
+
mainFields: ['es2020', 'browser', 'module', 'main'],
|
|
35
|
+
conditions: ['es2020', 'es2015', 'module'],
|
|
36
|
+
resolveExtensions: ['.ts', '.tsx', '.mjs', '.js'],
|
|
37
|
+
tsconfig: tsConfig,
|
|
38
|
+
splitting: true,
|
|
39
|
+
plugins: [moduleFederationPlugin(federationConfig)],
|
|
40
|
+
});
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.error(err);
|
|
43
|
+
process.exit(1);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
buildApp();
|
|
48
|
+
|
|
49
|
+
// Example of federation.config.js
|
|
50
|
+
|
|
51
|
+
const { withFederation, shareAll } = require('@module-federation/esbuild/build');
|
|
52
|
+
|
|
53
|
+
module.exports = withFederation({
|
|
54
|
+
name: 'host',
|
|
55
|
+
filename: 'remoteEntry.js',
|
|
56
|
+
exposes: {
|
|
57
|
+
'./Component': './src/Component',
|
|
58
|
+
},
|
|
59
|
+
shared: {
|
|
60
|
+
react: {
|
|
61
|
+
singleton: true,
|
|
62
|
+
version: '^18.2.0',
|
|
63
|
+
},
|
|
64
|
+
'react-dom': {
|
|
65
|
+
singleton: true,
|
|
66
|
+
version: '^18.2.0',
|
|
67
|
+
},
|
|
68
|
+
rxjs: {
|
|
69
|
+
singleton: true,
|
|
70
|
+
version: '^7.8.1',
|
|
71
|
+
},
|
|
72
|
+
...shareAll({
|
|
73
|
+
singleton: true,
|
|
74
|
+
strictVersion: true,
|
|
75
|
+
requiredVersion: 'auto',
|
|
76
|
+
includeSecondaries: false,
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
The `moduleFederationPlugin` accepts a configuration object with the following properties:
|
|
83
|
+
|
|
84
|
+
- `name` (string): The name of the host application.
|
|
85
|
+
- `filename` (string, optional): The name of the remote entry file. Defaults to `'remoteEntry.js'`.
|
|
86
|
+
- `remotes` (object, optional): An object specifying the remote applications and their entry points.
|
|
87
|
+
- `exposes` (object, optional): An object specifying the modules to be exposed by the host application.
|
|
88
|
+
- `shared` (array, optional): An array of package names to be shared between the host and remote applications.
|
|
89
|
+
|
|
90
|
+
## Plugin Features
|
|
91
|
+
|
|
92
|
+
The `moduleFederationPlugin` includes the following features:
|
|
93
|
+
|
|
94
|
+
- **Virtual Share Module**: Creates a virtual module for sharing dependencies between the host and remote applications.
|
|
95
|
+
- **Virtual Remote Module**: Creates a virtual module for importing exposed modules from remote applications.
|
|
96
|
+
- **CommonJS to ESM Transformation**: Transforms CommonJS modules to ESM format for compatibility with Module Federation.
|
|
97
|
+
- **Shared Dependencies Linking**: Links shared dependencies between the host and remote applications.
|
|
98
|
+
- **Manifest Generation**: Generates a manifest file containing information about the exposed modules and their exports.
|
|
99
|
+
|
|
100
|
+
## API
|
|
101
|
+
|
|
102
|
+
### `moduleFederationPlugin(config)`
|
|
103
|
+
|
|
104
|
+
Creates an esbuild plugin for Module Federation.
|
|
105
|
+
|
|
106
|
+
- `config` (object): The Module Federation configuration.
|
|
107
|
+
- `name` (string): The name of the host application.
|
|
108
|
+
- `filename` (string, optional): The name of the remote entry file. Defaults to `'remoteEntry.js'`.
|
|
109
|
+
- `remotes` (object, optional): An object specifying the remote applications and their entry points.
|
|
110
|
+
- `exposes` (object, optional): An object specifying the modules to be exposed by the host application.
|
|
111
|
+
- `shared` (array, optional): An array of package names to be shared between the host and remote applications.
|
|
112
|
+
|
|
113
|
+
Returns an esbuild plugin instance.
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const resolve: (arg1: string, arg2: string) => Promise<string | false | undefined>;
|
|
2
|
+
export declare const resolvePackageJson: (packageName: string, callback: (err: Error | null, result?: string) => void) => Promise<void>;
|
|
3
|
+
export declare function getExports(modulePath: string): Promise<string[]>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Plugin } from 'esbuild';
|
|
2
|
+
export interface CommonJSOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The regexp passed to onLoad() to match commonjs files.
|
|
5
|
+
*
|
|
6
|
+
* @default /\.c?js$/
|
|
7
|
+
*/
|
|
8
|
+
filter?: RegExp;
|
|
9
|
+
/**
|
|
10
|
+
* _Experimental_: Transform commonjs to es modules. You have to install
|
|
11
|
+
* `cjs-module-lexer` to let it work.
|
|
12
|
+
*
|
|
13
|
+
* When `true`, the plugin tries to wrap the commonjs module into:
|
|
14
|
+
*
|
|
15
|
+
* ```js
|
|
16
|
+
* var exports = {}, module = { exports };
|
|
17
|
+
* {
|
|
18
|
+
* // ... original content ...
|
|
19
|
+
* }
|
|
20
|
+
* exports = module.exports;
|
|
21
|
+
* // the exported names are extracted by cjs-module-lexer
|
|
22
|
+
* export default exports;
|
|
23
|
+
* var { something, "a-b" as a_b } = exports;
|
|
24
|
+
* export { something, a_b as "a-b" };
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @default false
|
|
28
|
+
*/
|
|
29
|
+
transform?: boolean | ((path: string) => boolean | TransformConfig | null | void);
|
|
30
|
+
/**
|
|
31
|
+
* _Experimental_: This options acts as a fallback of the `transform` option above.
|
|
32
|
+
*/
|
|
33
|
+
transformConfig?: Pick<TransformConfig, 'behavior' | 'sideEffects'>;
|
|
34
|
+
/**
|
|
35
|
+
* Controls which style of import should be used. By default, it transforms:
|
|
36
|
+
*
|
|
37
|
+
* ```js
|
|
38
|
+
* // input
|
|
39
|
+
* const foo = require("foo")
|
|
40
|
+
* // output
|
|
41
|
+
* import foo from "foo"
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* The above case is often correct when 'foo' is also a commonjs module.
|
|
45
|
+
* But if 'foo' has es module exports, it is better to use:
|
|
46
|
+
*
|
|
47
|
+
* ```js
|
|
48
|
+
* // output
|
|
49
|
+
* import * as foo from "foo"
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* In which case you can set `requireReturnsDefault` to `false` to get the above output.
|
|
53
|
+
* Or use the callback style to control the behavior for each module.
|
|
54
|
+
*
|
|
55
|
+
* @default true
|
|
56
|
+
*/
|
|
57
|
+
requireReturnsDefault?: boolean | ((path: string) => boolean);
|
|
58
|
+
/**
|
|
59
|
+
* Don't replace require("ignored-modules"). Note that this will cause
|
|
60
|
+
* esbuild generates the __require() wrapper which throw error at runtime.
|
|
61
|
+
*/
|
|
62
|
+
ignore?: string[] | ((path: string) => boolean);
|
|
63
|
+
}
|
|
64
|
+
export interface TransformConfig {
|
|
65
|
+
/**
|
|
66
|
+
* If `"babel"`, it will check if there be `exports.__esModule`,
|
|
67
|
+
* then export `exports.default`. i.e. The wrapper code becomes:
|
|
68
|
+
*
|
|
69
|
+
* ```js
|
|
70
|
+
* export default exports.__esModule ? exports.default : exports;
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @default "node"
|
|
74
|
+
*/
|
|
75
|
+
behavior?: 'babel' | 'node';
|
|
76
|
+
/**
|
|
77
|
+
* Also include these named exports if they aren't recognized automatically.
|
|
78
|
+
*
|
|
79
|
+
* @example ["something"]
|
|
80
|
+
*/
|
|
81
|
+
exports?: string[];
|
|
82
|
+
/**
|
|
83
|
+
* If `false`, slightly change the result to make it side-effect free.
|
|
84
|
+
* But it doesn't actually remove many code. So you maybe not need this.
|
|
85
|
+
*
|
|
86
|
+
* ```js
|
|
87
|
+
* var mod;
|
|
88
|
+
* var exports = /\*#__PURE__*\/ ((exports, module) => {
|
|
89
|
+
* // ... original content ...
|
|
90
|
+
* return module.exports;
|
|
91
|
+
* })((mod = { exports: {} }).exports, mod);
|
|
92
|
+
* export default exports;
|
|
93
|
+
* var a_b = /\*#__PURE__*\/ (() => exports['a-b'])();
|
|
94
|
+
* var something = /\*#__PURE__*\/ (() => exports.something)();
|
|
95
|
+
* export { a_b as "a-b", something };
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
sideEffects?: boolean;
|
|
99
|
+
}
|
|
100
|
+
export declare function commonjs({ filter, transform, transformConfig, requireReturnsDefault, ignore, }?: CommonJSOptions): Plugin;
|
|
101
|
+
export default commonjs;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NormalizedFederationConfig } from '../../lib/config/federation-config';
|
|
2
|
+
export declare const buildFederationHost: (config: NormalizedFederationConfig) => string;
|
|
3
|
+
export declare const initializeHostPlugin: (config: NormalizedFederationConfig) => {
|
|
4
|
+
name: string;
|
|
5
|
+
setup(build: any): void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare class Lexer {
|
|
2
|
+
input: string;
|
|
3
|
+
pos: number;
|
|
4
|
+
readString(input: string, pos: number): string | null;
|
|
5
|
+
readEscapedChar(): string | null;
|
|
6
|
+
readInt(radix: number, len: number): number | null;
|
|
7
|
+
readHexChar(len: number): number | null;
|
|
8
|
+
readCodePoint(): number | null;
|
|
9
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { NormalizedFederationConfig } from '../../lib/config/federation-config';
|
|
2
|
+
export declare const createVirtualRemoteModule: (name: string, ref: string) => string;
|
|
3
|
+
export declare const linkRemotesPlugin: (config: NormalizedFederationConfig) => {
|
|
4
|
+
name: string;
|
|
5
|
+
setup(build: any): void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PluginBuild } from 'esbuild';
|
|
2
|
+
import { NormalizedFederationConfig } from '../../lib/config/federation-config.js';
|
|
3
|
+
export declare const createVirtualShareModule: (name: string, ref: string, exports: string[]) => string;
|
|
4
|
+
export declare const createVirtualRemoteModule: (name: string, ref: string) => string;
|
|
5
|
+
export declare const moduleFederationPlugin: (config: NormalizedFederationConfig) => {
|
|
6
|
+
name: string;
|
|
7
|
+
setup(build: PluginBuild): void;
|
|
8
|
+
};
|