You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a somewhat esoteric case where we use styled-jsx inside a Cordova app (via a WKWebView. Cordova apps load their index page from a local file, so window.location points to some file URL like file:///Applications/....
While CSS loaded via link is fine, the file:// URL has the side effect that relative URLs used in styled-jsx code won't work:
...where Config.assetBase is a per-environment configuration. We can't define this string as a SASS variable globally because it's dependent on the current page. (We create a single Docker image for all environments.)
The above would be fine if all our code used styled-jsx, but we also have a ton of shared .scss files we import that contain mixins and stuff that need to be augmented this way. We could define base for all the imports:
<stylejsx>{` $base: ${Config.assetBase}`;
@import"stuff";// This now has access to $base.thing{background: url(${base}/thing.png);}`}</style>
This works. This doesn't work because styled-jsx doesn't support string interpolation. Unfortunately, this means every styled-jsx component needs to define this variable.
Is there a way to inject SASS variables dynamically and not at transpilation time? We can't do it during Babel transpilation because it's already too late — the base URL is effectively per-request, not a compile-time setting. Or is there a way to post-process the generated CSS so we can change relative URLs to be absolute?
Any ideas?
The text was updated successfully, but these errors were encountered:
We have a somewhat esoteric case where we use styled-jsx inside a Cordova app (via a
WKWebView
. Cordova apps load their index page from a local file, sowindow.location
points to some file URL likefile:///Applications/...
.While CSS loaded via
link
is fine, thefile://
URL has the side effect that relative URLs used in styled-jsx code won't work:We somehow have to change this to be an absolute URL:
...where
Config.assetBase
is a per-environment configuration. We can't define this string as a SASS variable globally because it's dependent on the current page. (We create a single Docker image for all environments.)The above would be fine if all our code used styled-jsx, but we also have a ton of shared
.scss
files we import that contain mixins and stuff that need to be augmented this way. We could definebase
for all the imports:This works. This doesn't work because styled-jsx doesn't support string interpolation. Unfortunately, this means every styled-jsx component needs to define this variable.Is there a way to inject SASS variables dynamically and not at transpilation time? We can't do it during Babel transpilation because it's already too late — the base URL is effectively per-request, not a compile-time setting. Or is there a way to post-process the generated CSS so we can change relative URLs to be absolute?
Any ideas?
The text was updated successfully, but these errors were encountered: