-
-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (45 loc) · 1.33 KB
/
index.js
File metadata and controls
49 lines (45 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import loaderUtils from 'loader-utils';
import { getPool } from './workerPools';
import { setupTransferHandler } from './messagePortTransferHandler';
setupTransferHandler();
function pitch() {
const options = loaderUtils.getOptions(this) || {};
const workerPool = getPool(options);
if (!workerPool.isAbleToRun()) {
return;
}
const callback = this.async();
workerPool.run({
loaders: this.loaders.slice(this.loaderIndex + 1).map((l) => {
return {
loader: l.path,
options: l.options,
ident: l.ident,
};
}),
resource: this.resourcePath + (this.resourceQuery || ''),
sourceMap: this.sourceMap,
emitError: this.emitError,
emitWarning: this.emitWarning,
resolve: this.resolve,
target: this.target,
minimize: this.minimize,
resourceQuery: this.resourceQuery,
optionsContext: this.rootContext || this.options.context,
}, (err, r) => {
if (r) {
r.fileDependencies.forEach(d => this.addDependency(d));
r.contextDependencies.forEach(d => this.addContextDependency(d));
}
if (err) {
callback(err);
return;
}
callback(null, ...r.result);
});
}
function warmup(options, requires) {
const workerPool = getPool(options);
workerPool.warmup(requires);
}
export { pitch, warmup }; // eslint-disable-line import/prefer-default-export