@squide/firefly-webpack-configs 4.2.1 → 4.2.3

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @squide/firefly-webpack-configs
2
2
 
3
+ ## 4.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#231](https://github.com/gsoft-inc/wl-squide/pull/231) [`3c6bce0`](https://github.com/gsoft-inc/wl-squide/commit/3c6bce0cd559d0b8517d644661b6fb2b818ab2f6) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Packages now includes source code and sourcemap.
8
+
9
+ ## 4.2.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#225](https://github.com/gsoft-inc/wl-squide/pull/225) [`4eb46d6`](https://github.com/gsoft-inc/wl-squide/commit/4eb46d69283804a5809494f7275f9d447022a97d) Thanks [@patricklafrance](https://github.com/patricklafrance)! - Added additional shared dependencies for Honeycomb.
14
+
3
15
  ## 4.2.1
4
16
 
5
17
  ### Patch Changes
@@ -0,0 +1,59 @@
1
+ import { ModuleFederationPlugin } from "@module-federation/enhanced/webpack";
2
+ import type { SwcConfig } from "@workleap/swc-configs";
3
+ import { type DefineBuildConfigOptions, type DefineDevConfigOptions } from "@workleap/webpack-configs";
4
+ import type HtmlWebpackPlugin from "html-webpack-plugin";
5
+ import type webpack from "webpack";
6
+ export type ModuleFederationPluginOptions = ConstructorParameters<typeof ModuleFederationPlugin>[0];
7
+ export type ModuleFederationRemotesOption = ModuleFederationPluginOptions["remotes"];
8
+ export type ModuleFederationRuntimePlugins = NonNullable<ModuleFederationPluginOptions["runtimePlugins"]>;
9
+ export type ModuleFederationShared = NonNullable<ModuleFederationPluginOptions["shared"]>;
10
+ export type Router = "react-router";
11
+ export interface Features {
12
+ router?: Router;
13
+ msw?: boolean;
14
+ i18next?: boolean;
15
+ environmentVariables?: boolean;
16
+ honeycomb?: boolean;
17
+ }
18
+ export interface RemoteDefinition {
19
+ name: string;
20
+ url: string;
21
+ }
22
+ export interface DefineHostModuleFederationPluginOptions extends ModuleFederationPluginOptions {
23
+ features?: Features;
24
+ }
25
+ export declare function defineHostModuleFederationPluginOptions(remotes: RemoteDefinition[], options: DefineHostModuleFederationPluginOptions): ModuleFederationPluginOptions;
26
+ export interface DefineDevHostConfigOptions extends Omit<DefineDevConfigOptions, "htmlWebpackPlugin" | "port"> {
27
+ htmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;
28
+ features?: Features;
29
+ sharedDependencies?: ModuleFederationShared;
30
+ runtimePlugins?: ModuleFederationRuntimePlugins;
31
+ moduleFederationPluginOptions?: ModuleFederationPluginOptions;
32
+ }
33
+ export declare function defineDevHostConfig(swcConfig: SwcConfig, port: number, remotes: RemoteDefinition[], options?: DefineDevHostConfigOptions): webpack.Configuration;
34
+ export interface DefineBuildHostConfigOptions extends Omit<DefineBuildConfigOptions, "htmlWebpackPlugin"> {
35
+ htmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;
36
+ features?: Features;
37
+ sharedDependencies?: ModuleFederationShared;
38
+ runtimePlugins?: ModuleFederationRuntimePlugins;
39
+ moduleFederationPluginOptions?: ModuleFederationPluginOptions;
40
+ }
41
+ export declare function defineBuildHostConfig(swcConfig: SwcConfig, remotes: RemoteDefinition[], options?: DefineBuildHostConfigOptions): webpack.Configuration;
42
+ export interface DefineRemoteModuleFederationPluginOptions extends ModuleFederationPluginOptions {
43
+ features?: Features;
44
+ }
45
+ export declare function defineRemoteModuleFederationPluginOptions(applicationName: string, options: DefineRemoteModuleFederationPluginOptions): ModuleFederationPluginOptions;
46
+ export interface DefineDevRemoteModuleConfigOptions extends Omit<DefineDevConfigOptions, "port" | "overlay"> {
47
+ features?: Features;
48
+ sharedDependencies?: ModuleFederationShared;
49
+ runtimePlugins?: ModuleFederationRuntimePlugins;
50
+ moduleFederationPluginOptions?: ModuleFederationPluginOptions;
51
+ }
52
+ export declare function defineDevRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, port: number, options?: DefineDevRemoteModuleConfigOptions): webpack.Configuration;
53
+ export interface DefineBuildRemoteModuleConfigOptions extends DefineBuildConfigOptions {
54
+ features?: Features;
55
+ sharedDependencies?: ModuleFederationShared;
56
+ runtimePlugins?: ModuleFederationRuntimePlugins;
57
+ moduleFederationPluginOptions?: ModuleFederationPluginOptions;
58
+ }
59
+ export declare function defineBuildRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, options?: DefineBuildRemoteModuleConfigOptions): webpack.Configuration;
@@ -0,0 +1,387 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__module_federation_enhanced_webpack_5184ba07__ from "@module-federation/enhanced/webpack";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__workleap_webpack_configs_227c33a7__ from "@workleap/webpack-configs";
3
+ import * as __WEBPACK_EXTERNAL_MODULE_deepmerge__ from "deepmerge";
4
+ import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
5
+ import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
6
+ import * as __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__ from "node:url";
7
+ import * as __WEBPACK_EXTERNAL_MODULE__shared_js_cc7b7cda__ from "./shared.js";
8
+
9
+ ;// CONCATENATED MODULE: external "@module-federation/enhanced/webpack"
10
+
11
+ ;// CONCATENATED MODULE: external "@workleap/webpack-configs"
12
+
13
+ ;// CONCATENATED MODULE: external "deepmerge"
14
+
15
+ ;// CONCATENATED MODULE: external "node:fs"
16
+
17
+ ;// CONCATENATED MODULE: external "node:path"
18
+
19
+ ;// CONCATENATED MODULE: external "node:url"
20
+
21
+ ;// CONCATENATED MODULE: external "./shared.js"
22
+
23
+ ;// CONCATENATED MODULE: ./src/defineConfig.ts?__rslib_entry__
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+ // Using import.meta.url instead of import.meta.dirname because Jest is throwing the following error:
32
+ // SyntaxError: Cannot use 'import.meta' outside a module
33
+ const applicationDirectory = (0,__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)((0,__WEBPACK_EXTERNAL_MODULE_node_url_e96de089__.fileURLToPath)(import.meta.url));
34
+ const packageDirectory = __WEBPACK_EXTERNAL_MODULE_node_url_e96de089__["default"].fileURLToPath(new URL(".", import.meta.url));
35
+ // Must be similar to the module name defined in @workleap/module-federation.
36
+ const RemoteRegisterModuleName = "./register";
37
+ const RemoteEntryPoint = "remoteEntry.js";
38
+ // Generally, only the host application should have eager dependencies.
39
+ // For more informations about shared dependencies refer to: https://github.com/patricklafrance/wmf-versioning
40
+ function getDefaultSharedDependencies(features, isHost) {
41
+ return {
42
+ "react": {
43
+ singleton: true,
44
+ eager: isHost ? true : undefined,
45
+ // Fixed the warning when `react-i18next` is imported in any remote modules.
46
+ // For more information, refer to: https://github.com/i18next/react-i18next/issues/1697#issuecomment-1821748226.
47
+ requiredVersion: features.i18next ? false : undefined
48
+ },
49
+ "react-dom": {
50
+ singleton: true,
51
+ eager: isHost ? true : undefined
52
+ },
53
+ "@squide/core": {
54
+ singleton: true,
55
+ eager: isHost ? true : undefined
56
+ },
57
+ "@squide/module-federation": {
58
+ singleton: true,
59
+ eager: isHost ? true : undefined
60
+ }
61
+ };
62
+ }
63
+ // Generally, only the host application should have eager dependencies.
64
+ // For more informations about shared dependencies refer to: https://github.com/patricklafrance/wmf-versioning
65
+ function getReactRouterSharedDependencies(isHost) {
66
+ return {
67
+ "react-router-dom": {
68
+ singleton: true,
69
+ eager: isHost ? true : undefined
70
+ },
71
+ "@squide/react-router": {
72
+ singleton: true,
73
+ eager: isHost ? true : undefined
74
+ }
75
+ };
76
+ }
77
+ function getMswSharedDependency(isHost) {
78
+ return {
79
+ "@squide/msw": {
80
+ singleton: true,
81
+ eager: isHost ? true : undefined
82
+ }
83
+ };
84
+ }
85
+ function getI18nextSharedDependency(isHost) {
86
+ return {
87
+ "i18next": {
88
+ singleton: true,
89
+ eager: isHost ? true : undefined
90
+ },
91
+ // Not adding as a shared dependency for the moment because it causes the following error:
92
+ // Uncaught (in promise) TypeError: i18next_browser_languagedetector__WEBPACK_IMPORTED_MODULE_3__ is not a constructor
93
+ // "i18next-browser-languagedetector": {
94
+ // singleton: true,
95
+ // eager: isHost ? true : undefined
96
+ // },
97
+ "react-i18next": {
98
+ singleton: true,
99
+ eager: isHost ? true : undefined
100
+ },
101
+ "@squide/i18next": {
102
+ singleton: true,
103
+ eager: isHost ? true : undefined
104
+ }
105
+ };
106
+ }
107
+ function getEnvironmentVariablesSharedDependencies(isHost) {
108
+ return {
109
+ "@squide/env-vars": {
110
+ singleton: true,
111
+ eager: isHost ? true : undefined
112
+ }
113
+ };
114
+ }
115
+ function getHoneycombSharedDependencies(isHost) {
116
+ return {
117
+ "@honeycombio/opentelemetry-web": {
118
+ singleton: true,
119
+ eager: isHost ? true : undefined
120
+ },
121
+ "@opentelemetry/api": {
122
+ singleton: true,
123
+ eager: isHost ? true : undefined
124
+ },
125
+ "@opentelemetry/auto-instrumentations-web": {
126
+ singleton: true,
127
+ eager: isHost ? true : undefined
128
+ },
129
+ "@squide/firefly-honeycomb": {
130
+ singleton: true,
131
+ eager: isHost ? true : undefined
132
+ }
133
+ };
134
+ }
135
+ function getFeaturesDependencies(features, isHost) {
136
+ const { router = "react-router", msw = true, i18next, environmentVariables, honeycomb } = features;
137
+ return {
138
+ ...router === "react-router" ? getReactRouterSharedDependencies(isHost) : {},
139
+ ...msw ? getMswSharedDependency(isHost) : {},
140
+ ...i18next ? getI18nextSharedDependency(isHost) : {},
141
+ ...environmentVariables ? getEnvironmentVariablesSharedDependencies(isHost) : {},
142
+ ...honeycomb ? getHoneycombSharedDependencies(isHost) : {}
143
+ };
144
+ }
145
+ function resolveDefaultSharedDependencies(features, isHost) {
146
+ return {
147
+ ...getDefaultSharedDependencies(features, isHost),
148
+ ...getFeaturesDependencies(features, isHost)
149
+ };
150
+ }
151
+ const forceNamedChunkIdsTransformer = (config)=>{
152
+ config.optimization = {
153
+ ...config.optimization ?? {},
154
+ // Without named chunk ids, there are some Webpack features that do not work
155
+ // when used with Module Federation. One of these feature is using a dynamic import in
156
+ // a remote module.
157
+ chunkIds: "named"
158
+ };
159
+ return config;
160
+ };
161
+ function createSetUniqueNameTransformer(uniqueName) {
162
+ const transformer = (config)=>{
163
+ config.output = {
164
+ ...config.output ?? {},
165
+ // Every host and remotes must have a "uniqueName" for React Refresh to work
166
+ // with Module Federation.
167
+ uniqueName
168
+ };
169
+ return config;
170
+ };
171
+ return transformer;
172
+ }
173
+ function resolveEntryFilePath(entryPaths) {
174
+ for(const entryPath in entryPaths){
175
+ if (__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(applicationDirectory, entryPath))) {
176
+ return entryPath;
177
+ }
178
+ }
179
+ return entryPaths[0];
180
+ }
181
+ const HostEntryFilePaths = [
182
+ "./src/index.ts",
183
+ "./src/index.tsx"
184
+ ];
185
+ // The function return type is mandatory, otherwise we got an error TS4058.
186
+ function defineHostModuleFederationPluginOptions(remotes, options) {
187
+ const { features = {}, shared = {}, runtimePlugins = [], ...rest } = options;
188
+ const defaultSharedDependencies = resolveDefaultSharedDependencies(features, true);
189
+ return {
190
+ name: __WEBPACK_EXTERNAL_MODULE__shared_js_cc7b7cda__.HostApplicationName,
191
+ // Since Squide modules are only exporting a register function with a standardized API
192
+ // it doesn't requires any typing.
193
+ dts: false,
194
+ // Currently only supporting .js remotes.
195
+ manifest: false,
196
+ remotes: remotes.reduce((acc, x)=>{
197
+ // Object reduce are always a mess for typings.
198
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
199
+ // @ts-ignore
200
+ acc[x.name] = `${x.name}@${x.url}/${RemoteEntryPoint}`;
201
+ return acc;
202
+ }, {}),
203
+ // Deep merging the default shared dependencies with the provided shared dependencies
204
+ // to allow the consumer to easily override a default option of a shared dependency
205
+ // without extending the whole default shared dependencies object.
206
+ shared: __WEBPACK_EXTERNAL_MODULE_deepmerge__["default"].all([
207
+ defaultSharedDependencies,
208
+ shared
209
+ ]),
210
+ runtimePlugins: [
211
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(packageDirectory, "./sharedDependenciesResolutionPlugin.js"),
212
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(packageDirectory, "./nonCacheableRemoteEntryPlugin.js"),
213
+ ...runtimePlugins
214
+ ],
215
+ // Commented because it doesn't seems to work, the runtime is still embedded into remotes.
216
+ // experiments: {
217
+ // // The runtime is 100kb minified.
218
+ // federationRuntime: "hoisted"
219
+ // },
220
+ ...rest
221
+ };
222
+ }
223
+ // Fixing HMR and page reloads when using `publicPath: auto` either in the host or remotes webpack configuration.
224
+ // Otherwise, when a nested page that belongs to a remote module is reloaded, an "Unexpected token" error will be thrown.
225
+ function trySetHtmlWebpackPluginPublicPath(options) {
226
+ if (!options.publicPath) {
227
+ options.publicPath = "/";
228
+ }
229
+ return options;
230
+ }
231
+ // The function return type is mandatory, otherwise we got an error TS4058.
232
+ function defineDevHostConfig(swcConfig, port, remotes, options = {}) {
233
+ const { entry = resolveEntryFilePath(HostEntryFilePaths), publicPath = "auto", cache, plugins = [], htmlWebpackPluginOptions, transformers = [], features, sharedDependencies, runtimePlugins, moduleFederationPluginOptions = defineHostModuleFederationPluginOptions(remotes, {
234
+ features,
235
+ shared: sharedDependencies,
236
+ runtimePlugins
237
+ }), ...webpackOptions } = options;
238
+ return (0,__WEBPACK_EXTERNAL_MODULE__workleap_webpack_configs_227c33a7__.defineDevConfig)(swcConfig, {
239
+ entry,
240
+ port,
241
+ publicPath,
242
+ cache,
243
+ htmlWebpackPlugin: trySetHtmlWebpackPluginPublicPath(htmlWebpackPluginOptions ?? (0,__WEBPACK_EXTERNAL_MODULE__workleap_webpack_configs_227c33a7__.defineBuildHtmlWebpackPluginConfig)()),
244
+ plugins: [
245
+ ...plugins,
246
+ new __WEBPACK_EXTERNAL_MODULE__module_federation_enhanced_webpack_5184ba07__.ModuleFederationPlugin(moduleFederationPluginOptions)
247
+ ],
248
+ ...webpackOptions,
249
+ transformers: [
250
+ createSetUniqueNameTransformer(__WEBPACK_EXTERNAL_MODULE__shared_js_cc7b7cda__.HostApplicationName),
251
+ ...transformers
252
+ ]
253
+ });
254
+ }
255
+ // The function return type is mandatory, otherwise we got an error TS4058.
256
+ function defineBuildHostConfig(swcConfig, remotes, options = {}) {
257
+ const { entry = resolveEntryFilePath(HostEntryFilePaths), publicPath = "auto", plugins = [], htmlWebpackPluginOptions, transformers = [], features, sharedDependencies, runtimePlugins, moduleFederationPluginOptions = defineHostModuleFederationPluginOptions(remotes, {
258
+ features,
259
+ shared: sharedDependencies,
260
+ runtimePlugins
261
+ }), ...webpackOptions } = options;
262
+ return (0,__WEBPACK_EXTERNAL_MODULE__workleap_webpack_configs_227c33a7__.defineBuildConfig)(swcConfig, {
263
+ entry,
264
+ publicPath,
265
+ htmlWebpackPlugin: trySetHtmlWebpackPluginPublicPath(htmlWebpackPluginOptions ?? (0,__WEBPACK_EXTERNAL_MODULE__workleap_webpack_configs_227c33a7__.defineDevHtmlWebpackPluginConfig)()),
266
+ plugins: [
267
+ ...plugins,
268
+ new __WEBPACK_EXTERNAL_MODULE__module_federation_enhanced_webpack_5184ba07__.ModuleFederationPlugin(moduleFederationPluginOptions)
269
+ ],
270
+ transformers: [
271
+ forceNamedChunkIdsTransformer,
272
+ createSetUniqueNameTransformer(__WEBPACK_EXTERNAL_MODULE__shared_js_cc7b7cda__.HostApplicationName),
273
+ ...transformers
274
+ ],
275
+ ...webpackOptions
276
+ });
277
+ }
278
+ //////////////////////////// Remote /////////////////////////////
279
+ const RemoteEntryFilePaths = [
280
+ "./src/register.tsx",
281
+ "./src/register.ts"
282
+ ];
283
+ // The function return type is mandatory, otherwise we got an error TS4058.
284
+ function defineRemoteModuleFederationPluginOptions(applicationName, options) {
285
+ const { features = {}, exposes = {}, shared = {}, runtimePlugins = [], ...rest } = options;
286
+ const defaultSharedDependencies = resolveDefaultSharedDependencies(features, false);
287
+ return {
288
+ name: applicationName,
289
+ // Since Squide modules are only exporting a register function with a standardized API
290
+ // it doesn't requires any typing.
291
+ dts: false,
292
+ // Currently only supporting .js remotes.
293
+ manifest: false,
294
+ filename: RemoteEntryPoint,
295
+ exposes: {
296
+ [RemoteRegisterModuleName]: "./src/register",
297
+ ...exposes
298
+ },
299
+ // Deep merging the default shared dependencies with the provided shared dependencies
300
+ // to allow the consumer to easily override a default option of a shared dependency
301
+ // without extending the whole default shared dependencies object.
302
+ shared: __WEBPACK_EXTERNAL_MODULE_deepmerge__["default"].all([
303
+ defaultSharedDependencies,
304
+ shared
305
+ ]),
306
+ runtimePlugins: [
307
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(packageDirectory, "./sharedDependenciesResolutionPlugin.js"),
308
+ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].resolve(packageDirectory, "./nonCacheableRemoteEntryPlugin.js"),
309
+ ...runtimePlugins
310
+ ],
311
+ // Commented because it doesn't seems to work, the runtime is still embedded into remotes.
312
+ // experiments: {
313
+ // // The runtime is 100kb minified.
314
+ // federationRuntime: "hoisted"
315
+ // },
316
+ ...rest
317
+ };
318
+ }
319
+ const devRemoteModuleTransformer = (config)=>{
320
+ // "config.devServer" does exist but webpack types are a messed. It could probably be solved by importing "webpack-dev-server"
321
+ // but I would prefer not adding it as a project dependency.
322
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
323
+ // @ts-ignore
324
+ config.devServer.headers = {
325
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
326
+ // @ts-ignore
327
+ ...config.devServer.headers ?? {},
328
+ // Otherwise hot reload in the host failed with a CORS error.
329
+ "Access-Control-Allow-Origin": "*"
330
+ };
331
+ return config;
332
+ };
333
+ // The function return type is mandatory, otherwise we got an error TS4058.
334
+ function defineDevRemoteModuleConfig(swcConfig, applicationName, port, options = {}) {
335
+ const { entry = resolveEntryFilePath(RemoteEntryFilePaths), publicPath = "auto", cache, plugins = [], htmlWebpackPlugin = false, transformers = [], features, sharedDependencies, runtimePlugins, moduleFederationPluginOptions = defineRemoteModuleFederationPluginOptions(applicationName, {
336
+ features,
337
+ shared: sharedDependencies,
338
+ runtimePlugins
339
+ }), ...webpackOptions } = options;
340
+ return (0,__WEBPACK_EXTERNAL_MODULE__workleap_webpack_configs_227c33a7__.defineDevConfig)(swcConfig, {
341
+ entry,
342
+ port,
343
+ publicPath,
344
+ cache,
345
+ htmlWebpackPlugin,
346
+ // Disable the error overlay by default for remotes as otherwise every remote module's error overlay will be
347
+ // stack on top of the host application's error overlay.
348
+ overlay: false,
349
+ plugins: [
350
+ ...plugins,
351
+ new __WEBPACK_EXTERNAL_MODULE__module_federation_enhanced_webpack_5184ba07__.ModuleFederationPlugin(moduleFederationPluginOptions)
352
+ ],
353
+ transformers: [
354
+ devRemoteModuleTransformer,
355
+ createSetUniqueNameTransformer(applicationName),
356
+ ...transformers
357
+ ],
358
+ ...webpackOptions
359
+ });
360
+ }
361
+ // The function return type is mandatory, otherwise we got an error TS4058.
362
+ function defineBuildRemoteModuleConfig(swcConfig, applicationName, options = {}) {
363
+ const { entry = resolveEntryFilePath(RemoteEntryFilePaths), publicPath = "auto", plugins = [], htmlWebpackPlugin = false, transformers = [], features, sharedDependencies, runtimePlugins, moduleFederationPluginOptions = defineRemoteModuleFederationPluginOptions(applicationName, {
364
+ features,
365
+ shared: sharedDependencies,
366
+ runtimePlugins
367
+ }), ...webpackOptions } = options;
368
+ return (0,__WEBPACK_EXTERNAL_MODULE__workleap_webpack_configs_227c33a7__.defineBuildConfig)(swcConfig, {
369
+ entry,
370
+ publicPath,
371
+ htmlWebpackPlugin,
372
+ plugins: [
373
+ ...plugins,
374
+ new __WEBPACK_EXTERNAL_MODULE__module_federation_enhanced_webpack_5184ba07__.ModuleFederationPlugin(moduleFederationPluginOptions)
375
+ ],
376
+ transformers: [
377
+ forceNamedChunkIdsTransformer,
378
+ createSetUniqueNameTransformer(applicationName),
379
+ ...transformers
380
+ ],
381
+ ...webpackOptions
382
+ });
383
+ }
384
+
385
+ export { defineBuildHostConfig, defineBuildRemoteModuleConfig, defineDevHostConfig, defineDevRemoteModuleConfig, defineHostModuleFederationPluginOptions, defineRemoteModuleFederationPluginOptions };
386
+
387
+ //# sourceMappingURL=defineConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defineConfig.js","sources":["webpack://@squide/firefly-webpack-configs/./src/defineConfig.ts"],"sourcesContent":["import { ModuleFederationPlugin } from \"@module-federation/enhanced/webpack\";\nimport type { SwcConfig } from \"@workleap/swc-configs\";\nimport { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineDevConfig, defineDevHtmlWebpackPluginConfig, type DefineBuildConfigOptions, type DefineDevConfigOptions, type WebpackConfig, type WebpackConfigTransformer } from \"@workleap/webpack-configs\";\nimport merge from \"deepmerge\";\nimport type HtmlWebpackPlugin from \"html-webpack-plugin\";\nimport fs from \"node:fs\";\nimport path, { dirname } from \"node:path\";\nimport url, { fileURLToPath } from \"node:url\";\nimport type webpack from \"webpack\";\nimport { HostApplicationName } from \"./shared.ts\";\n\n// Using import.meta.url instead of import.meta.dirname because Jest is throwing the following error:\n// SyntaxError: Cannot use 'import.meta' outside a module\nconst applicationDirectory = dirname(fileURLToPath(import.meta.url));\nconst packageDirectory = url.fileURLToPath(new URL(\".\", import.meta.url));\n\n// Must be similar to the module name defined in @workleap/module-federation.\nconst RemoteRegisterModuleName = \"./register\";\nconst RemoteEntryPoint = \"remoteEntry.js\";\n\n// Webpack doesn't export ModuleFederationPlugin typings.\nexport type ModuleFederationPluginOptions = ConstructorParameters<typeof ModuleFederationPlugin>[0];\nexport type ModuleFederationRemotesOption = ModuleFederationPluginOptions[\"remotes\"];\n\nexport type ModuleFederationRuntimePlugins = NonNullable<ModuleFederationPluginOptions[\"runtimePlugins\"]>;\nexport type ModuleFederationShared = NonNullable<ModuleFederationPluginOptions[\"shared\"]>;\n\n// Generally, only the host application should have eager dependencies.\n// For more informations about shared dependencies refer to: https://github.com/patricklafrance/wmf-versioning\nfunction getDefaultSharedDependencies(features: Features, isHost: boolean): ModuleFederationShared {\n return {\n \"react\": {\n singleton: true,\n eager: isHost ? true : undefined,\n // Fixed the warning when `react-i18next` is imported in any remote modules.\n // For more information, refer to: https://github.com/i18next/react-i18next/issues/1697#issuecomment-1821748226.\n requiredVersion: features.i18next ? false : undefined\n },\n \"react-dom\": {\n singleton: true,\n eager: isHost ? true : undefined\n },\n \"@squide/core\": {\n singleton: true,\n eager: isHost ? true : undefined\n },\n \"@squide/module-federation\": {\n singleton: true,\n eager: isHost ? true : undefined\n }\n };\n}\n\nexport type Router = \"react-router\";\n\nexport interface Features {\n router?: Router;\n msw?: boolean;\n i18next?: boolean;\n environmentVariables?: boolean;\n honeycomb?: boolean;\n}\n\n// Generally, only the host application should have eager dependencies.\n// For more informations about shared dependencies refer to: https://github.com/patricklafrance/wmf-versioning\nfunction getReactRouterSharedDependencies(isHost: boolean): ModuleFederationShared {\n return {\n \"react-router-dom\": {\n singleton: true,\n eager: isHost ? true : undefined\n },\n \"@squide/react-router\": {\n singleton: true,\n eager: isHost ? true : undefined\n }\n };\n}\n\nfunction getMswSharedDependency(isHost: boolean): ModuleFederationShared {\n return {\n \"@squide/msw\": {\n singleton: true,\n eager: isHost ? true : undefined\n }\n };\n}\n\nfunction getI18nextSharedDependency(isHost: boolean): ModuleFederationShared {\n return {\n \"i18next\": {\n singleton: true,\n eager: isHost ? true : undefined\n },\n // Not adding as a shared dependency for the moment because it causes the following error:\n // Uncaught (in promise) TypeError: i18next_browser_languagedetector__WEBPACK_IMPORTED_MODULE_3__ is not a constructor\n // \"i18next-browser-languagedetector\": {\n // singleton: true,\n // eager: isHost ? true : undefined\n // },\n \"react-i18next\": {\n singleton: true,\n eager: isHost ? true : undefined\n },\n \"@squide/i18next\": {\n singleton: true,\n eager: isHost ? true : undefined\n }\n };\n}\n\nfunction getEnvironmentVariablesSharedDependencies(isHost: boolean): ModuleFederationShared {\n return {\n \"@squide/env-vars\": {\n singleton: true,\n eager: isHost ? true : undefined\n }\n };\n}\n\nfunction getHoneycombSharedDependencies(isHost: boolean): ModuleFederationShared {\n return {\n \"@honeycombio/opentelemetry-web\": {\n singleton: true,\n eager: isHost ? true : undefined\n },\n \"@opentelemetry/api\": {\n singleton: true,\n eager: isHost ? true : undefined\n },\n \"@opentelemetry/auto-instrumentations-web\": {\n singleton: true,\n eager: isHost ? true : undefined\n },\n \"@squide/firefly-honeycomb\": {\n singleton: true,\n eager: isHost ? true : undefined\n }\n };\n}\n\nfunction getFeaturesDependencies(features: Features, isHost: boolean) {\n const {\n router = \"react-router\",\n msw = true,\n i18next,\n environmentVariables,\n honeycomb\n } = features;\n\n return {\n ...(router === \"react-router\" ? getReactRouterSharedDependencies(isHost) : {}),\n ...(msw ? getMswSharedDependency(isHost) : {}),\n ...(i18next ? getI18nextSharedDependency(isHost) : {}),\n ...(environmentVariables ? getEnvironmentVariablesSharedDependencies(isHost) : {}),\n ...(honeycomb ? getHoneycombSharedDependencies(isHost) : {})\n };\n}\n\nfunction resolveDefaultSharedDependencies(features: Features, isHost: boolean) {\n return {\n ...getDefaultSharedDependencies(features, isHost),\n ...getFeaturesDependencies(features, isHost)\n };\n}\n\nconst forceNamedChunkIdsTransformer: WebpackConfigTransformer = (config: WebpackConfig) => {\n config.optimization = {\n ...(config.optimization ?? {}),\n // Without named chunk ids, there are some Webpack features that do not work\n // when used with Module Federation. One of these feature is using a dynamic import in\n // a remote module.\n chunkIds: \"named\"\n };\n\n return config;\n};\n\nfunction createSetUniqueNameTransformer(uniqueName: string) {\n const transformer: WebpackConfigTransformer = (config: WebpackConfig) => {\n config.output = {\n ...(config.output ?? {}),\n // Every host and remotes must have a \"uniqueName\" for React Refresh to work\n // with Module Federation.\n uniqueName\n };\n\n return config;\n };\n\n return transformer;\n}\n\nfunction resolveEntryFilePath(entryPaths: string[]) {\n for (const entryPath in entryPaths) {\n if (fs.existsSync(path.resolve(applicationDirectory, entryPath))) {\n return entryPath;\n }\n }\n\n return entryPaths[0];\n}\n\n//////////////////////////// Host /////////////////////////////\n\nexport interface RemoteDefinition {\n // The name of the remote module.\n name: string;\n // The URL of the remote, ex: http://localhost:8081.\n url: string;\n}\n\nconst HostEntryFilePaths = [\n \"./src/index.ts\",\n \"./src/index.tsx\"\n];\n\nexport interface DefineHostModuleFederationPluginOptions extends ModuleFederationPluginOptions {\n features?: Features;\n}\n\n// The function return type is mandatory, otherwise we got an error TS4058.\nexport function defineHostModuleFederationPluginOptions(remotes: RemoteDefinition[], options: DefineHostModuleFederationPluginOptions): ModuleFederationPluginOptions {\n const {\n features = {},\n shared = {},\n runtimePlugins = [],\n ...rest\n } = options;\n\n const defaultSharedDependencies = resolveDefaultSharedDependencies(features, true);\n\n return {\n name: HostApplicationName,\n // Since Squide modules are only exporting a register function with a standardized API\n // it doesn't requires any typing.\n dts: false,\n // Currently only supporting .js remotes.\n manifest: false,\n remotes: remotes.reduce((acc, x) => {\n // Object reduce are always a mess for typings.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n acc[x.name] = `${x.name}@${x.url}/${RemoteEntryPoint}`;\n\n return acc;\n }, {}) as ModuleFederationRemotesOption,\n // Deep merging the default shared dependencies with the provided shared dependencies\n // to allow the consumer to easily override a default option of a shared dependency\n // without extending the whole default shared dependencies object.\n shared: merge.all([\n defaultSharedDependencies,\n shared\n ]) as ModuleFederationShared,\n runtimePlugins: [\n path.resolve(packageDirectory, \"./sharedDependenciesResolutionPlugin.js\"),\n path.resolve(packageDirectory, \"./nonCacheableRemoteEntryPlugin.js\"),\n ...runtimePlugins\n ],\n // Commented because it doesn't seems to work, the runtime is still embedded into remotes.\n // experiments: {\n // // The runtime is 100kb minified.\n // federationRuntime: \"hoisted\"\n // },\n ...rest\n };\n}\n\n// Fixing HMR and page reloads when using `publicPath: auto` either in the host or remotes webpack configuration.\n// Otherwise, when a nested page that belongs to a remote module is reloaded, an \"Unexpected token\" error will be thrown.\nfunction trySetHtmlWebpackPluginPublicPath(options: HtmlWebpackPlugin.Options) {\n if (!options.publicPath) {\n options.publicPath = \"/\";\n }\n\n return options;\n}\n\nexport interface DefineDevHostConfigOptions extends Omit<DefineDevConfigOptions, \"htmlWebpackPlugin\" | \"port\"> {\n htmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;\n features?: Features;\n sharedDependencies?: ModuleFederationShared;\n runtimePlugins?: ModuleFederationRuntimePlugins;\n moduleFederationPluginOptions?: ModuleFederationPluginOptions;\n}\n\n// The function return type is mandatory, otherwise we got an error TS4058.\nexport function defineDevHostConfig(swcConfig: SwcConfig, port: number, remotes: RemoteDefinition[], options: DefineDevHostConfigOptions = {}): webpack.Configuration {\n const {\n entry = resolveEntryFilePath(HostEntryFilePaths),\n publicPath = \"auto\",\n cache,\n plugins = [],\n htmlWebpackPluginOptions,\n transformers = [],\n features,\n sharedDependencies,\n runtimePlugins,\n moduleFederationPluginOptions = defineHostModuleFederationPluginOptions(remotes, { features, shared: sharedDependencies, runtimePlugins }),\n ...webpackOptions\n } = options;\n\n return defineDevConfig(swcConfig, {\n entry,\n port,\n publicPath,\n cache,\n htmlWebpackPlugin: trySetHtmlWebpackPluginPublicPath(htmlWebpackPluginOptions ?? defineBuildHtmlWebpackPluginConfig()),\n plugins: [\n ...plugins,\n new ModuleFederationPlugin(moduleFederationPluginOptions)\n ],\n ...webpackOptions,\n transformers: [\n createSetUniqueNameTransformer(HostApplicationName),\n ...transformers\n ]\n });\n}\n\nexport interface DefineBuildHostConfigOptions extends Omit<DefineBuildConfigOptions, \"htmlWebpackPlugin\"> {\n htmlWebpackPluginOptions?: HtmlWebpackPlugin.Options;\n features?: Features;\n sharedDependencies?: ModuleFederationShared;\n runtimePlugins?: ModuleFederationRuntimePlugins;\n moduleFederationPluginOptions?: ModuleFederationPluginOptions;\n}\n\n// The function return type is mandatory, otherwise we got an error TS4058.\nexport function defineBuildHostConfig(swcConfig: SwcConfig, remotes: RemoteDefinition[], options: DefineBuildHostConfigOptions = {}): webpack.Configuration {\n const {\n entry = resolveEntryFilePath(HostEntryFilePaths),\n publicPath = \"auto\",\n plugins = [],\n htmlWebpackPluginOptions,\n transformers = [],\n features,\n sharedDependencies,\n runtimePlugins,\n moduleFederationPluginOptions = defineHostModuleFederationPluginOptions(remotes, { features, shared: sharedDependencies, runtimePlugins }),\n ...webpackOptions\n } = options;\n\n return defineBuildConfig(swcConfig, {\n entry,\n publicPath,\n htmlWebpackPlugin: trySetHtmlWebpackPluginPublicPath(htmlWebpackPluginOptions ?? defineDevHtmlWebpackPluginConfig()),\n plugins: [\n ...plugins,\n new ModuleFederationPlugin(moduleFederationPluginOptions)\n ],\n transformers: [\n forceNamedChunkIdsTransformer,\n createSetUniqueNameTransformer(HostApplicationName),\n ...transformers\n ],\n ...webpackOptions\n });\n}\n\n//////////////////////////// Remote /////////////////////////////\n\nconst RemoteEntryFilePaths = [\n \"./src/register.tsx\",\n \"./src/register.ts\"\n];\n\nexport interface DefineRemoteModuleFederationPluginOptions extends ModuleFederationPluginOptions {\n features?: Features;\n}\n\n// The function return type is mandatory, otherwise we got an error TS4058.\nexport function defineRemoteModuleFederationPluginOptions(applicationName: string, options: DefineRemoteModuleFederationPluginOptions): ModuleFederationPluginOptions {\n const {\n features = {},\n exposes = {},\n shared = {},\n runtimePlugins = [],\n ...rest\n } = options;\n\n const defaultSharedDependencies = resolveDefaultSharedDependencies(features, false);\n\n return {\n name: applicationName,\n // Since Squide modules are only exporting a register function with a standardized API\n // it doesn't requires any typing.\n dts: false,\n // Currently only supporting .js remotes.\n manifest: false,\n filename: RemoteEntryPoint,\n exposes: {\n [RemoteRegisterModuleName]: \"./src/register\",\n ...exposes\n },\n // Deep merging the default shared dependencies with the provided shared dependencies\n // to allow the consumer to easily override a default option of a shared dependency\n // without extending the whole default shared dependencies object.\n shared: merge.all([\n defaultSharedDependencies,\n shared\n ]) as ModuleFederationShared,\n runtimePlugins: [\n path.resolve(packageDirectory, \"./sharedDependenciesResolutionPlugin.js\"),\n path.resolve(packageDirectory, \"./nonCacheableRemoteEntryPlugin.js\"),\n ...runtimePlugins\n ],\n // Commented because it doesn't seems to work, the runtime is still embedded into remotes.\n // experiments: {\n // // The runtime is 100kb minified.\n // federationRuntime: \"hoisted\"\n // },\n ...rest\n };\n}\n\nconst devRemoteModuleTransformer: WebpackConfigTransformer = (config: WebpackConfig) => {\n // \"config.devServer\" does exist but webpack types are a messed. It could probably be solved by importing \"webpack-dev-server\"\n // but I would prefer not adding it as a project dependency.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n config.devServer.headers = {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n ...(config.devServer.headers ?? {}),\n // Otherwise hot reload in the host failed with a CORS error.\n \"Access-Control-Allow-Origin\": \"*\"\n };\n\n return config;\n};\n\nexport interface DefineDevRemoteModuleConfigOptions extends Omit<DefineDevConfigOptions, \"port\" | \"overlay\"> {\n features?: Features;\n sharedDependencies?: ModuleFederationShared;\n runtimePlugins?: ModuleFederationRuntimePlugins;\n moduleFederationPluginOptions?: ModuleFederationPluginOptions;\n}\n\n// The function return type is mandatory, otherwise we got an error TS4058.\nexport function defineDevRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, port: number, options: DefineDevRemoteModuleConfigOptions = {}): webpack.Configuration {\n const {\n entry = resolveEntryFilePath(RemoteEntryFilePaths),\n publicPath = \"auto\",\n cache,\n plugins = [],\n htmlWebpackPlugin = false,\n transformers = [],\n features,\n sharedDependencies,\n runtimePlugins,\n moduleFederationPluginOptions = defineRemoteModuleFederationPluginOptions(applicationName, { features, shared: sharedDependencies, runtimePlugins }),\n ...webpackOptions\n } = options;\n\n return defineDevConfig(swcConfig, {\n entry,\n port,\n publicPath,\n cache,\n htmlWebpackPlugin,\n // Disable the error overlay by default for remotes as otherwise every remote module's error overlay will be\n // stack on top of the host application's error overlay.\n overlay: false,\n plugins: [\n ...plugins,\n new ModuleFederationPlugin(moduleFederationPluginOptions)\n ],\n transformers: [\n devRemoteModuleTransformer,\n createSetUniqueNameTransformer(applicationName),\n ...transformers\n ],\n ...webpackOptions\n });\n}\n\nexport interface DefineBuildRemoteModuleConfigOptions extends DefineBuildConfigOptions {\n features?: Features;\n sharedDependencies?: ModuleFederationShared;\n runtimePlugins?: ModuleFederationRuntimePlugins;\n moduleFederationPluginOptions?: ModuleFederationPluginOptions;\n}\n\n// The function return type is mandatory, otherwise we got an error TS4058.\nexport function defineBuildRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, options: DefineBuildRemoteModuleConfigOptions = {}): webpack.Configuration {\n const {\n entry = resolveEntryFilePath(RemoteEntryFilePaths),\n publicPath = \"auto\",\n plugins = [],\n htmlWebpackPlugin = false,\n transformers = [],\n features,\n sharedDependencies,\n runtimePlugins,\n moduleFederationPluginOptions = defineRemoteModuleFederationPluginOptions(applicationName, { features, shared: sharedDependencies, runtimePlugins }),\n ...webpackOptions\n } = options;\n\n return defineBuildConfig(swcConfig, {\n entry,\n publicPath,\n htmlWebpackPlugin,\n plugins: [\n ...plugins,\n new ModuleFederationPlugin(moduleFederationPluginOptions)\n ],\n transformers: [\n forceNamedChunkIdsTransformer,\n createSetUniqueNameTransformer(applicationName),\n ...transformers\n ],\n ...webpackOptions\n });\n}\n"],"names":["ModuleFederationPlugin","defineBuildConfig","defineBuildHtmlWebpackPluginConfig","defineDevConfig","defineDevHtmlWebpackPluginConfig","merge","fs","path","dirname","url","fileURLToPath","HostApplicationName","applicationDirectory","packageDirectory","URL","RemoteRegisterModuleName","RemoteEntryPoint","getDefaultSharedDependencies","features","isHost","undefined","getReactRouterSharedDependencies","getMswSharedDependency","getI18nextSharedDependency","getEnvironmentVariablesSharedDependencies","getHoneycombSharedDependencies","getFeaturesDependencies","router","msw","i18next","environmentVariables","honeycomb","resolveDefaultSharedDependencies","forceNamedChunkIdsTransformer","config","createSetUniqueNameTransformer","uniqueName","transformer","resolveEntryFilePath","entryPaths","entryPath","HostEntryFilePaths","defineHostModuleFederationPluginOptions","remotes","options","shared","runtimePlugins","rest","defaultSharedDependencies","acc","x","trySetHtmlWebpackPluginPublicPath","defineDevHostConfig","swcConfig","port","entry","publicPath","cache","plugins","htmlWebpackPluginOptions","transformers","sharedDependencies","moduleFederationPluginOptions","webpackOptions","defineBuildHostConfig","RemoteEntryFilePaths","defineRemoteModuleFederationPluginOptions","applicationName","exposes","devRemoteModuleTransformer","defineDevRemoteModuleConfig","htmlWebpackPlugin","defineBuildRemoteModuleConfig"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAA6E;AAEuL;AACtO;AAEL;AACiB;AACI;AAEI;AAElD,qGAAqG;AACrG,yDAAyD;AACzD,MAAMY,uBAAuBJ,0DAAOA,CAACE,+DAAaA,CAAC,YAAY,GAAG;AAClE,MAAMG,mBAAmBJ,sEAAiB,CAAC,IAAIK,IAAI,KAAK,YAAY,GAAG;AAEvE,6EAA6E;AAC7E,MAAMC,2BAA2B;AACjC,MAAMC,mBAAmB;AASzB,uEAAuE;AACvE,8GAA8G;AAC9G,SAASC,6BAA6BC,QAAkB,EAAEC,MAAe;IACrE,OAAO;QACH,SAAS;YACL,WAAW;YACX,OAAOA,SAAS,OAAOC;YACvB,4EAA4E;YAC5E,gHAAgH;YAChH,iBAAiBF,SAAS,OAAO,GAAG,QAAQE;QAChD;QACA,aAAa;YACT,WAAW;YACX,OAAOD,SAAS,OAAOC;QAC3B;QACA,gBAAgB;YACZ,WAAW;YACX,OAAOD,SAAS,OAAOC;QAC3B;QACA,6BAA6B;YACzB,WAAW;YACX,OAAOD,SAAS,OAAOC;QAC3B;IACJ;AACJ;AAYA,uEAAuE;AACvE,8GAA8G;AAC9G,SAASC,iCAAiCF,MAAe;IACrD,OAAO;QACH,oBAAoB;YAChB,WAAW;YACX,OAAOA,SAAS,OAAOC;QAC3B;QACA,wBAAwB;YACpB,WAAW;YACX,OAAO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EAAE,EACpJ,GAAGiB,gBACN,GAAGnB;IAEJ,OAAO3C,oFAAiBA,CAACoD,WAAW;QAChCE;QACAC;QACAe;QACA,SAAS;eACFb;YACH,IAAI1D,+FAAsBA,CAAC8D;SAC9B;QACD,cAAc;YACV7B;YACAE,+BAA+BgC;eAC5BP;SACN;QACD,GAAGG,cAAc;IACrB;AACJ"}
package/dist/index.d.ts CHANGED
@@ -1,25 +1,2 @@
1
- import { Features, DefineDevHostConfigOptions, RemoteDefinition, DefineBuildHostConfigOptions, DefineDevRemoteModuleConfigOptions, DefineBuildRemoteModuleConfigOptions } from '@squide/webpack-configs';
2
- export { DefineHostModuleFederationPluginOptions, DefineRemoteModuleFederationPluginOptions, ModuleFederationPluginOptions, RemoteDefinition, Router, defineRemoteModuleFederationPluginOptions } from '@squide/webpack-configs';
3
- import { SwcConfig } from '@workleap/swc-configs';
4
- import webpack from 'webpack';
5
- export * from '@workleap/webpack-configs';
6
-
7
- type FireflyFeatures = Omit<Features, "router" | "msw">;
8
- interface FireflyDefineDevHostConfigOptions extends DefineDevHostConfigOptions {
9
- features?: FireflyFeatures;
10
- }
11
- declare function defineDevHostConfig(swcConfig: SwcConfig, port: number, remotes: RemoteDefinition[], { features, ...options }?: FireflyDefineDevHostConfigOptions): webpack.Configuration;
12
- interface FireflyDefineBuildHostConfigOptions extends DefineBuildHostConfigOptions {
13
- features?: FireflyFeatures;
14
- }
15
- declare function defineBuildHostConfig(swcConfig: SwcConfig, remotes: RemoteDefinition[], { features, ...options }?: FireflyDefineBuildHostConfigOptions): webpack.Configuration;
16
- interface FireflyDefineDevRemoteModuleConfigOptions extends DefineDevRemoteModuleConfigOptions {
17
- features?: FireflyFeatures;
18
- }
19
- declare function defineDevRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, port: number, { features, ...options }?: FireflyDefineDevRemoteModuleConfigOptions): webpack.Configuration;
20
- interface FireflyDefineBuildRemoteModuleConfigOptions extends DefineBuildRemoteModuleConfigOptions {
21
- features?: FireflyFeatures;
22
- }
23
- declare function defineBuildRemoteModuleConfig(swcConfig: SwcConfig, applicationName: string, { features, ...options }?: FireflyDefineBuildRemoteModuleConfigOptions): webpack.Configuration;
24
-
25
- export { type FireflyDefineBuildHostConfigOptions, type FireflyDefineBuildRemoteModuleConfigOptions, type FireflyDefineDevHostConfigOptions, type FireflyDefineDevRemoteModuleConfigOptions, type FireflyFeatures, defineBuildHostConfig, defineBuildRemoteModuleConfig, defineDevHostConfig, defineDevRemoteModuleConfig };
1
+ export * from "@workleap/webpack-configs";
2
+ export * from "./defineConfig.ts";
package/dist/index.js CHANGED
@@ -1,47 +1,9 @@
1
- import { defineDevHostConfig as defineDevHostConfig$1, defineBuildHostConfig as defineBuildHostConfig$1, defineDevRemoteModuleConfig as defineDevRemoteModuleConfig$1, defineBuildRemoteModuleConfig as defineBuildRemoteModuleConfig$1 } from '@squide/webpack-configs';
2
- export { defineRemoteModuleFederationPluginOptions } from '@squide/webpack-configs';
3
- export * from '@workleap/webpack-configs';
1
+ export * from "@workleap/webpack-configs";
2
+ export * from "./defineConfig.js";
4
3
 
5
- // src/index.ts
6
- function defineDevHostConfig(swcConfig, port, remotes, { features = {}, ...options } = {}) {
7
- return defineDevHostConfig$1(swcConfig, port, remotes, {
8
- ...options,
9
- features: {
10
- router: "react-router",
11
- msw: true,
12
- ...features
13
- }
14
- });
15
- }
16
- function defineBuildHostConfig(swcConfig, remotes, { features = {}, ...options } = {}) {
17
- return defineBuildHostConfig$1(swcConfig, remotes, {
18
- ...options,
19
- features: {
20
- router: "react-router",
21
- msw: true,
22
- ...features
23
- }
24
- });
25
- }
26
- function defineDevRemoteModuleConfig(swcConfig, applicationName, port, { features = {}, ...options } = {}) {
27
- return defineDevRemoteModuleConfig$1(swcConfig, applicationName, port, {
28
- ...options,
29
- features: {
30
- router: "react-router",
31
- msw: true,
32
- ...features
33
- }
34
- });
35
- }
36
- function defineBuildRemoteModuleConfig(swcConfig, applicationName, { features = {}, ...options } = {}) {
37
- return defineBuildRemoteModuleConfig$1(swcConfig, applicationName, {
38
- ...options,
39
- features: {
40
- router: "react-router",
41
- msw: true,
42
- ...features
43
- }
44
- });
45
- }
4
+ ;// CONCATENATED MODULE: ./src/index.ts?__rslib_entry__
46
5
 
