Skip to content

Commit 08c0f45

Browse files
authored
fix: Uncompiled SFC under webpack (#28)
1 parent 923d82f commit 08c0f45

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/core/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { isDev } from './isDev';
55
import { parse_ID } from './parse_ID';
66
import { transform } from './transform';
77

8-
export const unpluginFactory: UnpluginFactory<Options> = (options = {}) => {
8+
export const unpluginFactory: UnpluginFactory<Options | undefined> = (
9+
options = {},
10+
meta,
11+
) => {
912
if (!isDev()) {
1013
return {
1114
name: 'unplugin-vue-source',
@@ -14,6 +17,7 @@ export const unpluginFactory: UnpluginFactory<Options> = (options = {}) => {
1417

1518
const opts = resolveOptions(options);
1619
const filter = createFilter(opts.include, opts.exclude);
20+
const isWebpack = meta.framework === 'webpack';
1721

1822
return {
1923
name: 'unplugin-vue-source',
@@ -24,7 +28,7 @@ export const unpluginFactory: UnpluginFactory<Options> = (options = {}) => {
2428
return query.raw == null && filter(file);
2529
},
2630
transform(code, id) {
27-
return transform(code, id, opts);
31+
return transform(code, id, opts, isWebpack);
2832
},
2933
};
3034
};

src/core/transform.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ import { transform_SFC } from './transform_SFC';
77
import { transform_MDX } from './transform_MDX';
88
import { transform_JSX } from './transform_JSX';
99

10-
export function transform(code: string, id: string, opts: ResolvedOptions) {
10+
export function transform(
11+
code: string,
12+
id: string,
13+
opts: ResolvedOptions,
14+
isWebpack = false,
15+
) {
1116
const { root, sourceMap } = opts;
1217

1318
let s: MagicString;
1419
const parsed = parse_ID(id, root);
1520

16-
if (parsed.query[TRACE_ID]) {
21+
if (!isWebpack && parsed.query[TRACE_ID]) {
1722
return;
1823
}
1924

0 commit comments

Comments
 (0)