1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getDefaultFilename = getDefaultFilename;
|
7 | exports.getDefaultChunkFilename = getDefaultChunkFilename;
|
8 | exports.getExternalsType = getExternalsType;
|
9 | exports.workerGenerator = workerGenerator;
|
10 | exports.sourceURLWebpackRegex = exports.sourceMappingURLRegex = void 0;
|
11 |
|
12 | var _loaderUtils = require("loader-utils");
|
13 |
|
14 | function getDefaultFilename(filename) {
|
15 | if (typeof filename === "function") {
|
16 | return filename;
|
17 | }
|
18 |
|
19 | return filename.replace(/\.([a-z]+)(\?.+)?$/i, ".worker.$1$2");
|
20 | }
|
21 |
|
22 | function getDefaultChunkFilename(chunkFilename) {
|
23 | return chunkFilename.replace(/\.([a-z]+)(\?.+)?$/i, ".worker.$1$2");
|
24 | }
|
25 |
|
26 | function getExternalsType(compilerOptions) {
|
27 |
|
28 | if (compilerOptions.output.libraryTarget) {
|
29 | return compilerOptions.output.libraryTarget;
|
30 | }
|
31 |
|
32 |
|
33 | if (compilerOptions.externalsType) {
|
34 | return compilerOptions.externalsType;
|
35 | }
|
36 |
|
37 | if (compilerOptions.output.library) {
|
38 | return compilerOptions.output.library.type;
|
39 | }
|
40 |
|
41 | if (compilerOptions.output.module) {
|
42 | return "module";
|
43 | }
|
44 |
|
45 | return "var";
|
46 | }
|
47 |
|
48 | function workerGenerator(loaderContext, workerFilename, workerSource, options) {
|
49 | let workerConstructor;
|
50 | let workerOptions;
|
51 |
|
52 | if (typeof options.worker === "undefined") {
|
53 | workerConstructor = "Worker";
|
54 | } else if (typeof options.worker === "string") {
|
55 | workerConstructor = options.worker;
|
56 | } else {
|
57 | ({
|
58 | type: workerConstructor,
|
59 | options: workerOptions
|
60 | } = options.worker);
|
61 | }
|
62 |
|
63 | const esModule = typeof options.esModule !== "undefined" ? options.esModule : true;
|
64 | const fnName = `${workerConstructor}_fn`;
|
65 |
|
66 | if (options.inline) {
|
67 | const InlineWorkerPath = (0, _loaderUtils.stringifyRequest)(loaderContext, `!!${require.resolve("./runtime/inline.js")}`);
|
68 | let fallbackWorkerPath;
|
69 |
|
70 | if (options.inline === "fallback") {
|
71 | fallbackWorkerPath = `__webpack_public_path__ + ${JSON.stringify(workerFilename)}`;
|
72 | }
|
73 |
|
74 | return `
|
75 | ${esModule ? `import worker from ${InlineWorkerPath};` : `var worker = require(${InlineWorkerPath});`}
|
76 |
|
77 | ${esModule ? "export default" : "module.exports ="} function ${fnName}() {\n return worker(${JSON.stringify(workerSource)}, ${JSON.stringify(workerConstructor)}, ${JSON.stringify(workerOptions)}, ${fallbackWorkerPath});\n}\n`;
|
78 | }
|
79 |
|
80 | return `${esModule ? "export default" : "module.exports ="} function ${fnName}() {\n return new ${workerConstructor}(__webpack_public_path__ + ${JSON.stringify(workerFilename)}${workerOptions ? `, ${JSON.stringify(workerOptions)}` : ""});\n}\n`;
|
81 | }
|
82 |
|
83 |
|
84 | const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*(.*?(?=[\s'"]|\\n|\*\/|$)(?:\\n)?)\s*/;
|
85 |
|
86 |
|
87 | const sourceMappingURLRegex = RegExp("(?:" + "/\\*" + "(?:\\s*\r?\n(?://)?)?" + "(?:" + innerRegex.source + ")" + "\\s*" + "\\*/" + "|" + "//(?:" + innerRegex.source + ")" + ")" + "\\s*");
|
88 | exports.sourceMappingURLRegex = sourceMappingURLRegex;
|
89 | const sourceURLWebpackRegex = RegExp("\\/\\/#\\ssourceURL=webpack-internal:\\/\\/\\/(.*?)\\\\n");
|
90 |
|
91 |
|
92 | exports.sourceURLWebpackRegex = sourceURLWebpackRegex; |
\ | No newline at end of file |