diff --git a/src/core/index.ts b/src/core/index.ts index 90d20be..eadea89 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -24,18 +24,18 @@ export const unpluginFactory: UnpluginFactory = ( enforce: 'pre', transformInclude(id) { - const { file, query } = parse_ID(id); + const { file, query } = parse_ID(normalizePath(id)); return query.raw == null && filter(file); }, transform(code, id) { - return transform(code, id, opts, isWebpack); + return transform(code, normalizePath(id), opts, isWebpack); }, }; }; function resolveOptions(opts: Options): ResolvedOptions { return { - root: opts.root ?? process.cwd(), + root: normalizePath(opts.root ?? process.cwd()), sourceMap: opts.sourceMap ?? false, babelParserPlugins: opts.babelParserPlugins ?? [], include: opts.include ?? /\.(vue|jsx|tsx|mdx)$/, @@ -43,4 +43,8 @@ function resolveOptions(opts: Options): ResolvedOptions { }; } +function normalizePath(path: string) { + return path.replace(/\\/g, '/'); +} + export default /* #__PURE__ */ createUnplugin(unpluginFactory);