From a8293b886162ce9d610f8297e281a5a4bc7e37cf Mon Sep 17 00:00:00 2001 From: Anthony Fu Date: Mon, 25 Oct 2021 21:04:32 +0800 Subject: [PATCH] fix: windows path resolving --- src/webpack/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/webpack/index.ts b/src/webpack/index.ts index 75a63cdb..29aa2e3f 100644 --- a/src/webpack/index.ts +++ b/src/webpack/index.ts @@ -1,6 +1,6 @@ import fs from 'fs' import { fileURLToPath } from 'url' -import { resolve, dirname, join } from 'path' +import { resolve, dirname } from 'path' import VirtualModulesPlugin from 'webpack-virtual-modules' import type { Resolver, ResolveRequest } from 'enhanced-resolve' import type { UnpluginContextMeta, UnpluginInstance, UnpluginFactory, WebpackCompiler, ResolvedUnpluginOptions } from '../types' @@ -26,12 +26,17 @@ export function getWebpackPlugin ( } } + let virtualModulePrefix = slash(resolve(process.cwd(), '_virtual_')) + if (!virtualModulePrefix.startsWith('/')) { + virtualModulePrefix = '/' + virtualModulePrefix + } + const rawPlugin = factory(userOptions, meta) const plugin = Object.assign( rawPlugin, { __unpluginMeta: meta, - __virtualModulePrefix: slash(join(process.cwd(), '_virtual_')) + __virtualModulePrefix: virtualModulePrefix } ) as ResolvedUnpluginOptions