@patternslib/dev 2.7.2 → 3.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/CHANGES.md +61 -0
- package/Makefile +93 -35
- package/jest/setup-tests.js +0 -20
- package/package.json +20 -24
- package/webpack/module_federation--dynamic-federation.js +40 -0
- package/webpack/module_federation--getOrLoadRemote.js +71 -0
- package/webpack/module_federation.js +57 -0
- package/webpack/webpack.config.js +0 -8
package/CHANGES.md
CHANGED
|
@@ -2,6 +2,67 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
## [3.1.0](https://github.com/patternslib/dev/compare/3.0.0...3.1.0) (2022-11-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
* Allow to add the compiled bundles to npm packages. ([84bdefd](https://github.com/patternslib/dev/commit/84bdefd339b9aa553ef78e9448e4cdd998178d40))Creating a npm release with the Makefile prepares now a bundle build
|
|
12
|
+
with the correct package version added as a comment to the bundle files.
|
|
13
|
+
The compiled bundle can then be uploaded to npm if it is part of the git
|
|
14
|
+
repository (included by .gitignore) or part of the npm release
|
|
15
|
+
(preferred, included by .npmignore).
|
|
16
|
+
|
|
17
|
+
Adding the compiled bundle to npm allows to directly include it via a
|
|
18
|
+
CDN like so:
|
|
19
|
+
|
|
20
|
+
https://cdn.jsdelivr.net/npm/@patternslib/patternslib@9.7.0-alpha.2/dist/bundle.min.js
|
|
21
|
+
or
|
|
22
|
+
https://unpkg.com/@patternslib/patternslib@9.7.0-alpha.2/dist/bundle.min.js
|
|
23
|
+
|
|
24
|
+
We have to compile the bundle with the correct version BEFORE the npm
|
|
25
|
+
package is created with release-it. The next version is queried using
|
|
26
|
+
the LEVEL parameter (set by the different release targets) and the
|
|
27
|
+
"semver" tool.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Maintenance
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
* Upgrade dependencies. ([e687405](https://github.com/patternslib/dev/commit/e6874052cf9ae2cd359996659c091de532b6f5cb))
|
|
34
|
+
|
|
35
|
+
## [3.0.0](https://github.com/patternslib/dev/compare/2.7.2...3.0.0) (2022-10-15)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Features
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
* **Build:** Add Module Federation configuration for webpack. ([b84c2fb](https://github.com/patternslib/dev/commit/b84c2fb8053837206c044e3148522d9a54afa300))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### Breaking Changes
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
* **Build:** Remove the showdown-prettify loading config and the now unused imports-loader. ([27ba90f](https://github.com/patternslib/dev/commit/27ba90fc9e615c57b4be0ae20b84c2f16a918759))
|
|
48
|
+
|
|
49
|
+
* **Tests:** Remove dependency on jQuery. ([259d801](https://github.com/patternslib/dev/commit/259d801ab0a203ea64073e3cc0366976a38f1e0c))Use the following in your test setup to provide jQuery to external
|
|
50
|
+
libraries if they depend on a global jQuery object or extend from the
|
|
51
|
+
jest config from @patternslib/patternslib:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
import jquery from "jquery";
|
|
55
|
+
global.$ = global.jQuery = jquery;
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
* **Tests:** Remove the Dependency on @patternslib/patternslib. ([afe8fee](https://github.com/patternslib/dev/commit/afe8feec6304d2ce184afd587d429f3ae5bd533c))If you need Patternslib specific test setup, extend from Patternslib.
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### Maintenance
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
* Upgrade dependencies. ([f868454](https://github.com/patternslib/dev/commit/f868454982447190e968ab9eab4988bfee01c43a))
|
|
65
|
+
|
|
5
66
|
## [2.7.2](https://github.com/patternslib/dev/compare/2.7.1...2.7.2) (2022-09-28)
|
|
6
67
|
|
|
7
68
|
|
package/Makefile
CHANGED
|
@@ -1,11 +1,22 @@
|
|
|
1
|
+
# This Makefile is meant to be exported by Patternslib or Mockup packages.
|
|
2
|
+
|
|
3
|
+
# .evn include, mainly for a GITHUB_TOKEN.
|
|
1
4
|
-include .env
|
|
2
5
|
export
|
|
3
6
|
|
|
7
|
+
|
|
8
|
+
# If you want to release on GitHub, make sure to have a .env file with a GITHUB_TOKEN.
|
|
9
|
+
# Also see:
|
|
10
|
+
# https://github.com/settings/tokens
|
|
11
|
+
# and https://github.com/release-it/release-it/blob/master/docs/github-releases.md#automated
|
|
12
|
+
|
|
13
|
+
|
|
4
14
|
ESLINT ?= npx eslint
|
|
5
15
|
YARN ?= npx yarn
|
|
6
16
|
|
|
7
17
|
PACKAGE_DEV=@patternslib/dev
|
|
8
18
|
PACKAGE_NAME := $(shell node -p "require('./package.json').name")
|
|
19
|
+
BUNDLE_NAME := $(subst @patternslib/,,$(subst @plone/,,$(PACKAGE_NAME)))
|
|
9
20
|
|
|
10
21
|
.PHONY: install
|
|
11
22
|
stamp-yarn install:
|
|
@@ -43,6 +54,7 @@ bundle-pre:
|
|
|
43
54
|
@# yarn install --force
|
|
44
55
|
|
|
45
56
|
|
|
57
|
+
# Compile the bundle.
|
|
46
58
|
.PHONY: bundle
|
|
47
59
|
bundle: bundle-pre stamp-yarn
|
|
48
60
|
ifneq "$(PACKAGE_NAME)" "$(PACKAGE_DEV)"
|
|
@@ -51,58 +63,104 @@ ifneq "$(PACKAGE_NAME)" "$(PACKAGE_DEV)"
|
|
|
51
63
|
endif
|
|
52
64
|
|
|
53
65
|
|
|
54
|
-
#
|
|
55
|
-
# Also see:
|
|
56
|
-
# https://github.com/settings/tokens
|
|
57
|
-
# and https://github.com/release-it/release-it/blob/master/docs/github-releases.md#automated
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
# Create a ZIP file from the bundle which is uploaded to the GitHub release tag.
|
|
60
67
|
release-zip: clean-dist bundle
|
|
61
68
|
ifneq "$(PACKAGE_NAME)" "$(PACKAGE_DEV)"
|
|
62
69
|
@# Do not create a zip release for @patternslib/dev
|
|
63
|
-
$(eval BUNDLE_NAME := $(subst @patternslib/,,$(subst @plone/,,$(PACKAGE_NAME))))
|
|
64
70
|
$(eval PACKAGE_VERSION := $(shell node -p "require('./package.json').version"))
|
|
65
71
|
@echo Creating $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
|
|
66
|
-
mkdir -p
|
|
67
|
-
-
|
|
68
|
-
|
|
72
|
+
mkdir -p $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
73
|
+
-cp -R dist/* $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
74
|
+
zip -r $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)/
|
|
75
|
+
rm -Rf $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION)
|
|
69
76
|
endif
|
|
70
77
|
|
|
71
78
|
|
|
79
|
+
# Update the package.json version with NEXT_VERSION
|
|
80
|
+
define write_package_json
|
|
81
|
+
const fs = require("fs"); \
|
|
82
|
+
const package_json = require("./package.json"); \
|
|
83
|
+
package_json.version = "$(NEXT_VERSION)"; \
|
|
84
|
+
const data = JSON.stringify(package_json, null, 4); \
|
|
85
|
+
fs.writeFileSync("package.json", data);
|
|
86
|
+
endef
|
|
87
|
+
|
|
88
|
+
prepare-release:
|
|
89
|
+
@# Get the current package version.
|
|
90
|
+
$(eval CURRENT_VERSION := $(shell node -p "require('./package.json').version"))
|
|
91
|
+
ifeq ($(LEVEL),$(filter $(LEVEL), alpha beta))
|
|
92
|
+
@# case alpha or beta pre-release
|
|
93
|
+
|
|
94
|
+
@# Set level argument for release-it.
|
|
95
|
+
$(eval RELEASE_IT_LEVEL := "--preRelease=$(LEVEL)")
|
|
96
|
+
@# Get the next version via semver.
|
|
97
|
+
$(eval NEXT_VERSION := $(shell npx semver --increment premajor --preid $(LEVEL) $(CURRENT_VERSION)))
|
|
98
|
+
else
|
|
99
|
+
@# case normal major/minor/patch release
|
|
100
|
+
|
|
101
|
+
@# Set level argument for release-it.
|
|
102
|
+
$(eval RELEASE_IT_LEVEL := $(LEVEL))
|
|
103
|
+
@# Get the next version via semver.
|
|
104
|
+
$(eval NEXT_VERSION := $(shell npx semver --increment $(LEVEL) $(CURRENT_VERSION)))
|
|
105
|
+
endif
|
|
106
|
+
@echo Next version is: $(NEXT_VERSION)
|
|
107
|
+
|
|
108
|
+
@# Temporarily write the NEXT_VERSION to package.json, so that the bundle
|
|
109
|
+
@# and release-zip generate correct version strings.
|
|
110
|
+
node -p '$(write_package_json)'
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
release: clean install check prepare-release release-zip
|
|
114
|
+
@# RELEASE_IT_LEVEL and NEXT_VERSION set by prepare-release
|
|
115
|
+
|
|
116
|
+
@# Note: If you want to include the compiled bundle in your npm package you
|
|
117
|
+
@# have to allow it in a .npmignore file.
|
|
118
|
+
|
|
119
|
+
@# Checkout package.json which was modified by prepare-release and read by
|
|
120
|
+
@# release-zip.
|
|
121
|
+
git checkout .
|
|
122
|
+
|
|
123
|
+
@# 1) Release on npm.
|
|
124
|
+
@# 2) When successful, update release on GitHub
|
|
125
|
+
@# 3) Checkout CHANGES.md, which was modified by step 2)
|
|
126
|
+
npx release-it $(RELEASE_IT_LEVEL) \
|
|
127
|
+
&& npx release-it \
|
|
128
|
+
--github.release \
|
|
129
|
+
--github.update \
|
|
130
|
+
--github.assets=$(BUNDLE_NAME)-bundle-$(NEXT_VERSION).zip \
|
|
131
|
+
--no-github.draft \
|
|
132
|
+
--no-increment \
|
|
133
|
+
--no-git \
|
|
134
|
+
--no-npm
|
|
135
|
+
&& git checkout CHANGES.md
|
|
136
|
+
|
|
137
|
+
@# Remove the bundle from release-zip again.
|
|
138
|
+
rm $(BUNDLE_NAME)-bundle-$(PACKAGE_VERSION).zip
|
|
139
|
+
|
|
140
|
+
|
|
72
141
|
.PHONY: release-major
|
|
73
|
-
release-major:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
|
|
77
|
-
git checkout CHANGES.md
|
|
142
|
+
release-major:
|
|
143
|
+
make LEVEL=major release
|
|
144
|
+
|
|
78
145
|
|
|
79
146
|
.PHONY: release-minor
|
|
80
|
-
release-minor:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
|
|
84
|
-
git checkout CHANGES.md
|
|
147
|
+
release-minor:
|
|
148
|
+
make LEVEL=minor release
|
|
149
|
+
|
|
85
150
|
|
|
86
151
|
.PHONY: release-patch
|
|
87
|
-
release-patch:
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
|
|
91
|
-
git checkout CHANGES.md
|
|
152
|
+
release-patch:
|
|
153
|
+
make LEVEL=patch release
|
|
154
|
+
|
|
92
155
|
|
|
93
156
|
.PHONY: prerelease-alpha
|
|
94
|
-
prerelease-alpha:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
|
|
98
|
-
git checkout CHANGES.md
|
|
157
|
+
prerelease-alpha:
|
|
158
|
+
make LEVEL=alpha release
|
|
159
|
+
|
|
99
160
|
|
|
100
161
|
.PHONY: prerelease-beta
|
|
101
|
-
prerelease-beta:
|
|
102
|
-
|
|
103
|
-
make release-zip && \
|
|
104
|
-
npx release-it --github.release --github.update --github.assets=dist/*.zip --no-github.draft --no-increment --no-git --no-npm && \
|
|
105
|
-
git checkout CHANGES.md
|
|
162
|
+
prerelease-beta:
|
|
163
|
+
make LEVEL=beta release
|
|
106
164
|
|
|
107
165
|
|
|
108
166
|
.PHONY: serve
|
package/jest/setup-tests.js
CHANGED
|
@@ -2,15 +2,6 @@
|
|
|
2
2
|
import "core-js/stable";
|
|
3
3
|
import "regenerator-runtime/runtime";
|
|
4
4
|
|
|
5
|
-
import jquery from "jquery";
|
|
6
|
-
global.$ = global.jQuery = jquery;
|
|
7
|
-
|
|
8
|
-
jquery.expr.pseudos.visible = function () {
|
|
9
|
-
// Fix jQuery ":visible" selector always returns false in JSDOM.
|
|
10
|
-
// https://github.com/jsdom/jsdom/issues/1048#issuecomment-401599392
|
|
11
|
-
return true;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
5
|
// pat-fullscreen
|
|
15
6
|
document.requestFullscreen = jest.fn();
|
|
16
7
|
document.exitFullscreen = jest.fn();
|
|
@@ -67,17 +58,6 @@ global.IntersectionObserver = class IntersectionObserver {
|
|
|
67
58
|
}
|
|
68
59
|
};
|
|
69
60
|
|
|
70
|
-
// Do not output error messages
|
|
71
|
-
import logging from "@patternslib/patternslib/src/core/logging";
|
|
72
|
-
logging.setLevel(50); // level: FATAL
|
|
73
|
-
|
|
74
|
-
// patch dom.is_visible to not rely on jest-unavailable offsetWidth/Height but
|
|
75
|
-
// simply on el.hidden.
|
|
76
|
-
import dom from "@patternslib/patternslib/src/core/dom";
|
|
77
|
-
dom.is_visible = (el) => {
|
|
78
|
-
return !el.hidden;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
61
|
// jsDOM does not add ``getClientRects`` or ``getBoundingClientRect`` to a ``document.createRange()``
|
|
82
62
|
// Originally from pat-tiptap to allow scroloing into the view when focusing the editor.
|
|
83
63
|
Range.prototype.getClientRects = () => [];
|
package/package.json
CHANGED
|
@@ -1,45 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternslib/dev",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Development base files for working with Patternslib and add-ons.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@babel/core": "^7.
|
|
7
|
+
"@babel/core": "^7.20.2",
|
|
8
8
|
"@babel/eslint-parser": "^7.19.1",
|
|
9
|
-
"@babel/preset-env": "^7.
|
|
10
|
-
"@commitlint/cli": "^17.
|
|
11
|
-
"@commitlint/config-conventional": "^17.
|
|
12
|
-
"@release-it/conventional-changelog": "^5.1.
|
|
13
|
-
"babel-loader": "^
|
|
14
|
-
"core-js": "3.
|
|
15
|
-
"css-loader": "^6.7.
|
|
16
|
-
"eslint": "^8.
|
|
9
|
+
"@babel/preset-env": "^7.20.2",
|
|
10
|
+
"@commitlint/cli": "^17.2.0",
|
|
11
|
+
"@commitlint/config-conventional": "^17.2.0",
|
|
12
|
+
"@release-it/conventional-changelog": "^5.1.1",
|
|
13
|
+
"babel-loader": "^9.1.0",
|
|
14
|
+
"core-js": "3.26.1",
|
|
15
|
+
"css-loader": "^6.7.2",
|
|
16
|
+
"eslint": "^8.27.0",
|
|
17
17
|
"eslint-config-prettier": "^8.5.0",
|
|
18
|
-
"husky": "^8.0.
|
|
18
|
+
"husky": "^8.0.2",
|
|
19
19
|
"identity-obj-proxy": "^3.0.0",
|
|
20
|
-
"
|
|
21
|
-
"jest": "^29.
|
|
22
|
-
"jest-environment-jsdom": "^29.1.1",
|
|
20
|
+
"jest": "^29.3.1",
|
|
21
|
+
"jest-environment-jsdom": "^29.3.1",
|
|
23
22
|
"jest-watch-typeahead": "^2.2.0",
|
|
24
23
|
"prettier": "^2.7.1",
|
|
25
|
-
"regenerator-runtime": "^0.13.
|
|
26
|
-
"release-it": "^15.
|
|
27
|
-
"sass": "^1.
|
|
28
|
-
"sass-loader": "^13.0
|
|
24
|
+
"regenerator-runtime": "^0.13.10",
|
|
25
|
+
"release-it": "^15.5.0",
|
|
26
|
+
"sass": "^1.56.1",
|
|
27
|
+
"sass-loader": "^13.2.0",
|
|
28
|
+
"semver": "^7.3.8",
|
|
29
29
|
"style-loader": "^3.3.0",
|
|
30
30
|
"terser-webpack-plugin": "^5.3.6",
|
|
31
31
|
"timezone-mock": "^1.3.4",
|
|
32
|
-
"webpack": "^5.
|
|
33
|
-
"webpack-bundle-analyzer": "^4.
|
|
32
|
+
"webpack": "^5.75.0",
|
|
33
|
+
"webpack-bundle-analyzer": "^4.7.0",
|
|
34
34
|
"webpack-cli": "^4.10.0",
|
|
35
35
|
"webpack-dev-server": "^4.11.1",
|
|
36
36
|
"whybundled": "^2.0.0",
|
|
37
37
|
"yarn": "^1.22.19"
|
|
38
38
|
},
|
|
39
|
-
"devDependencies": {
|
|
40
|
-
"@patternslib/patternslib": "*",
|
|
41
|
-
"jquery": "^3.6.1"
|
|
42
|
-
},
|
|
43
39
|
"scripts": {
|
|
44
40
|
"test": "jest"
|
|
45
41
|
},
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Author: Manfred Steyer <manfred.steyer@gmx.net>
|
|
2
|
+
// Author: Johannes Raggam <thetetet@gmail.com>
|
|
3
|
+
|
|
4
|
+
// From:
|
|
5
|
+
// https://github.com/manfredsteyer/plugin-demo.git
|
|
6
|
+
// https://github.com/thet/module-federation-minimaltest.git
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Load remote module / bundle.
|
|
10
|
+
*
|
|
11
|
+
* Wrapper around webpack runtime API
|
|
12
|
+
*
|
|
13
|
+
* Usage: get_container("bundle-name-xyz")
|
|
14
|
+
*
|
|
15
|
+
* @param {string} remote - the remote global name
|
|
16
|
+
* @returns {Promise<object>} - Federated Module Container
|
|
17
|
+
*/
|
|
18
|
+
const container_map = {};
|
|
19
|
+
let is_default_scope_initialized = false;
|
|
20
|
+
|
|
21
|
+
export default async function get_container(remote) {
|
|
22
|
+
const container = window[remote];
|
|
23
|
+
|
|
24
|
+
// Do we still need to initialize the remote?
|
|
25
|
+
if (container_map[remote]) {
|
|
26
|
+
return container;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Do we still need to initialize the shared scope?
|
|
30
|
+
if (!is_default_scope_initialized) {
|
|
31
|
+
await __webpack_init_sharing__("default"); // eslint-disable-line no-undef
|
|
32
|
+
is_default_scope_initialized = true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
await container.init(__webpack_share_scopes__.default); // eslint-disable-line no-undef
|
|
36
|
+
|
|
37
|
+
// Remember that the container has been initialized.
|
|
38
|
+
container_map[remote] = true;
|
|
39
|
+
return container;
|
|
40
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// Author: ScriptedAlchemy <zackary.l.jackson@gmail.com>
|
|
2
|
+
// Author: Johannes Raggam <thetetet@gmail.com>
|
|
3
|
+
|
|
4
|
+
// From:
|
|
5
|
+
// https://twitter.com/ScriptedAlchemy/status/1505135006158532612
|
|
6
|
+
// https://gist.github.com/ScriptedAlchemy/3a24008ef60adc47fad1af7d3299a063
|
|
7
|
+
// https://github.com/module-federation/module-federation-examples/blob/master/dynamic-system-host/app1/src/utils/getOrLoadRemote.js
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Load remote module / bundle.
|
|
11
|
+
*
|
|
12
|
+
* Usage: get_container("bundle-name-xyz", "default", "http://theRemote.com")
|
|
13
|
+
*
|
|
14
|
+
*
|
|
15
|
+
* @param {string} remote - the remote global name
|
|
16
|
+
* @param {string} share_scope - the scope key
|
|
17
|
+
* @param {string} remote_fallback_url - fallback url for remote module
|
|
18
|
+
* @returns {Promise<object>} - Federated Module Container
|
|
19
|
+
*/
|
|
20
|
+
export default function get_container(
|
|
21
|
+
remote,
|
|
22
|
+
share_scope = "default",
|
|
23
|
+
remote_fallback_url = undefined
|
|
24
|
+
) {
|
|
25
|
+
new Promise((resolve, reject) => {
|
|
26
|
+
if (!window[remote]) {
|
|
27
|
+
// Remote not yet globally available.
|
|
28
|
+
|
|
29
|
+
// onload hook when Module Federated resource is loaded.
|
|
30
|
+
const onload = async () => {
|
|
31
|
+
// When remote is loaded, initialize it if it wasn't already.
|
|
32
|
+
if (!window[remote].__initialized) {
|
|
33
|
+
await window[remote].init(__webpack_share_scopes__[share_scope]); // eslint-disable-line no-undef
|
|
34
|
+
// Mark remote as initialized.
|
|
35
|
+
window[remote].__initialized = true;
|
|
36
|
+
}
|
|
37
|
+
// Resolve promise so marking remote as loaded.
|
|
38
|
+
resolve(window[remote]);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Search dom to see if the remote exists as script tag.
|
|
42
|
+
// It might still be loading (async).
|
|
43
|
+
const existing_remote = document.querySelector(`[data-webpack="${remote}"]`);
|
|
44
|
+
|
|
45
|
+
if (existing_remote) {
|
|
46
|
+
// If remote exists but was not loaded, hook into its onload
|
|
47
|
+
// and wait for it to be ready.
|
|
48
|
+
existing_remote.onload = onload;
|
|
49
|
+
existing_remote.onerror = reject;
|
|
50
|
+
} else if (remote_fallback_url) {
|
|
51
|
+
// Inject remote if a fallback exists and call the same onload
|
|
52
|
+
// function
|
|
53
|
+
const script = document.createElement("script");
|
|
54
|
+
script.type = "text/javascript";
|
|
55
|
+
// Mark as data-webpack so runtime can track it internally.
|
|
56
|
+
script.setAttribute("data-webpack", `${remote}`);
|
|
57
|
+
script.async = true;
|
|
58
|
+
script.onerror = reject;
|
|
59
|
+
script.onload = onload;
|
|
60
|
+
script.src = remote_fallback_url;
|
|
61
|
+
document.getElementsByTagName("head")[0].appendChild(script);
|
|
62
|
+
} else {
|
|
63
|
+
// No remote and no fallback exist, reject.
|
|
64
|
+
reject(`Cannot Find Remote ${remote} to inject`);
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
// Remote already instantiated, resolve
|
|
68
|
+
resolve(window[remote]);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize dynamic module federation.
|
|
3
|
+
*/
|
|
4
|
+
import get_container from "./module_federation--dynamic-federation";
|
|
5
|
+
|
|
6
|
+
// Patternslib Module Federation bundle prefix.
|
|
7
|
+
// This is used to filter for module federation enabled bundles.
|
|
8
|
+
// NOTE: This is also defined in ``webpack.mf.js``.
|
|
9
|
+
export const MF_NAME_PREFIX = "__patternslib_mf__";
|
|
10
|
+
|
|
11
|
+
if (typeof window.__patternslib_container_map === "undefined") {
|
|
12
|
+
window.__patternslib_container_map = {};
|
|
13
|
+
}
|
|
14
|
+
const container_map = window.__patternslib_container_map;
|
|
15
|
+
|
|
16
|
+
export async function initialize_remote({ remote_name, exposed_module = "./main" }) {
|
|
17
|
+
if (container_map[`${remote_name}-${exposed_module}`]) {
|
|
18
|
+
// already initialized, return.
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const container = await get_container(remote_name);
|
|
22
|
+
const factory = await container.get(exposed_module);
|
|
23
|
+
const module = factory();
|
|
24
|
+
|
|
25
|
+
container_map[`${remote_name}-${exposed_module}`] = true;
|
|
26
|
+
|
|
27
|
+
console.debug(
|
|
28
|
+
`Patternslib Module Federation: Loaded and initialized bundle "${remote_name}".`
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
return module;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function document_ready(fn) {
|
|
35
|
+
// see if DOM is already available
|
|
36
|
+
if (document.readyState === "complete" || document.readyState === "interactive") {
|
|
37
|
+
// call on next available tick
|
|
38
|
+
setTimeout(fn, 1);
|
|
39
|
+
} else {
|
|
40
|
+
document.addEventListener("DOMContentLoaded", fn);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
document_ready(function () {
|
|
45
|
+
// Automatically initialize all Module Federation enabled Patternslib based
|
|
46
|
+
// bundles by filtering for the prefix ``__patternslib_mf__``.
|
|
47
|
+
// Do this on document ready, as this is the time where all MF bundles have
|
|
48
|
+
// been registered in the global namespace.
|
|
49
|
+
const bundles = Object.keys(window).filter((it) => it.indexOf(MF_NAME_PREFIX) === 0);
|
|
50
|
+
for (const bundle_name of bundles) {
|
|
51
|
+
// Now load + initialize each bundle.
|
|
52
|
+
initialize_remote({ remote_name: bundle_name });
|
|
53
|
+
}
|
|
54
|
+
document.dispatchEvent(
|
|
55
|
+
new Event("patternslib__mf--loaded", { bubbles: true, cancelable: false })
|
|
56
|
+
);
|
|
57
|
+
});
|
|
@@ -54,14 +54,6 @@ const config_factory = (env, argv, config, babel_include = [], package_json) =>
|
|
|
54
54
|
exclude: new RegExp(babel_exclude),
|
|
55
55
|
loader: "babel-loader",
|
|
56
56
|
},
|
|
57
|
-
{
|
|
58
|
-
test: /showdown-prettify/,
|
|
59
|
-
use: [
|
|
60
|
-
{
|
|
61
|
-
loader: "imports-loader?showdown,google-code-prettify",
|
|
62
|
-
},
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
57
|
{
|
|
66
58
|
test: /\.(?:sass|scss|css)$/i,
|
|
67
59
|
use: [
|