-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to Vite #319
Switch to Vite #319
Conversation
@crgwbr : I solved this on joyapp.com by switching the subdomain for static assets. A wildcard subdomain has the release hash in it. I've always hated all these mechanisms, but understand you need one. I'll think of something, maybe give you an env var. But I'm curious how you solved it with the prior system / white noise. Can you post the relevant pseudo code or Python/React areas on esbuild reactivated? Note: you can already just change For the record, my least favorite part of this conversion is having to detect and inject assets separately between development and production. I like things being explicit. But Vite's ESM module handling requires it. |
class CoreAssets(NamedTuple):
favicon: str
css: List[str]
js: List[str]
class CoreAssetProcessor(NamedTuple):
core_assets: CoreAssets
def core_assets(request: HttpRequest) -> CoreAssetProcessor:
"""
Add static-related context variables to the context.
"""
return {
"core_assets": {
"favicon": static("favicon.ico"),
"css": [
static("dist/index.css"),
],
"js": [
static("dist/index.js"),
static("js/footer.js"),
],
}
} export const PageSkeleton = (props: {
children?: React.ReactNode;
}) => {
const context = React.useContext(Context);
return (
<>
<Helmet>
<link
rel="icon"
sizes="16x16 32x32 64x64"
href={context.core_assets.favicon}
type="image/x-icon"
/>
{context.core_assets.css.map((file) => (
<link
key={file}
rel="stylesheet"
type="text/css"
href={file}
/>
))}
{context.core_assets.js.map((file) => (
<script
key={file}
defer
crossOrigin="anonymous"
src={file}
/>
))}
</Helmet>
{props.children}
</>
);
}; |
@crgwbr that helps. So if you're doing this in the build process, and presumably you know your release version (say the commit hash), what's stopping you from Then on your docker file (pseudocode):
I could add an ENV variable of some sort, but you'll still need to inject it in docker so your build process changes too. |
Ok, I can make something like that work. 👍 |
I think this is my last pending issue here. Manually setting |
What's the need or use case though? I'm using it only in development in During production, vite doesn't serve anything at all, only |
Vite always needs to know the static URL so that it knows how to link to it's own assets. Like in my example here: #319 (comment) A CSS file includes a reference another file (like a font or image): @font-face {
font-family: NunitoSans-Regular;
src: url("../../../static/fonts/NunitoSans-Regular.woff2")
} During the build process, Vite traverses that path to find the file, and saves is in the dist folder. So now you have: static/
- dist/
- index.js
- index.css
- NunitoSans-Regular.woff2 But currently, @font-face {
font-family: NunitoSans-Regular;
src: url("NunitoSans-Regular.woff2")
} IOW, during build Vite doesn't know it's URL prefix. By setting @font-face {
font-family: NunitoSans-Regular;
src: url("/static/dist/NunitoSans-Regular.woff2")
} |
That helps. Never ran into this because I don't include anything like fonts in the bundle. I just include them directly as a style tag and point to the static URL. Will investigate, at worst you can just create a custom vite config file. Which is actually a feature: overriding is now as simple as creating a vite config that is automatically picked up and merged. Will even include additional plugins, etc. |
@crgwbr : I think I see the issue. Vite knows about it during development, but not at build time. Can you confirm the issue happens with
|
Yes, that’s exactly correct.
…On Fri, Feb 16, 2024 at 10:51 PM Silvio ***@***.***> wrote:
@crgwbr <https://github.com/crgwbr> : I think I see the issue. Vite knows
about it during development, but not at build time. Can you confirm the
issue happens with build.py and not runserver?
vite.mts is only used during development not at build time (
build.client.mts is used for that)
—
Reply to this email directly, view it on GitHub
<#319 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AABKJIDAFXKTOAX6QA4K5ZDYUASN7AVCNFSM6AAAAABCXLCYPSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBZGYZTEOBVG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
No description provided.