-
Notifications
You must be signed in to change notification settings - Fork 2
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
Basic Vite setup #4
Conversation
6789ba8
to
e968831
Compare
$host = Craft::$app->getRequest()->getIsConsoleRequest() | ||
? App::env('PRIMARY_SITE_URL') | ||
: Craft::$app->getRequest()->getHostInfo(); | ||
$httpPort = 3000; | ||
$httpsPort = 3001; | ||
$devServerPort = str_starts_with($host, 'https') ? $httpsPort : $httpPort; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a while I was having difficulty getting https
working with DDEV (I've got it working great now).
Figured it wasn't too much extra code to accommodate other's who might hit that issue.
font-family: 'Source Sans Pro'; | ||
font-style: normal; | ||
font-weight: 300; | ||
src: url('../fonts/sourcesanspro-light-webfont.woff2') format('woff2'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Vite can automatically copy & hash filenames for fonts. It just has to be a relative path from the css file to the font file.
<link rel="preload" href="{{ craft.vite.asset("src/fonts/sourcesanspro-bold-webfont.woff2") }}" as="font" type="font/woff2" crossorigin> | ||
<link rel="preload" href="{{ craft.vite.asset("src/fonts/sourcesanspro-light-webfont.woff2") }}" as="font" type="font/woff2" crossorigin> | ||
<link rel="preload" href="{{ craft.vite.asset("src/fonts/sourcesanspro-regular-webfont.woff2") }}" as="font" type="font/woff2" crossorigin> | ||
<link rel="preload" href="{{ craft.vite.asset("src/fonts/sourcesanspro-semibold-webfont.woff2") }}" as="font" type="font/woff2" crossorigin> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figured this would be a nice example/reminder to preload your fonts.
host: '0.0.0.0', | ||
strictPort: true, | ||
port: HTTP_PORT, | ||
origin: env.PRIMARY_SITE_URL + ':' + originPort, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is also needed to get webfonts, images, etc to work properly in dev mode.
You have to tell Vite the precise URL to use for any files referenced in your CSS & JS files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Overview
What this PR does.
What this PR (intentionally) doesn't do
How to test
Create a directory for your new Craft project
Run the following
composer create-project
command.It uses this branch as the starter project.
After completing the setup steps (it prompts for your project's name), run the following commands.
👇 These will gradually become more automated as this project progresses.
What you should see:
ℹ️ You may need a
ddev restart
to get rid of 404s around webfonts. The Vite config is looking for thePRIMARY_SITE_URL
environment variable. It might not be fully loaded by DDEV.