Skip to content

Commit de42712

Browse files
committed
Merge branch 'release/4.0.9' into v4
2 parents f652387 + 95f356d commit de42712

File tree

9 files changed

+529
-357
lines changed

9 files changed

+529
-357
lines changed

.craftplugin

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/workflows/code-analysis.yaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,20 @@ jobs:
2323
name: ${{ matrix.actions.name }}
2424
runs-on: ubuntu-latest
2525
steps:
26-
- uses: actions/checkout@v4
27-
# see https://github.com/shivammathur/setup-php
28-
- uses: shivammathur/setup-php@v2
29-
with:
30-
php-version: 8.0
31-
coverage: none
32-
# composer install cache - https://github.com/ramsey/composer-install
33-
- uses: "ramsey/composer-install@v2"
34-
- run: ${{ matrix.actions.run }}
26+
- uses: actions/checkout@v4
27+
- name: Cache Composer dependencies
28+
uses: actions/cache@v4
29+
with:
30+
path: /tmp/composer-cache
31+
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
32+
- name: Setup PHP
33+
id: setup-php
34+
uses: shivammathur/setup-php@v2
35+
with:
36+
php-version: 8.2
37+
extensions: 'ctype,curl,dom,iconv,imagick,intl,json,mbstring,openssl,pcre,pdo,reflection,spl,zip'
38+
ini-values: post_max_size=256M, max_execution_time=180, memory_limit=512M
39+
tools: composer:v2
40+
- name: Install Composer dependencies
41+
run: composer install --no-interaction --no-ansi --no-progress
42+
- run: ${{ matrix.actions.run }}

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## 4.0.9 - 2024.03.02
6+
### Added
7+
* Add documentation for Craft Cloud usage with Vite ([#83](https://github.com/nystudio107/craft-vite/pull/83))
8+
* Add support for clearing Vite caches in response to Craft Cloud's `UpController::EVENT_AFTER_UP` event ([#83](https://github.com/nystudio107/craft-vite/pull/83))
9+
10+
### Fixed
11+
* Fixed an issue where the wrong CSS hash would be returned if you were using Vite 3 or earlier ([#80](https://github.com/nystudio107/craft-vite/issues/80))
12+
* Fixed an issue where `craft.vite.entry()` would fail if you were using Vite 5 or later, due to the `ManifestHelper::fileNameWithoutHash()` function not working correctly ([#24](https://github.com/nystudio107/craft-plugin-vite/issues/24))
13+
514
## 4.0.8 - 2024.01.30
615
### Added
716
* If the `devServer` is running, the `ViteService::fetch()` method will try to use the `devServerInternal` URL first, falling back on the `devServerPublic` so that `craft.vite.inline()` can pull from the `devServer` if it is running ([#22](https://github.com/nystudio107/craft-plugin-vite/issues/22))

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "nystudio107/craft-vite",
33
"description": "Allows the use of the Vite.js next generation frontend tooling with Craft CMS",
44
"type": "craft-plugin",
5-
"version": "4.0.8",
5+
"version": "4.0.9",
66
"keywords": [
77
"craft",
88
"cms",
@@ -24,15 +24,16 @@
2424
],
2525
"require": {
2626
"craftcms/cms": "^4.0.0",
27-
"nystudio107/craft-plugin-vite": "^4.0.9"
27+
"nystudio107/craft-plugin-vite": "^4.0.10"
2828
},
2929
"require-dev": {
30+
"craftcms/cloud": "^1.41.0",
3031
"craftcms/ecs": "dev-main",
3132
"craftcms/phpstan": "dev-main",
3233
"craftcms/rector": "dev-main"
3334
},
3435
"scripts": {
35-
"phpstan": "vendor/bin/phpstan --ansi --memory-limit=1G",
36+
"phpstan": "phpstan --ansi --memory-limit=1G",
3637
"check-cs": "ecs check --ansi",
3738
"fix-cs": "ecs check --fix --ansi"
3839
},

docs/docs/index.md

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ services:
359359
expose:
360360
- '3000'
361361
environment:
362-
- HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILHOG_PORT}:8025,3001:3000
363-
- HTTPS_EXPOSE=${DDEV_ROUTER_HTTPS_PORT}:80,${DDEV_MAILHOG_HTTPS_PORT}:8025,3000:3000
362+
- HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILPIT_PORT}:8025,3001:3000
363+
- HTTPS_EXPOSE=${DDEV_ROUTER_HTTPS_PORT}:80,${DDEV_MAILPIT_HTTPS_PORT}:8025,3000:3000
364364
```
365365
366366
In your `vite.config.js`, the `server.host` should to be set to `0.0.0.0`, and `server.port` set to `3000`:
@@ -501,8 +501,16 @@ JavaScript file via Twig in a `<script>` tag, you instead do:
501501
{{ craft.vite.script("src/js/app.ts") }}
502502
```
503503
504-
Note that Vite automatically also supports the direct linking to TypeScript (as in the above example), JSX, and other
505-
files via plugins. You just link directly to them, that’s it.
504+
Vite automatically supports the direct linking to TypeScript (as in the above example), JavaScript, JSX, and other
505+
files formats via plugins. You just link directly to them, that’s it.
506+
507+
::: tip CSS is Asynchronous by default
508+
By default, the Vite plugin will load your [CSS asynchronously](https://www.filamentgroup.com/lab/load-css-simpler/). If you are **not** using Critical CSS, you'll want to change that to avoid Flash Of Unstyled Content (FOUC) by setting the setting the second argument to `false`:
509+
```twig
510+
{{ craft.vite.script("src/js/app.ts", false) }}
511+
```
512+
See the **[Other Options](#other-options)** section below for details
513+
:::
506514
507515
##### Development
508516
@@ -586,16 +594,7 @@ import '/src/css/app.pcss';
586594
The Vite plugin will take care of automatically generating the `<link rel="stylesheet">` tag for you in production.
587595
588596
By default, it loads the [CSS asynchronously](https://www.filamentgroup.com/lab/load-css-simpler/), but you can
589-
configure this. See the **Other Options** section.
590-
591-
#### Polyfills
592-
593-
To work properly, you must also import the [Vite Polyfill](https://vitejs.dev/config/#build-polyfilldynamicimport) in
594-
your `build.input` JavaScript file entries listed in the `vite.config.js`, for example:
595-
596-
```js
597-
import "vite/dynamic-import-polyfill";
598-
```
597+
configure this. See the **[Other Options](#other-options)** section.
599598
600599
#### Legacy
601600
@@ -911,6 +910,53 @@ So for example:
911910
) }}
912911
```
913912
913+
## Craft Cloud
914+
915+
During a [build](https://craftcms.com/knowledge-base/cloud-builds), Craft Cloud deploys static assets to a CDN, so you’ll need to configure the plugin to use the appropriate URLs:
916+
917+
```php
918+
<?php
919+
// config/vite.php
920+
921+
use craft\cloud\Helper as CloudHelper;
922+
923+
return [
924+
'manifestPath' => CloudHelper::artifactUrl('dist/.vite/manifest.json'),
925+
'serverPublic' => CloudHelper::artifactUrl('dist/'),
926+
];
927+
```
928+
929+
This helper function returns a CDN URL that includes your project and environment identifiers, like this:
930+
931+
```
932+
https://cdn.craft.com/{project-uuid}/builds/{environment-uuid}/artifacts/dist/
933+
```
934+
935+
Outside of Cloud, this behaves as though it were prepended with `@web`.
936+
937+
If you’d prefer to use an on-disk `manifestPath` when working locally (instead of a URL), the `CloudHelper::isCraftCloud()` function lets you switch based on the environment:
938+
939+
```php
940+
<?php
941+
// config/vite.php
942+
943+
use craft\cloud\Helper as CloudHelper;
944+
945+
return [
946+
'manifestPath' => CloudHelper::isCraftCloud() ? CloudHelper::artifactUrl('dist/.vite/manifest.json') : '@webroot/dist/.vite/manifest.json',
947+
'serverPublic' => CloudHelper::artifactUrl('dist/'),
948+
];
949+
```
950+
951+
Additionally, your Vite config should have [public `base`](https://vitejs.dev/guide/build.html#public-base-path) set to use the same CDN URL. In Craft Cloud’s build pipeline, this is exposed as an [`CRAFT_CLOUD_ARTIFACT_BASE_URL` environment variable](https://craftcms.com/knowledge-base/cloud-builds#build-command):
952+
953+
```javascript
954+
// vite.config.js
955+
export default ({ command }) => ({
956+
base: command === 'serve' ? '' : `${process.env.CRAFT_CLOUD_ARTIFACT_BASE_URL || ''}/dist/`,
957+
})
958+
```
959+
914960
## Vite Roadmap
915961
916962
Some things to do, and ideas for potential features:

0 commit comments

Comments
 (0)