Skip to content

Commit

Permalink
fix: remove commonjs-entry query from moduleFacadeId
Browse files Browse the repository at this point in the history
  • Loading branch information
patak-dev committed May 18, 2022
1 parent 105168e commit 8b43995
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/vite/src/node/plugins/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
isRelativeBase,
normalizePath,
processSrcSet,
removeCommonJsEntryQuery,
slash
} from '../utils'
import type { ResolvedConfig } from '../config'
Expand Down Expand Up @@ -604,7 +605,8 @@ export function buildHtmlPlugin(config: ResolvedConfig): Plugin {
(chunk) =>
chunk.type === 'chunk' &&
chunk.isEntry &&
chunk.facadeModuleId === id
chunk.facadeModuleId &&
removeCommonJsEntryQuery(chunk.facadeModuleId) === id
) as OutputChunk | undefined

let canInlineEntry = false
Expand Down
7 changes: 5 additions & 2 deletions packages/vite/src/node/plugins/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from 'path'
import type { OutputChunk } from 'rollup'
import type { ResolvedConfig } from '..'
import type { Plugin } from '../plugin'
import { normalizePath } from '../utils'
import { normalizePath, removeCommonJsEntryQuery } from '../utils'

export type Manifest = Record<string, ManifestChunk>

Expand Down Expand Up @@ -33,7 +33,10 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
function getChunkName(chunk: OutputChunk) {
if (chunk.facadeModuleId) {
let name = normalizePath(
path.relative(config.root, chunk.facadeModuleId)
path.relative(
config.root,
removeCommonJsEntryQuery(chunk.facadeModuleId)
)
)
if (format === 'system' && !chunk.name.includes('-legacy')) {
const ext = path.extname(name)
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ export function removeTimestampQuery(url: string): string {
return url.replace(timestampRE, '').replace(trailingSeparatorRE, '')
}

const commonJsEntryQueryRE = /(\?|&)commonjs-entry(?:&|$)/
export function removeCommonJsEntryQuery(url: string): string {
return url.replace(commonJsEntryQueryRE, '').replace(trailingSeparatorRE, '')
}

export function isRelativeBase(base: string): boolean {
return base === '' || base.startsWith('.')
}
Expand Down

0 comments on commit 8b43995

Please sign in to comment.