/
websites
/
test-project
/
node_modules
/
worker-plugin
/
dist
/
Upload File
HOME
{"version":3,"file":"loader.js","sources":["../src/loader.js"],"sourcesContent":["/**\n * Copyright 2018 Google LLC\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\nimport loaderUtils from 'loader-utils';\nimport SingleEntryPlugin from 'webpack/lib/SingleEntryPlugin';\nimport WebWorkerTemplatePlugin from 'webpack/lib/webworker/WebWorkerTemplatePlugin';\nimport WORKER_PLUGIN_SYMBOL from './symbol';\n\nlet FetchCompileWasmPlugin;\ntry {\n FetchCompileWasmPlugin = require('webpack/lib/web/FetchCompileWasmPlugin'); // Webpack 5\n} catch (e) {}\nFetchCompileWasmPlugin = FetchCompileWasmPlugin || require('webpack/lib/web/FetchCompileWasmTemplatePlugin'); // Webpack 4\n\nconst NAME = 'WorkerPluginLoader';\nlet hasWarned = false;\n\nexport function pitch (request) {\n this.cacheable(false);\n const cb = this.async();\n\n const compilerOptions = this._compiler.options || {};\n\n const plugin = compilerOptions.plugins.find(p => p[WORKER_PLUGIN_SYMBOL]) || {};\n const pluginOptions = (plugin && plugin.options) || {};\n\n if (pluginOptions.globalObject == null && !hasWarned && compilerOptions.output && compilerOptions.output.globalObject === 'window') {\n hasWarned = true;\n console.warn('Warning (worker-plugin): output.globalObject is set to \"window\". It must be set to \"self\" to support HMR in Workers.');\n }\n\n const options = loaderUtils.getOptions(this) || {};\n const chunkFilename = compilerOptions.output.chunkFilename.replace(/\\.([a-z]+)(\\?.+)?$/i, '.worker.$1$2');\n const workerOptions = {\n filename: (options.filename || pluginOptions.filename || chunkFilename).replace(/\\[(?:chunkhash|contenthash)(:\\d+(?::\\d+)?)?\\]/g, '[hash$1]'),\n chunkFilename: options.chunkFilename || pluginOptions.chunkFilename || chunkFilename,\n globalObject: pluginOptions.globalObject || 'self'\n };\n\n const plugins = (pluginOptions.plugins || []).map(plugin => {\n if (typeof plugin !== 'string') {\n return plugin;\n }\n const found = compilerOptions.plugins.find(p => p.constructor.name === plugin);\n if (!found) {\n console.warn(`Warning (worker-plugin): Plugin \"${plugin}\" is not found.`);\n }\n return found;\n });\n\n const workerCompiler = this._compilation.createChildCompiler(NAME, workerOptions, plugins);\n workerCompiler.context = this._compiler.context;\n (new WebWorkerTemplatePlugin()).apply(workerCompiler);\n (new FetchCompileWasmPlugin({\n mangleImports: compilerOptions.optimization.mangleWasmImports\n })).apply(workerCompiler);\n (new SingleEntryPlugin(this.context, request, options.name)).apply(workerCompiler);\n\n const subCache = `subcache ${__dirname} ${request}`;\n workerCompiler.hooks.compilation.tap(NAME, compilation => {\n if (compilation.cache) {\n if (!compilation.cache[subCache]) compilation.cache[subCache] = {};\n compilation.cache = compilation.cache[subCache];\n }\n });\n\n workerCompiler.runAsChild((err, entries, compilation) => {\n if (!err && compilation.errors && compilation.errors.length) {\n err = compilation.errors[0];\n }\n const entry = entries && entries[0] && entries[0].files.values().next().value; // compatible with Array (v4) and Set (v5) prototypes\n if (!err && !entry) err = Error(`WorkerPlugin: no entry for ${request}`);\n if (err) return cb(err);\n return cb(null, `${options.esModule ? 'export default' : 'module.exports ='} __webpack_public_path__ + ${JSON.stringify(entry)}`);\n });\n};\n\nexport default { pitch };\n"],"names":["let","FetchCompileWasmPlugin","require","e","const","NAME","hasWarned","pitch","request","cacheable","cb","async","compilerOptions","_compiler","options","plugin","plugins","find","p","WORKER_PLUGIN_SYMBOL","pluginOptions","globalObject","output","console","warn","loaderUtils","getOptions","chunkFilename","replace","workerOptions","filename","map","found","constructor","name","workerCompiler","_compilation","createChildCompiler","context","WebWorkerTemplatePlugin","apply","mangleImports","optimization","mangleWasmImports","SingleEntryPlugin","subCache","__dirname","hooks","compilation","tap","cache","runAsChild","err","entries","errors","length","entry","files","values","next","value","Error","esModule","JSON","stringify"],"mappings":";;;;;;;AAAA;;;;;;;;;;;;;;;AAgBA,AAKAA,IAAIC,sBAAJ;;AACA,IAAI;EACFA,sBAAsB,GAAGC,OAAO,CAAC,wCAAD,CAAhC,CADE;CAAJ,CAEE,OAAOC,CAAP,EAAU;;AACZF,sBAAsB,GAAGA,sBAAsB,IAAIC,OAAO,CAAC,gDAAD,CAA1D;;AAEAE,IAAMC,IAAI,GAAG,oBAAb;AACAL,IAAIM,SAAS,GAAG,KAAhB;AAEA,AAAO,SAASC,KAAT,CAAgBC,OAAhB,EAAyB;OACzBC,SAAL,CAAe,KAAf;MACMC,EAAE,GAAG,KAAKC,KAAL,EAAX;MAEMC,eAAe,GAAG,KAAKC,SAAL,CAAeC,OAAf,IAA0B,EAAlD;MAEMC,MAAM,GAAGH,eAAe,CAACI,OAAhB,CAAwBC,IAAxB,WAA6BC,YAAKA,CAAC,CAACC,oBAAD,IAAnC,KAA8D,EAA7E;MACMC,aAAa,GAAIL,MAAM,IAAIA,MAAM,CAACD,OAAlB,IAA8B,EAApD;;MAEIM,aAAa,CAACC,YAAd,IAA8B,IAA9B,IAAsC,CAACf,SAAvC,IAAoDM,eAAe,CAACU,MAApE,IAA8EV,eAAe,CAACU,MAAhB,CAAuBD,YAAvB,KAAwC,QAA1H,EAAoI;IAClIf,SAAS,GAAG,IAAZ;IACAiB,OAAO,CAACC,IAAR,CAAa,sHAAb;;;MAGIV,OAAO,GAAGW,WAAW,CAACC,UAAZ,CAAuB,IAAvB,KAAgC,EAAhD;MACMC,aAAa,GAAGf,eAAe,CAACU,MAAhB,CAAuBK,aAAvB,CAAqCC,OAArC,CAA6C,qBAA7C,EAAoE,cAApE,CAAtB;MACMC,aAAa,GAAG;IACpBC,QAAQ,EAAE,CAAChB,OAAO,CAACgB,QAAR,IAAoBV,aAAa,CAACU,QAAlC,IAA8CH,aAA/C,EA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