1 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
2 |
|
3 | var path = _interopDefault(require('path'));
|
4 | var loaderUtils = _interopDefault(require('loader-utils'));
|
5 | var slash = _interopDefault(require('slash'));
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | var comlinkLoaderSpecificOptions = ['multiple', 'multi',
|
23 | 'singleton'];
|
24 | function loader() {}
|
25 |
|
26 | loader.pitch = function (request) {
|
27 | var options = loaderUtils.getOptions(this) || {};
|
28 | var singleton = options.singleton;
|
29 | var workerLoaderOptions = {};
|
30 |
|
31 | for (var i in options) {
|
32 | if (comlinkLoaderSpecificOptions.indexOf(i) === -1) {
|
33 | workerLoaderOptions[i] = options[i];
|
34 | }
|
35 | }
|
36 |
|
37 | var workerLoader = "!worker-loader?" + (JSON.stringify(workerLoaderOptions)) + "!" + (slash(path.resolve(__dirname, 'comlink-worker-loader.js')));
|
38 | var remainingRequest = JSON.stringify(workerLoader + '!' + request);
|
39 |
|
40 | if (singleton === true) {
|
41 | return ("\n module.exports = require('comlink').wrap(require(" + remainingRequest + ")());\n " + (options.module === false ? '' : 'module.exports.__esModule = true;') + "\n ").replace(/\n\s*/g, '');
|
42 | }
|
43 |
|
44 |
|
45 | if (singleton === false) {
|
46 | return ("\n module.exports = function () {\n return require('comlink').wrap(require(" + remainingRequest + ")());\n };\n ").replace(/\n\s*/g, '');
|
47 | }
|
48 |
|
49 | return ("\n var wrap = require('comlink').wrap,\n Worker = require(" + remainingRequest + "),\n inst;\n module.exports = function f() {\n if (this instanceof f) return wrap(Worker());\n return inst || (inst = wrap(Worker()));\n };\n ").replace(/\n\s*/g, '');
|
50 | };
|
51 |
|
52 | module.exports = loader;
|
53 |
|