Skip to content

Commit e7fb11e

Browse files
committed
feat: support source maps
1 parent 6963c47 commit e7fb11e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/cache.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ export default function createCache(config: ResolvedConfig) {
1313
if (!descriptorCache.has(filename)) {
1414
const { descriptor, errors } = compiler.parse(
1515
fs.readFileSync(filename, "utf8").toString(),
16-
{ filename }
16+
{
17+
filename,
18+
sourceMap:
19+
config.command === "build" ? !!config.build.sourcemap : true,
20+
sourceRoot: config.root,
21+
}
1722
);
1823
if (errors.length > 0) {
1924
throw errors[0];

src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ export default function vueNestedSFC(): PluginOption {
3737

3838
const descriptor = cache.getDescriptor(filename);
3939

40-
return (
41-
descriptor.customBlocks.find(
42-
(block) =>
43-
block.type === "component" &&
44-
typeof block.attrs.name === "string" &&
45-
pascalCase(block.attrs.name) === component
46-
)?.content || ""
40+
const componentBlock = descriptor.customBlocks.find(
41+
(block) =>
42+
block.type === "component" &&
43+
typeof block.attrs.name === "string" &&
44+
pascalCase(block.attrs.name) === component
4745
);
46+
47+
if (!componentBlock) {
48+
return "";
49+
}
50+
51+
return { code: componentBlock.content, map: componentBlock.map as any };
4852
},
4953

5054
transform(code, id) {

0 commit comments

Comments
 (0)