forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
51 lines (40 loc) · 1.09 KB
/
index.ts
File metadata and controls
51 lines (40 loc) · 1.09 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
50
51
/* eslint-disable import/default */
// @ts-ignore
import PugWorker from 'worker-loader?publicPath=/&name=pug-transpiler.[hash:8].worker.js!./pug-worker';
/* eslint-enable import/default */
import WorkerTranspiler from '../worker-transpiler';
import { LoaderContext } from '../../transpiled-module';
import { TranspilerResult } from '..';
class PugTranspiler extends WorkerTranspiler {
worker: Worker;
constructor() {
super('pug-loader', PugWorker, 1);
this.cacheable = false;
}
doTranspilation(
code: string,
loaderContext: LoaderContext
): Promise<TranspilerResult> {
return new Promise((resolve, reject) => {
const { path } = loaderContext;
this.queueTask(
{
code,
path,
},
loaderContext._module.getId(),
loaderContext,
(err, data) => {
if (err) {
loaderContext.emitError(err);
return reject(err);
}
return resolve(data);
}
);
});
}
}
const transpiler = new PugTranspiler();
export { PugTranspiler };
export default transpiler;