@appshell/webpack-plugin 1.0.0-alpha.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.
Files changed (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +311 -0
  3. package/dist/main.js +14 -0
  4. package/dist/main.js.LICENSE.txt +39 -0
  5. package/dist/types/config/src/axios.d.ts +3 -0
  6. package/dist/types/config/src/axios.d.ts.map +1 -0
  7. package/dist/types/config/src/configmap.d.ts +7 -0
  8. package/dist/types/config/src/configmap.d.ts.map +1 -0
  9. package/dist/types/config/src/deregister.d.ts +3 -0
  10. package/dist/types/config/src/deregister.d.ts.map +1 -0
  11. package/dist/types/config/src/generate.env.d.ts +3 -0
  12. package/dist/types/config/src/generate.env.d.ts.map +1 -0
  13. package/dist/types/config/src/generate.global-config.d.ts +10 -0
  14. package/dist/types/config/src/generate.global-config.d.ts.map +1 -0
  15. package/dist/types/config/src/generate.manifest.d.ts +8 -0
  16. package/dist/types/config/src/generate.manifest.d.ts.map +1 -0
  17. package/dist/types/config/src/index.d.ts +17 -0
  18. package/dist/types/config/src/index.d.ts.map +1 -0
  19. package/dist/types/config/src/mappers/appshell.config.d.ts +3 -0
  20. package/dist/types/config/src/mappers/appshell.config.d.ts.map +1 -0
  21. package/dist/types/config/src/outdated.d.ts +4 -0
  22. package/dist/types/config/src/outdated.d.ts.map +1 -0
  23. package/dist/types/config/src/publish.d.ts +26 -0
  24. package/dist/types/config/src/publish.d.ts.map +1 -0
  25. package/dist/types/config/src/register.d.ts +4 -0
  26. package/dist/types/config/src/register.d.ts.map +1 -0
  27. package/dist/types/config/src/sync.d.ts +21 -0
  28. package/dist/types/config/src/sync.d.ts.map +1 -0
  29. package/dist/types/config/src/types.d.ts +296 -0
  30. package/dist/types/config/src/types.d.ts.map +1 -0
  31. package/dist/types/config/src/utils/blur.d.ts +3 -0
  32. package/dist/types/config/src/utils/blur.d.ts.map +1 -0
  33. package/dist/types/config/src/utils/compare.d.ts +8 -0
  34. package/dist/types/config/src/utils/compare.d.ts.map +1 -0
  35. package/dist/types/config/src/utils/config.d.ts +6 -0
  36. package/dist/types/config/src/utils/config.d.ts.map +1 -0
  37. package/dist/types/config/src/utils/copy.d.ts +11 -0
  38. package/dist/types/config/src/utils/copy.d.ts.map +1 -0
  39. package/dist/types/config/src/utils/index.d.ts +10 -0
  40. package/dist/types/config/src/utils/index.d.ts.map +1 -0
  41. package/dist/types/config/src/utils/isValidUrl.d.ts +3 -0
  42. package/dist/types/config/src/utils/isValidUrl.d.ts.map +1 -0
  43. package/dist/types/config/src/utils/list.d.ts +10 -0
  44. package/dist/types/config/src/utils/list.d.ts.map +1 -0
  45. package/dist/types/config/src/utils/load.d.ts +14 -0
  46. package/dist/types/config/src/utils/load.d.ts.map +1 -0
  47. package/dist/types/config/src/utils/loadJson.d.ts +10 -0
  48. package/dist/types/config/src/utils/loadJson.d.ts.map +1 -0
  49. package/dist/types/config/src/utils/merge.d.ts +4 -0
  50. package/dist/types/config/src/utils/merge.d.ts.map +1 -0
  51. package/dist/types/config/src/validators/AppshellGlobalConfigValidator.d.ts +4 -0
  52. package/dist/types/config/src/validators/AppshellGlobalConfigValidator.d.ts.map +1 -0
  53. package/dist/types/config/src/validators/AppshellManifestValidator.d.ts +4 -0
  54. package/dist/types/config/src/validators/AppshellManifestValidator.d.ts.map +1 -0
  55. package/dist/types/config/src/validators/AppshellTemplateValidator.d.ts +4 -0
  56. package/dist/types/config/src/validators/AppshellTemplateValidator.d.ts.map +1 -0
  57. package/dist/types/config/src/validators/index.d.ts +4 -0
  58. package/dist/types/config/src/validators/index.d.ts.map +1 -0
  59. package/dist/types/webpack-plugin/src/AppshellPlugin.d.ts +43 -0
  60. package/dist/types/webpack-plugin/src/AppshellPlugin.d.ts.map +1 -0
  61. package/dist/types/webpack-plugin/src/index.d.ts +6 -0
  62. package/dist/types/webpack-plugin/src/index.d.ts.map +1 -0
  63. package/package.json +32 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Navaris Technologies, LLC
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,311 @@
1
+ <div align="center">
2
+ <a href="https://github.com/navaris/appshell">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="https://github.com/navaris/appshell/blob/main/assets/branding/appshell-logo-white_2x.png">
5
+ <img alt="appshell" src="https://github.com/navaris/appshell/blob/main/assets/branding/appshell-logo_2x.png">
6
+ </picture>
7
+ </a>
8
+ </div>
9
+
10
+ [![Appshell CI](https://github.com/navaris/appshell/actions/workflows/pipeline.yml/badge.svg)](https://github.com/navaris/appshell/actions/workflows/pipeline.yml)
11
+
12
+ # @appshell/webpack-plugin
13
+
14
+ Emits an appshell manifest template for building micro-frontends with Appshell and Webpack Module Federation. The appshell manifest template is subseqently processed to generate an `appshell manifest`.
15
+
16
+ Working examples can be found [here](https://github.com/navaris/appshell/tree/main/examples).
17
+
18
+ ## Getting Started
19
+
20
+ To begin, you'll need to install `@appshell/webpack-plugin`:
21
+
22
+ ```console
23
+ npm install @appshell/webpack-plugin --save-dev
24
+ ```
25
+
26
+ or
27
+
28
+ ```console
29
+ yarn add -D @appshell/webpack-plugin
30
+ ```
31
+
32
+ or
33
+
34
+ ```console
35
+ pnpm add -D @appshell/webpack-plugin
36
+ ```
37
+
38
+ Then add the plugin to the `webpack` config of each remote app module. For example:
39
+
40
+ **webpack.config.js**
41
+
42
+ ```js
43
+ const { AppshellPlugin } = require('@appshell/webpack-plugin');
44
+
45
+ module.exports = {
46
+ plugins: [
47
+ new AppshellPlugin({
48
+ config: './path/to/appshell.config.yaml',
49
+ }),
50
+ ],
51
+ };
52
+ ```
53
+
54
+ ## Publishing on build
55
+
56
+ The plugin can publish the generated manifest to an Appshell registry after every successful build,
57
+ so a running `--watch` keeps an environment current as you work. It is **off by default** — nothing
58
+ is sent anywhere unless you opt in.
59
+
60
+ ```js
61
+ new AppshellPlugin({
62
+ config: './path/to/appshell.config.yaml',
63
+ registry: 'https://registry.example.com',
64
+ environment: 'acme/my-dev', // optional: activate the published version here
65
+ publish: true,
66
+ });
67
+ ```
68
+
69
+ Every option falls back to an environment variable, which is usually how you enable this — the same
70
+ webpack config then publishes in a dev loop or in CI without being edited:
71
+
72
+ | Option | Variable | Notes |
73
+ | ------------- | --------------------------- | ------------------------------------------------ |
74
+ | `publish` | `APPSHELL_PUBLISH_ON_BUILD` | Any non-empty value opts in |
75
+ | `registry` | `APPSHELL_REGISTRY_URL` | Required when publishing |
76
+ | `environment` | `APPSHELL_ENVIRONMENT` | `scope/name`; omit to publish without activating |
77
+ | — | `APPSHELL_TOKEN` | Bearer token. Never a plugin option |
78
+
79
+ The app is published under its **npm** name and version, unscoped — the registry takes the scope
80
+ from your token. Publishing the same content twice is a no-op, so a watch loop that rebuilds without
81
+ a version bump is harmless; publishing _different_ content under an existing version is rejected.
82
+
83
+ A failed publish is reported as a compilation error rather than thrown, so `--watch` reports it and
84
+ keeps running.
85
+
86
+ **What is appshell.config.yaml?**
87
+
88
+ > A configuration file consumed by the plugin to provide additional information and context to the Appshell host about remote entrypoints, routing, display names, etc.
89
+
90
+ Sample appshell.config.yaml
91
+
92
+ ```yaml
93
+ remotes:
94
+ TestModule/Foo: # Must match the scope/module defined in ModuleFederationPlugin
95
+ url: ${APPS_TEST_URL}/remoteEntry.js # Environment variables will be expanded when the global runtime manifest is generated.
96
+ metadata: # Use metadata to provide additional information
97
+ route: ${FOO_ROUTE}
98
+ displayName: Foo App
99
+ displayGroup: main
100
+ order: 10
101
+ icon: ViewList
102
+
103
+ TestModule/Bar:
104
+ url: ${APPS_TEST_URL}/remoteEntry.js
105
+ metadata:
106
+ route: /bar
107
+ displayName: Bar App
108
+ displayGroup: main
109
+ order: 20
110
+ icon: ViewList
111
+
112
+ BizModule/Biz:
113
+ url: http://localhost:4040/remoteEntry.js
114
+ metadata:
115
+ route: /biz
116
+ displayName: Biz App
117
+ displayGroup: auxiliary
118
+ order: 30
119
+ icon: ViewList
120
+
121
+ environment:
122
+ RUNTIME_ARG_1: ${RUNTIME_ARG_1}
123
+ RUNTIME_ARG_2: ${RUNTIME_ARG_2}
124
+ RUNTIME_ARG_3: ${RUNTIME_ARG_3}
125
+ ```
126
+
127
+ > **Note** the variable expansion syntax `${CRA_MFE_URL}`. When the `appshell manifest` is generated the actual runtime environment values are injected.
128
+
129
+ > **Note** the `environment` section defines runtime environment variables that are injected into the global namesapce `window.__appshell_env__[module_name]` when an Appshell component is loaded. See the examples for a use case.
130
+
131
+ **What happens at build time?**
132
+
133
+ > The plugin emits a manifest template file that is subsequently used to generate the `appshell manifest` at runtime.
134
+
135
+ ## Sample output
136
+
137
+ ```json
138
+ {
139
+ "remotes": {
140
+ "CraModule/App": {
141
+ "url": "${CRA_MFE_URL}",
142
+ "metadata": {
143
+ "route": "/cra",
144
+ "displayName": "Example App",
145
+ "displayGroup": "${CRA_MFE_DISPLAY_GROUP}",
146
+ "order": 10,
147
+ "icon": "ViewList"
148
+ },
149
+ "id": "3eb81a0c"
150
+ }
151
+ },
152
+ "module": {
153
+ "exposes": {
154
+ "./App": "./src/App"
155
+ },
156
+ "filename": "remoteEntry.js",
157
+ "name": "CraModule",
158
+ "shared": {
159
+ "react": {
160
+ "singleton": true,
161
+ "requiredVersion": "^18.2.0"
162
+ },
163
+ "react-dom": {
164
+ "singleton": true,
165
+ "requiredVersion": "^18.2.0"
166
+ }
167
+ }
168
+ }
169
+ }
170
+ ```
171
+
172
+ **How do I generate the appshell manifest?**
173
+
174
+ > Use [@appshell/cli](https://www.npmjs.com/package/@appshell/config) in a startup script:
175
+
176
+ ```bash
177
+ appshell generate manifest --template appshell.template.json
178
+ ```
179
+
180
+ Sample `appshell manifest`:
181
+
182
+ ```json
183
+ {
184
+ "remotes": {
185
+ "CraModule/App": {
186
+ "id": "3eb81a0c",
187
+ "url": "http://localhost:3000/remoteEntry.js",
188
+ "scope": "CraModule",
189
+ "module": "./App",
190
+ "metadata": {
191
+ "route": "/cra",
192
+ "displayName": "Example App",
193
+ "displayGroup": "main",
194
+ "order": 10,
195
+ "icon": "ViewList"
196
+ }
197
+ },
198
+ "VanillaModule/Vanilla": {
199
+ "id": "8232ce86",
200
+ "url": "http://localhost:5000/remoteEntry.js",
201
+ "scope": "VanillaModule",
202
+ "module": "./Vanilla",
203
+ "metadata": {
204
+ "route": "/vanilla",
205
+ "displayName": "Example React App",
206
+ "displayGroup": "main",
207
+ "order": 10,
208
+ "icon": "ViewList"
209
+ }
210
+ }
211
+ },
212
+ "modules": {
213
+ "Appshell": {
214
+ "name": "Appshell",
215
+ "shared": {
216
+ "react": {
217
+ "singleton": true,
218
+ "requiredVersion": "^18.2.0"
219
+ },
220
+ "react-dom": {
221
+ "singleton": true,
222
+ "requiredVersion": "^18.2.0"
223
+ }
224
+ }
225
+ },
226
+ "CraModule": {
227
+ "exposes": {
228
+ "./App": "./src/App"
229
+ },
230
+ "filename": "remoteEntry.js",
231
+ "name": "CraModule",
232
+ "shared": {
233
+ "react": {
234
+ "singleton": true,
235
+ "requiredVersion": "^18.2.0"
236
+ },
237
+ "react-dom": {
238
+ "singleton": true,
239
+ "requiredVersion": "^18.2.0"
240
+ }
241
+ }
242
+ },
243
+ "VanillaModule": {
244
+ "exposes": {
245
+ "./Vanilla": "./src/App"
246
+ },
247
+ "filename": "remoteEntry.js",
248
+ "name": "VanillaModule",
249
+ "shared": {
250
+ "react": {
251
+ "singleton": true,
252
+ "requiredVersion": "^18.2.0"
253
+ },
254
+ "react-dom": {
255
+ "singleton": true,
256
+ "requiredVersion": "^18.2.0"
257
+ }
258
+ }
259
+ }
260
+ },
261
+ "environment": {
262
+ "CraModule": {
263
+ "RUNTIME_ARG_1": "Foo",
264
+ "RUNTIME_ARG_2": "Biz"
265
+ },
266
+ "VanillaModule": {
267
+ "RUNTIME_ARG_1": "Bar"
268
+ }
269
+ }
270
+ }
271
+ ```
272
+
273
+ ## Options
274
+
275
+ - **[`options`](#options-1)**
276
+
277
+ The plugin's signature:
278
+
279
+ **webpack.config.js**
280
+
281
+ ```js
282
+ const { AppshellPlugin } = require('@appshell/webpack-plugin');
283
+
284
+ module.exports = {
285
+ plugins: [
286
+ new AppshellPlugin({
287
+ config: './path/to/appshell.config.yaml',
288
+ }),
289
+ ],
290
+ };
291
+ ```
292
+
293
+ ### `Options`
294
+
295
+ - [`config`](#config)
296
+
297
+ #### `config`
298
+
299
+ Type:
300
+
301
+ ```ts
302
+ type config = string;
303
+ ```
304
+
305
+ Default: `appshell.config.yaml`
306
+
307
+ Location of the `appshell.config.yaml` file.
308
+
309
+ ## License
310
+
311
+ [MIT](./LICENSE)