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
58 lines (46 loc) · 1.29 KB
/
index.ts
File metadata and controls
58 lines (46 loc) · 1.29 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
52
53
54
55
56
57
58
// @ts-ignore
import SassWorker from 'worker-loader?publicPath=/&name=sass-transpiler.[hash:8].worker.js!./worker';
import WorkerTranspiler from '../worker-transpiler';
import { LoaderContext } from '../../transpiled-module';
import { TranspilerResult } from '..';
class SassTranspiler extends WorkerTranspiler {
worker: Worker;
constructor() {
super('sass-loader', SassWorker, 1, { hasFS: true });
this.cacheable = false;
}
doTranspilation(
code: string,
loaderContext: LoaderContext
): Promise<TranspilerResult> {
const indentedSyntax =
loaderContext.options.indentedSyntax == null
? loaderContext.path.endsWith('.sass')
: true;
return new Promise((resolve, reject) => {
if (code === '' || code == null) {
resolve({ transpiledCode: '' });
return;
}
this.queueTask(
{
code,
path: loaderContext.path,
indentedSyntax,
},
loaderContext._module.getId(),
loaderContext,
(err, data) => {
if (err) {
loaderContext.emitError(err);
return reject(err);
}
return resolve(data);
}
);
});
}
}
const transpiler = new SassTranspiler();
export { SassTranspiler };
export default transpiler;