File tree Expand file tree Collapse file tree 5 files changed +70
-0
lines changed Expand file tree Collapse file tree 5 files changed +70
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Webworker
2
+
3
+
4
+ ## How to run
5
+
6
+ ``` shell
7
+ node ../../bin/webpack-dev-server.js
8
+ ```
9
+
10
+
11
+ ## What should happen
12
+
13
+ 1 . The main thread sends a message to the Worker.
14
+ 2 . The worker outputs the message in the console.
15
+ 3 . The worker sends a message back to the main thread.
16
+ 4 . The main thread posts the message in the console.
17
+
18
+ No error, warning or other log traces should be in the console.
19
+
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html >
3
+ < head >
4
+ < meta charset ="utf-8 ">
5
+ < title > Example "webworker"</ title >
6
+ </ head >
7
+ < body >
8
+ < script src ="web.bundle.js "> </ script >
9
+ </ body >
10
+ </ html >
Original file line number Diff line number Diff line change
1
+ /* eslint-env browser */
2
+ "use strict" ;
3
+
4
+ const worker = new Worker ( "worker.bundle.js" ) ;
5
+ worker . onmessage = function ( e ) {
6
+ console . log ( "[MAIN]" , e ) ;
7
+ } ;
8
+ worker . postMessage ( {
9
+ hello : 111
10
+ } ) ;
Original file line number Diff line number Diff line change
1
+ "use strict" ;
2
+
3
+ module . exports = [
4
+ {
5
+ devtool : "source-map" ,
6
+ target : "web" ,
7
+ entry : "./web.js" ,
8
+ output : {
9
+ filename : "web.bundle.js" ,
10
+ path : __dirname
11
+ }
12
+ } ,
13
+ {
14
+ devtool : "source-map" ,
15
+ target : "webworker" ,
16
+ entry : "./worker.js" ,
17
+ output : {
18
+ filename : "worker.bundle.js" ,
19
+ path : __dirname
20
+ }
21
+ }
22
+ ] ;
Original file line number Diff line number Diff line change
1
+ /* eslint-env worker */
2
+ "use strict" ;
3
+
4
+ self . onmessage = function ( e ) {
5
+ console . log ( "[WORKER]" , e ) ;
6
+ self . postMessage ( {
7
+ hello : 222
8
+ } ) ;
9
+ } ;
You can’t perform that action at this time.
0 commit comments