This repository was archived by the owner on Sep 9, 2021. It is now read-only.
Description
Operating System: MacOS
Node Version: 12.16.1
NPM Version: 6.13.4
webpack Version: 4.44.1
worker-loader Version: 3.0.1
Expected Behavior
I would expect that setting publicPath in options would take precedence over __webpack_public_path__ variable.
We use webpacker and setting a CDN path to serve our assets. However, worker must be served from same domain in order to work.
I had to use patch-package to revert to one of previous versions and fit it my needs (code below).
Actual Behavior
With our setup, passing publicPath does nothing.
Code
patch-package snippet
diff -- git a / node_modules / worker - loader / dist / utils . js b / node_modules / worker - loader / dist / utils . js
index abe26e2 . .89089 ce 100644
-- - a / node_modules / worker - loader / dist / utils . js
++ + b / node_modules / worker - loader / dist / utils . js
@@ - 62 , 12 + 62 , 16 @@ function workerGenerator ( loaderContext , workerFilename , workerSource , options ) {
const esModule = typeof options . esModule !== 'undefined' ? options . esModule : true ;
+ const publicPath = typeof options . publicPath === 'undefined'
+ ? '__webpack_public_path__'
+ : JSON . stringify ( options . publicPath ) ;
+
if ( options . inline ) {
const InlineWorkerPath = ( 0 , _loaderUtils . stringifyRequest ) ( loaderContext , `!!${ require . resolve ( './runtime/inline.js' ) } ` ) ;
let fallbackWorkerPath ;
if ( options . inline === 'fallback' ) {
- fallbackWorkerPath = `__webpack_public_path__ + ${ JSON . stringify ( workerFilename ) } ` ;
+ fallbackWorkerPath = `${ publicPath } + ${ JSON . stringify ( workerFilename ) } ` ;
}
return `
@@ -76,7 +80,7 @@ ${ esModule ? `import worker from ${ InlineWorkerPath } ;` : `var worker = require($
${ esModule ? 'export default' : 'module.exports =' } function() {\n return worker(${ JSON . stringify ( workerSource ) } , ${ JSON . stringify ( workerConstructor ) } , ${ JSON . stringify ( workerOptions ) } , ${ fallbackWorkerPath } );\n}\n` ;
}
- return ` $ { esModule ? 'export default' : 'module.exports =' } function ( ) { \n return new $ { workerConstructor} ( __webpack_public_path__ + $ { JSON . stringify ( workerFilename ) } ${workerOptions ? `, ${ JSON . stringify ( workerOptions ) } ` : '' } ) ; \n} \n`;
+ return ` $ { esModule ? 'export default' : 'module.exports =' } function ( ) { \n return new $ { workerConstructor} ( $ { publicPath} + $ { JSON . stringify ( workerFilename ) } ${workerOptions ? `, ${ JSON . stringify ( workerOptions ) } ` : '' } ) ; \n} \n`;
} // Matches only the last occurrence of sourceMappingURL
Reactions are currently unavailable
Expected Behavior
I would expect that setting publicPath in options would take precedence over
__webpack_public_path__variable.We use webpacker and setting a CDN path to serve our assets. However, worker must be served from same domain in order to work.
I had to use patch-package to revert to one of previous versions and fit it my needs (code below).
Actual Behavior
With our setup, passing
publicPathdoes nothing.Code
patch-package snippet