Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: keep the same slash with system #82

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/webpack/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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'
import { slash, backSlash } from './utils'
import { slash } from './utils'
import genContext from './genContext'
const _dirname = typeof __dirname !== 'undefined' ? __dirname : dirname(fileURLToPath(import.meta.url))
const TRANSFORM_LOADER = resolve(_dirname, 'webpack/loaders/transform.js')
Expand Down Expand Up @@ -86,7 +86,7 @@ export function getWebpackPlugin<UserOptions = {}> (
return callback()
}

const id = backSlash(request.request)
const id = slash(request.request)

// filter out invalid requests
if (id.startsWith(plugin.__virtualModulePrefix)) {
Expand All @@ -106,7 +106,7 @@ export function getWebpackPlugin<UserOptions = {}> (
// if the resolved module is not exists,
// we treat it as a virtual module
if (!fs.existsSync(resolved)) {
resolved = plugin.__virtualModulePrefix + backSlash(resolved)
resolved = plugin.__virtualModulePrefix + slash(resolved)
// webpack virtual module should pass in the correct path
plugin.__vfs!.writeModule(resolved, '')
plugin.__vfsModules!.add(resolved)
Expand Down
8 changes: 3 additions & 5 deletions src/webpack/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
export function slash (path: string) {
return path.replace(/\\/g, '/')
}
import { sep } from 'path'

export function backSlash (path: string) {
return path.replace(/\//g, '\\')
export function slash (path: string) {
return path.replace(/[\\/]/g, sep)
}