@module-federation/native-federation-typescript 0.1.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 ADDED
@@ -0,0 +1,28 @@
1
+ # Changelog
2
+
3
+ This file was generated using [@jscutlery/semver](https://github.com/jscutlery/semver).
4
+
5
+ # 0.1.0 (2023-04-05)
6
+
7
+
8
+ ### Bug Fixes
9
+
10
+ * build ([d0b2f72](https://github.com/module-federation/nextjs-mf/commit/d0b2f72f4fc3647825412be1574311c3152cf167))
11
+ * build step ([a217170](https://github.com/module-federation/nextjs-mf/commit/a21717096cbc09bff20d3aeebfea2f3533afb0d7))
12
+ * compiler instance ([e5c249d](https://github.com/module-federation/nextjs-mf/commit/e5c249d41d68339886268337654ff47b31b06a3a))
13
+ * deps ([a378441](https://github.com/module-federation/nextjs-mf/commit/a37844194a3f189cc5863bbdd4776259bce69fa4))
14
+ * dirtree tests ([5cb49fd](https://github.com/module-federation/nextjs-mf/commit/5cb49fd1c6520311a7d2e7d2b37a93389a500715))
15
+ * eslintrc ([0f69dee](https://github.com/module-federation/nextjs-mf/commit/0f69dee253c2c608b2367d545c7d4a57ad0c2ca5))
16
+ * format ([25fb765](https://github.com/module-federation/nextjs-mf/commit/25fb7659481287a791e9de4fe839e980dbf06968))
17
+ * readme ([eaca0b3](https://github.com/module-federation/nextjs-mf/commit/eaca0b311d3b8d9e73309cb92d9a9488f9fc23c0))
18
+ * readme ([fc0e5dc](https://github.com/module-federation/nextjs-mf/commit/fc0e5dc26e617664224e1c10548b151a44f8dff9))
19
+ * README.md ([9159171](https://github.com/module-federation/nextjs-mf/commit/91591712e9a103fff351f0a168c149470c0d69ad))
20
+ * remove changelog ([724918e](https://github.com/module-federation/nextjs-mf/commit/724918ebf888297689b6ed700bd14ec01fd1ef35))
21
+ * ts build ([9ed3a52](https://github.com/module-federation/nextjs-mf/commit/9ed3a527d0ba903b6cfa6023a7ad5da63781970c))
22
+
23
+
24
+ ### Features
25
+
26
+ * federated tests plugin ([063ab33](https://github.com/module-federation/nextjs-mf/commit/063ab336c4830aff4f5bd3b9894df60b4651a9be))
27
+ * native-federation-typescript plugin ([#692](https://github.com/module-federation/nextjs-mf/issues/692)) ([b41c5aa](https://github.com/module-federation/nextjs-mf/commit/b41c5aacfeda0fada5b426086658235edfd86cdd))
28
+ * test command ([3ade629](https://github.com/module-federation/nextjs-mf/commit/3ade629488f4ea1549314b82b41caef9a046da9f))
package/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # native-federation-typescript
2
+
3
+ Bundler agnostic plugins to share federated types.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm i -D @module-federation/native-federation-typescript
9
+ ```
10
+
11
+ This module provides two plugins:
12
+
13
+ ### NativeFederationTypeScriptRemote
14
+ This plugin is used to build the federated types.
15
+
16
+ #### Configuration
17
+ ```typescript
18
+ {
19
+ moduleFederationConfig: any; // the configuration same configuration provided to the module federation plugin, it is MANDATORY
20
+ tsConfigPath?: string; // path where the tsconfig file is located, default is ''./tsconfig.json'
21
+ typesFolder?: string; // folder where all the files will be stored, default is '@mf-types',
22
+ compiledTypesFolder?: string; // folder where the federated modules types will be stored, default is 'compiled-types'
23
+ deleteTypesFolder?: boolean; // indicate if the types folder will be deleted when the job completes, default is 'true'
24
+ additionalFilesToCompile?: string[] // The path of each additional file which should be emitted
25
+ compilerInstance?: 'tsc' | 'vue-tsc' // The compiler to use to emit files, default is 'tsc'
26
+ }
27
+ ```
28
+
29
+ #### Additional configuration
30
+ Note that, for Webpack, the plugin automatically inject the `devServer.static.directory` configuration.
31
+ For the other bundlers, you should configure it by yourself.
32
+
33
+ ### NativeFederationTypeScriptHost
34
+ This plugin is used to download the federated types.
35
+
36
+ ### Configuration
37
+
38
+ ```typescript
39
+ {
40
+ moduleFederationConfig: any; // the configuration same configuration provided to the module federation plugin, it is MANDATORY
41
+ typesFolder?: string; // folder where all the files will be stored, default is '@mf-types',
42
+ deleteTypesFolder?: boolean; // indicate if the types folder will be deleted before the job starts, default is 'true'
43
+ }
44
+ ```
45
+
46
+ ## Bundler configuration
47
+
48
+ <details>
49
+ <summary>Vite</summary><br>
50
+
51
+ ```ts
52
+ // vite.config.ts
53
+ import {NativeFederationTypeScriptHost, NativeFederationTypeScriptRemote} from '@module-federation/native-federation-typescript/vite'
54
+
55
+ export default defineConfig({
56
+ plugins: [
57
+ NativeFederationTypeScriptRemote({ /* options */ }),
58
+ NativeFederationTypeScriptHost({ /* options */ }),
59
+ ],
60
+ /* ... */
61
+ server: { // This is needed to emulate the devServer.static.directory of WebPack and correctly serve the zip file
62
+ /* ... */
63
+ proxy: {
64
+ '/@mf-types.zip': {
65
+ target: 'http://localhost:3000',
66
+ changeOrigin: true,
67
+ rewrite: () => `/@fs/${process.cwd()}/dist/@mf-types.zip`
68
+ }
69
+ },
70
+ fs: {
71
+ /* ... */
72
+ allow: ['./dist']
73
+ /* ... */
74
+ }
75
+ }
76
+ })
77
+ ```
78
+
79
+ <br>
80
+ </details>
81
+ <details>
82
+ <summary>Rollup</summary><br>
83
+
84
+ ```ts
85
+ // rollup.config.js
86
+ import {NativeFederationTypeScriptHost, NativeFederationTypeScriptRemote} from '@module-federation/native-federation-typescript/rollup'
87
+
88
+ export default {
89
+ plugins: [
90
+ NativeFederationTypeScriptRemote({ /* options */ }),
91
+ NativeFederationTypeScriptHost({ /* options */ }),
92
+ ],
93
+ }
94
+ ```
95
+
96
+ <br>
97
+ </details>
98
+ <details>
99
+ <summary>Webpack</summary><br>
100
+
101
+ ```ts
102
+ // webpack.config.js
103
+ const {NativeFederationTypeScriptHost, NativeFederationTypeScriptRemote} = require('@module-federation/native-federation-typescript/webpack')
104
+ module.exports = {
105
+ /* ... */
106
+ plugins: [
107
+ NativeFederationTypeScriptRemote({ /* options */ }),
108
+ NativeFederationTypeScriptHost({ /* options */ })
109
+ ]
110
+ }
111
+ ```
112
+
113
+ <br>
114
+ </details>
115
+ <details>
116
+ <summary>esbuild</summary><br>
117
+
118
+ ```ts
119
+ // esbuild.config.js
120
+ import { build } from 'esbuild'
121
+ import {NativeFederationTypeScriptHost, NativeFederationTypeScriptRemote} from '@module-federation/native-federation-typescript/esbuild'
122
+
123
+ build({
124
+ plugins: [
125
+ NativeFederationTypeScriptRemote({ /* options */ }),
126
+ NativeFederationTypeScriptHost({ /* options */ })
127
+ ],
128
+ })
129
+ ```
130
+
131
+ <br>
132
+ </details>
133
+ <details>
134
+ <summary>Rspack</summary><br>
135
+
136
+ ```ts
137
+ // rspack.config.js
138
+ const {NativeFederationTypeScriptHost, NativeFederationTypeScriptRemote} = require('@module-federation/native-federation-typescript/rspack')
139
+ module.exports = {
140
+ /* ... */
141
+ plugins: [
142
+ NativeFederationTypeScriptRemote({ /* options */ }),
143
+ NativeFederationTypeScriptHost({ /* options */ })
144
+ ]
145
+ }
146
+ ```
147
+
148
+ <br>
149
+ </details>
150
+
151
+ ## TypeScript configuration
152
+
153
+ To have the type definitions automatically found for imports, add paths to the `compilerOptions` in the `tsconfig.json`:
154
+
155
+ ```json
156
+ {
157
+ "paths": {
158
+ "*": ["./@mf-types/*"]
159
+ }
160
+ }
161
+ ```
162
+
163
+ ## Examples
164
+
165
+ To use it in a `host` module, refer to [this example](https://github.com/ilteoood/module-federation-typescript/tree/host).
166
+ To use it in a `remote` module, refer to [this example](https://github.com/ilteoood/module-federation-typescript/tree/remote).
@@ -0,0 +1,17 @@
1
+ interface HostOptions {
2
+ moduleFederationConfig: any;
3
+ typesFolder?: string;
4
+ deleteTypesFolder?: boolean;
5
+ }
6
+
7
+ interface RemoteOptions {
8
+ moduleFederationConfig: any;
9
+ tsConfigPath?: string;
10
+ typesFolder?: string;
11
+ compiledTypesFolder?: string;
12
+ deleteTypesFolder?: boolean;
13
+ additionalFilesToCompile?: string[];
14
+ compilerInstance?: 'tsc' | 'vue-tsc';
15
+ }
16
+
17
+ export { HostOptions as H, RemoteOptions as R };