Skip to content

Commit

Permalink
fix: Normalize paths in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
zjxxxxxxxxx committed Jul 17, 2024
1 parent 0548cb3 commit 5086052
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,27 @@ export const unpluginFactory: UnpluginFactory<Options | undefined> = (
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)$/,
exclude: opts.exclude ?? /\/node_modules\//,
};
}

function normalizePath(path: string) {
return path.replace(/\\/g, '/');
}

export default /* #__PURE__ */ createUnplugin(unpluginFactory);

0 comments on commit 5086052

Please sign in to comment.