簡體   English   中英

如何使用 Angular 8 和 single-spa 來更新 publicPath 以加載很棒的字體?

[英]How do I get the publicPath to update using Angular 8 with single-spa to load font awesome?

我正在嘗試使用 Angular 更新webpack_public_path 我正在使用 single-spa 庫,但在加載 font-awesome 字體時遇到了問題。

它在我們服務器的根目錄 ('/') 中尋找它們,但它們實際上位於應用程序文件夾 ('/app1') 中。

我已經創建了一個文件 set-public-path.ts 並將它導入到 main.single-spa.ts 中。

設置公共路徑.ts

// @ts-ignore
__webpack_public_path__ = 'https://appURL.net/app1/'

main.single-spa.ts

import './set-public-path.ts'
import { enableProdMode, NgZone } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { ɵAnimationEngine as AnimationEngine } from '@angular/animations/browser'; 
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
import singleSpaAngular from 'single-spa-angular';
import { singleSpaPropsSubject } from './single-spa/single-spa-props';

if (environment.production) {
  enableProdMode();
}

// @ts-ignore
console.log(__webpack_public_path__);

const domElementGetter = () => document.getElementById('application');

const lifecycles = singleSpaAngular({
  bootstrapFunction: singleSpaProps => {
    singleSpaPropsSubject.next(singleSpaProps);
    return platformBrowserDynamic().bootstrapModule(AppModule);
  },
  template: '<app1-root />',
  domElementGetter,
  NgZone,
AnimationEngine,
});


export const bootstrap = lifecycles.bootstrap;
export const mount = lifecycles.mount;
export const unmount = lifecycles.unmount;

當應用程序運行時,它會記錄正確的 URL,但 404 錯誤仍然表示它正在查找根目錄。 我不確定我做錯了什么。 我正在使用 SystemJS 導入 index.html 文件中的應用程序。

環境信息:

"@angular-builders/custom-webpack": "^8",
"@angular/animations": "~8.2.11",
"@angular/cdk": "~8.2.3",
"@angular/common": "~8.2.11",
"@angular/compiler": "~8.2.11",
"@angular/core": "^8.2.14",
"@angular/forms": "~8.2.11",
"@angular/material": "^8.2.3",
"@angular/platform-browser": "~8.2.11",
"@angular/platform-browser-dynamic": "~8.2.11",
"@angular/router": "~8.2.11",
"@azure/msal-angular": "^0.1.4",
"@microsoft/applicationinsights-web": "^2.0.0",
"@okta/okta-angular": "^1.3.1",
"@types/jest": "^24.0.24",
"hammerjs": "^2.0.8",
"node-sass": "^4.13.1",
"rxjs": "~6.4.0",
"rxjs-compat": "^6.5.3",
"single-spa-angular": "^3.0.1",
"tslib": "^1.10.0",
"zone.js": "~0.9.1"

這對我有用;

設置公共路徑.js

export default function setPublicPath() {
    return Promise.all([getUrl()]).then(values => {
        const [url] =values;
        __webpack_public_path__ = url;
        return true;
    });
}

function getUrl() {
     return window.System.resolve('app8');
}

main.single-spa.ts

import setPublicPath from './set-public-path.js';
setPublicPath();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM