Skip to content

Commit

Permalink
fix(css-file-paths-formatting): ensure CSS paths include hostname for…
Browse files Browse the repository at this point in the history
… remote module styles (#667)
  • Loading branch information
viguenstepanyan authored Jan 18, 2025
1 parent 8df65ef commit e39a86f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@originjs/vite-plugin-federation",
"version": "1.3.8",
"version": "1.3.9",
"description": "A Vite plugin which support Module Federation.",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand Down
26 changes: 20 additions & 6 deletions packages/lib/src/prod/expose-production.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,26 @@ export function prodExposePlugin(
const assetsDir = __VITE_ASSETS_DIR_PLACEHOLDER__;
cssFilePaths.forEach(cssPath => {
let href = ''
const baseUrl = base || curUrl
if (baseUrl && baseUrl !== '/') {
href = [baseUrl, assetsDir, cssPath].filter(Boolean).map(part => part.endsWith('/') ? part.substring(0, part.length - 1) : part).join('/')
let href = '';
const baseUrl = base || curUrl;
if (baseUrl) {
const trimmer = {
trailing: (path) => (path.endsWith('/') ? path.slice(0, -1) : path),
leading: (path) => (path.startsWith('/') ? path.slice(1) : path)
}
const isAbsoluteUrl = (url) => url.startsWith('http') || url.startsWith('//');
const cleanBaseUrl = trimmer.trailing(baseUrl);
const cleanCssPath = trimmer.leading(cssPath);
const cleanCurUrl = trimmer.trailing(curUrl);
if (isAbsoluteUrl(baseUrl)) {
href = [cleanBaseUrl, cleanCssPath].filter(Boolean).join('/');
} else {
href = [cleanCurUrl + cleanBaseUrl, cleanCssPath].filter(Boolean).join('/');
}
} else {
href = curUrl + cssPath
href = cssPath;
}
if (href in seen) return;
Expand Down Expand Up @@ -180,7 +194,7 @@ export function prodExposePlugin(
.replace(
'__VITE_ASSETS_DIR_PLACEHOLDER__',
`'${viteConfigResolved.config?.build?.assetsDir || ''}'`
);
)

const filepathMap = new Map()
const getFilename = (name) => parse(parse(name).name).name
Expand Down

0 comments on commit e39a86f

Please sign in to comment.