47
- export { defineBuildHostConfig, defineBuildRemoteModuleConfig, defineDevHostConfig, defineDevRemoteModuleConfig };
6
+
7
+
8
+
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["webpack://@squide/firefly-webpack-configs/./src/index.ts"],"sourcesContent":["export * from \"@workleap/webpack-configs\";\nexport * from \"./defineConfig.ts\";\n\n"],"names":[],"mappings":";;;;AAA0C;AACR"}
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from "@module-federation/enhanced/runtime";
2
+ declare const plugin: () => FederationRuntimePlugin;
3
+ export default plugin;
@@ -0,0 +1,21 @@
1
+
2
+ ;// CONCATENATED MODULE: ./src/nonCacheableRemoteEntryPlugin.ts?__rslib_entry__
3
+ const nonCacheableRemoteEntryPlugin_rslib_entry_plugin = ()=>{
4
+ return {
5
+ name: "non-cacheable-remote-entry-plugin",
6
+ createScript: function({ url }) {
7
+ const element = document.createElement("script");
8
+ // Adding a timestamp to make sure the remote entry points are never cached.
9
+ // View: https://github.com/module-federation/module-federation-examples/issues/566.
10
+ element.src = `${url}?t=${Date.now()}`;
11
+ element.type = "text/javascript";
12
+ element.async = true;
13
+ return element;
14
+ }
15
+ };
16
+ };
17
+ /* ESM default export */ const nonCacheableRemoteEntryPlugin_rslib_entry_ = (nonCacheableRemoteEntryPlugin_rslib_entry_plugin);
18
+
19
+ export { nonCacheableRemoteEntryPlugin_rslib_entry_ as default };
20
+
21
+ //# sourceMappingURL=nonCacheableRemoteEntryPlugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nonCacheableRemoteEntryPlugin.js","sources":["webpack://@squide/firefly-webpack-configs/./src/nonCacheableRemoteEntryPlugin.ts"],"sourcesContent":["import type { FederationRuntimePlugin } from \"@module-federation/enhanced/runtime\";\n\nconst plugin: () => FederationRuntimePlugin = () => {\n return {\n name: \"non-cacheable-remote-entry-plugin\",\n createScript: function({ url }) {\n const element = document.createElement(\"script\");\n\n // Adding a timestamp to make sure the remote entry points are never cached.\n // View: https://github.com/module-federation/module-federation-examples/issues/566.\n element.src = `${url}?t=${Date.now()}`;\n element.type = \"text/javascript\";\n element.async = true;\n\n return element;\n }\n };\n};\n\nexport default plugin;\n"],"names":["plugin","url","element","document","Date"],"mappings":";;AAEA,MAAMA,gDAAMA,GAAkC;IAC1C,OAAO;QACH,MAAM;QACN,cAAc,SAAS,EAAEC,GAAG,EAAE;YAC1B,MAAMC,UAAUC,SAAS,aAAa,CAAC;YAEvC,4EAA4E;YAC5E,oFAAoF;YACpFD,QAAQ,GAAG,GAAG,GAAGD,IAAI,GAAG,EAAEG,KAAK,GAAG,IAAI;YACtCF,QAAQ,IAAI,GAAG;YACfA,QAAQ,KAAK,GAAG;YAEhB,OAAOA;QACX;IACJ;AACJ;AAEA,6EAAeF,gDAAMA,EAAC"}
@@ -0,0 +1 @@
1
+ export declare const HostApplicationName = "host";