@@ -7,6 +7,7 @@ import WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlug
7
7
8
8
export default function loader ( ) { }
9
9
10
+ const CACHE = { } ;
10
11
const tapName = 'workerize-loader' ;
11
12
12
13
function compilationHook ( compiler , handler ) {
@@ -37,25 +38,24 @@ loader.pitch = function(request) {
37
38
38
39
const cb = this . async ( ) ;
39
40
40
- const filename = loaderUtils . interpolateName ( this , `${ options . name || '[fullhash]' } .worker.js` , {
41
- context : options . context || this . rootContext || this . options . context ,
42
- regExp : options . regExp
43
- } ) ;
41
+ const compilerOptions = this . _compiler . options || { } ;
42
+
43
+ const filename = ( options . name || '[fullhash]' ) + '.worker.js' ;
44
44
45
45
const worker = { } ;
46
46
47
47
worker . options = {
48
48
filename,
49
- chunkFilename : `[id].${ filename } ` ,
50
- namedChunkFilename : null
49
+ chunkFilename : filename ,
50
+ publicPath : options . publicPath || compilerOptions . output . publicPath ,
51
+ globalObject : 'self'
51
52
} ;
52
53
53
- const compilerOptions = this . _compiler . options || { } ;
54
54
if ( compilerOptions . output && compilerOptions . output . globalObject === 'window' ) {
55
55
console . warn ( 'Warning (workerize-loader): output.globalObject is set to "window". It should be set to "self" or "this" to support HMR in Workers.' ) ;
56
56
}
57
57
58
- worker . compiler = this . _compilation . createChildCompiler ( ' worker' , worker . options ) ;
58
+ worker . compiler = this . _compilation . createChildCompiler ( ` worker ${ request } ` , worker . options ) ;
59
59
60
60
( new WebWorkerTemplatePlugin ( worker . options ) ) . apply ( worker . compiler ) ;
61
61
@@ -82,10 +82,9 @@ loader.pitch = function(request) {
82
82
} ) . apply ( worker . compiler ) ;
83
83
}
84
84
85
- ( new SingleEntryPlugin ( this . context , `!! ${ path . resolve ( __dirname , 'rpc-worker-loader.js' ) } ! ${ request } ` , 'main' ) ) . apply ( worker . compiler ) ;
85
+ const bundleName = path . parse ( this . resourcePath ) . name ;
86
86
87
- const subCache = `subcache ${ __dirname } ${ request } ` ;
88
- const CACHE = this . _compilation . getCache ( subCache ) ;
87
+ ( new SingleEntryPlugin ( this . context , `!!${ path . resolve ( __dirname , 'rpc-worker-loader.js' ) } !${ request } ` , bundleName ) ) . apply ( worker . compiler ) ;
89
88
90
89
compilationHook ( worker . compiler , ( compilation , data ) => {
91
90
parseHook ( data , ( parser , options ) => {
@@ -96,7 +95,7 @@ loader.pitch = function(request) {
96
95
let entryModule =
97
96
compilation . entries instanceof Map
98
97
? compilation . moduleGraph . getModule (
99
- compilation . entries . get ( 'main' ) . dependencies [ 0 ]
98
+ compilation . entries . get ( bundleName ) . dependencies [ 0 ]
100
99
)
101
100
: compilation . entries [ 0 ] ;
102
101
@@ -121,7 +120,7 @@ loader.pitch = function(request) {
121
120
if ( compilation . moduleGraph ) {
122
121
const { getEntryRuntime } = require ( 'webpack/lib/util/runtime' ) ;
123
122
const { UsageState } = require ( 'webpack' ) ;
124
- const runtime = getEntryRuntime ( compilation , 'main' ) ;
123
+ const runtime = getEntryRuntime ( compilation , bundleName ) ;
125
124
for ( const exportName of Object . keys ( exports ) ) {
126
125
const exportInfo = compilation . moduleGraph . getExportInfo ( entryModule , exportName ) ;
127
126
exportInfo . setUsed ( UsageState . Used , runtime ) ;
0 commit comments