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: add library to fix module federation hmr #2082

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
11 changes: 8 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ export interface VueLoaderOptions {
customElement?: boolean | RegExp

hotReload?: boolean
/**
* To address the issue of identical component names in different projects
* module federation
*/
library?: string
exposeFilename?: boolean
appendExtension?: boolean
enableTsInTemplate?: boolean
Expand Down Expand Up @@ -137,7 +142,7 @@ export default function loader(
})
return ``
}

const hmrPrifix = options.library ? options.library + '_' : ''
// module id for scoped CSS & hot-reload
const rawShortFilePath = path
.relative(rootContext || process.cwd(), filename)
Expand All @@ -146,7 +151,7 @@ export default function loader(
const id = hash(
isProduction
? shortFilePath + '\n' + source.replace(/\r\n/g, '\n')
: shortFilePath
: hmrPrifix + shortFilePath
)

// if the query has a type field, this is a language block request
Expand Down Expand Up @@ -316,7 +321,7 @@ export default function loader(
// from the devtools.
propsToAttach.push([
`__file`,
JSON.stringify(rawShortFilePath.replace(/\\/g, '/')),
JSON.stringify(hmrPrifix + rawShortFilePath.replace(/\\/g, '/')),
])
} else if (options.exposeFilename) {
// Libraries can opt-in to expose their components' filenames in production builds.
Expand Down