Skip to content

Commit e72f41a

Browse files
committed
fix(Build): Register jQuery globally.
Since the module federation support jQuery was registered globally too late for some scripts. Now jQuery is registered as soon as the index.js is loaded. This allows for following scripts to use jQuery.
1 parent 8f49053 commit e72f41a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,11 @@ import "../webpack/module_federation";
33
// The next import needs to be kept with parentheses, otherwise we get this error:
44
// "Shared module is not available for eager consumption."
55
import("./patterns");
6+
7+
// Register jQuery gloablly as soon as this script is executed.
8+
async function register_global_libraries() {
9+
const jquery = (await import("jquery")).default;
10+
window.jQuery = jquery;
11+
window.$ = jquery;
12+
}
13+
register_global_libraries();

webpack/webpack.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ module.exports = () => {
3535
name: "patternslib",
3636
remote_entry: config.entry["bundle.min"],
3737
dependencies: package_json.dependencies,
38+
shared: {
39+
jquery: {
40+
singleton: true,
41+
requiredVersion: package_json.dependencies["jquery"],
42+
eager: true,
43+
},
44+
},
3845
})
3946
);
4047

0 commit comments

Comments
 (0)