好吧,我将发布我想出的东西,它并不漂亮,但它似乎适用于 CSS 资产。
首先,我在远程模块的 build: angular.json 中将它们分开:
"styles": [
"projects/xxx-admin/src/styles/styles.scss",
"projects/xxx-admin/src/styles/admin.scss",
{
"input": "projects/xxx-admin/src/styles/admin.scss",
"bundleName": "admin_module_styles",
"inject": false
}
],
这会生成一个带有明确非自动生成名称的 CSS。然后我们从应用程序的路由中加载联合模块:
{
path: "admin",
component: AdminPanelComponent,
canActivate: [XxxAdminGuard],
loadChildren: () => {
const baseUrl = getAdminFrontendBaseUrl();
return loadAdminStyles().then(
() => loadRemoteModule({
remoteName: "xxx_admin",
remoteEntry: `${baseUrl}/remoteEntry.js`,
exposedModule: "AdminModule",
}).then((m) => m.AdminModule));
},
},
...
export function loadAdminStyles(): Promise<void> {
return new Promise((resolve => {
const baseUrl = getAdminFrontendBaseUrl();
const el = document.getElementById("admin-module-styles");
// Load one instance, do it like this to handle errors and retrying
if (el) {
el.remove();
}
const headEl = document.getElementsByTagName("head")[0];
const styleLinkEl = document.createElement("link");
styleLinkEl.rel = "stylesheet";
styleLinkEl.id = "admin-module-styles";
styleLinkEl.href = `${baseUrl}/admin_module_styles.css`;
headEl.appendChild(styleLinkEl);
resolve();
}));
}
这是次优的,但我想不出更好的办法。