Commit 6948c7c 1 parent 27ee9f1 commit 6948c7c Copy full SHA for 6948c7c
File tree 1 file changed +24
-0
lines changed
1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -828,6 +828,30 @@ const require = createRequire(cwd() + '/<preload>');
828
828
}
829
829
` ` `
830
830
831
+ In order to allow communication between the application and the loader another
832
+ argument is provided to the preload code ` port` . This is available as an
833
+ parameter to the loader hook and inside of the source text returned by the hook.
834
+ Some care must be taken in order to properly ` ref ()` and ` unref ()` the
835
+ ` MessagePort ` to prevent a process from being in a state where it won't close
836
+ normally.
837
+
838
+ ` ` ` js
839
+ /**
840
+ * This example causes
841
+ * @param {object} utilities
842
+ * @param {MessagePort} utilities.port
843
+ */
844
+ export function getGlobalPreloadCode ({port}) {
845
+ port .onmessage = (evt ) => {
846
+ // ...
847
+ };
848
+ return ` \
849
+ port.postMessage('I went to the Loader and back');
850
+ port.onmessage = eval;
851
+ ` ;
852
+ }
853
+ ` ` `
854
+
831
855
### Examples
832
856
833
857
The various loader hooks can be used together to accomplish wide-ranging
You can’t perform that action at this time.
0 commit comments