Closed daniloesk closed 3 years ago
Maybe a workaround using SCSS and Angular Style preprocessor options?
After taking a deeper look into Angular's webpack configuration I realized I misunderstood how Angular handles styles. Actually the root style.css is not processed by the webpack rules, unlike component styles. Moving the URL into a component style and using deployUrl
had the static publicPath set on the build and serve contents.
Here is an updated demo on the change: https://github.com/daniloesk/single-spa-errors/tree/single-spa-angular%23317-closed (the printed webpack config is what gave me the insight)
Having a runtime publicPath evaluated from the actual hosting URL would be better, but this already makes it work.
Still not using interop of any other special publicPath configuration unlike stated in the documentation. It is very possible I am missing something here, in which case I would be very glad to have some directions. Otherwise updating the doc would be a good idea.
Forgot to make it clear:
rebaseRootRelativeCssUrls
to have them take publicPath.rebaseRootRelativeCssUrls
no longer works, so you need to move URLs into component styles.Hi @daniloesk, thanks for the details here. Ideally we'd get Angular CLI to allow us to set the webpack public path dynamically in the browser - this is how things work in the single-spa ecosystem for react, vue, etc. The reason that --deploy-url
and rebaseRootRelativeCssUrls
have been encouraged with single-spa-angular is only because Angular CLI's webpack config is rigidly opinionated about having a build-time public path and I wasn't able to get it to respect a runtime public path.
The best solution here in my opinion would be to investigate if we can get Angular CLI to compile asset urls to something like __webpack_public_path__ + '/assets/img.png'
.
Updated the https://github.com/daniloesk/single-spa-errors/tree/single-spa-angular%23317-closed tag. No idea why it was pointing to master...
Tried to inject some options in the rules using extra-webpack.config.js
with no luck. Below are the rules after singleSpaAngularWebpack
(used inspect). I am guessing they already include Angular rules.
I guess that for now we can work with that. =) Here is an example for working asset URLs: https://github.com/daniloesk/single-spa-examples/releases/tag/v20201211-app11
The rewrite solution for asset URL in style files documented in https://single-spa.js.org/docs/ecosystem-angular/#styles using
rebaseRootRelativeCssUrls
no longer works in Angular 11 since that configuration was removed.deployUrl
is also deprecated forng serve
and may be removed in the future.It looks like such solution was actually based on
rebaseRootRelativeCssUrls
anddeployUrl
, not on public path. I built an Angular 10 demo with assert URL rewriting without setting the public path (https://github.com/daniloesk/single-spa-errors/tree/css-asset-ng10). This one works.Also built a similiar demo for Angular 11, with only the style with asset URL, since
rebaseRootRelativeCssUrls
is no longer around: https://github.com/daniloesk/single-spa-errors/tree/single-spa-angular%23317. This is the one that doesn't work.Demonstration
npm install
npm run serve:prod
Expected Behavior
loader.gif
is loaded from http://localhost:11200 and displayed.Actual Behavior
loader.gif
is loaded from http://single-spa-playground.org and not found.