forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloader.js
More file actions
21 lines (18 loc) · 736 Bytes
/
loader.js
File metadata and controls
21 lines (18 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import path from 'path';
import parse from '../parser';
import { type LoaderContext } from '../../../transpiled-module';
export default function(code: string, loaderContext: LoaderContext) {
const query = loaderContext.options;
const { context } = query;
let filename = path.basename(loaderContext.path);
filename =
filename.substring(0, filename.lastIndexOf(path.extname(filename))) +
'.vue';
const sourceRoot = path.dirname(path.relative(context, loaderContext.path));
const parts = parse(code, filename, false, sourceRoot, query.bustCache);
let part = parts[query.type];
if (Array.isArray(part)) {
part = part[query.index];
}
return Promise.resolve({ transpiledCode: part ? part.content : '' });
}