Skip to content

Commit a2eaa9b

Browse files
committed
Merge branch 'release/5.0.1' into v5
2 parents 054c61b + d953d6c commit a2eaa9b

File tree

7 files changed

+1243
-630
lines changed

7 files changed

+1243
-630
lines changed

CHANGELOG.md

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

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

5+
## 5.0.1 - 2024.08.13
6+
### Added
7+
* Added a `craft.vite.integrity()` method that will extract the integrity hash (for building a Content Security Policy)
8+
* Added an `includeScriptOnloadHandler` config setting that allows you to disable the adding of an `onload` handler on the `<script>` tags (useful when implementing a Content Security Policy)
9+
10+
### Changed
11+
* Filter out empty attributes so they don't render on the `<script>` tags
12+
13+
### Fixed
14+
* Use `strrpos` instead of `strpos` when attempting to extract a file name without the hash ([#28](https://github.com/nystudio107/craft-plugin-vite/pull/28))
15+
516
## 5.0.0 - 2024.04.16
617
### Added
718
* Stable release for Craft CMS 5

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
MAJOR_VERSION?=5
2+
PLUGINDEV_PROJECT_DIR?=/Users/andrew/webdev/sites/plugindev/cms_v${MAJOR_VERSION}/
3+
VENDOR?=nystudio107
4+
PROJECT_PATH?=${VENDOR}/$(shell basename $(CURDIR))
5+
6+
.PHONY: dev release
7+
8+
# Start up the buildchain dev server
9+
dev:
10+
# Start up the docs dev server
11+
docs:
12+
${MAKE} -C docs/ dev
13+
# Run code quality tools, tests, and build the buildchain & docs in preparation for a release
14+
release: --code-quality --code-tests --buildchain-clean-build --docs-clean-build
15+
# The internal targets used by the dev & release targets
16+
--buildchain-clean-build:
17+
--code-quality:
18+
${MAKE} -C ${PLUGINDEV_PROJECT_DIR} -- ecs check vendor/${PROJECT_PATH}/src --fix
19+
${MAKE} -C ${PLUGINDEV_PROJECT_DIR} -- phpstan analyze -c vendor/${PROJECT_PATH}/phpstan.neon
20+
--code-tests:
21+
--docs-clean-build:
22+
${MAKE} -C docs/ clean
23+
${MAKE} -C docs/ image-build
24+
${MAKE} -C docs/ fix

composer.json

Lines changed: 2 additions & 2 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": "5.0.0",
5+
"version": "5.0.1",
66
"keywords": [
77
"craft",
88
"cms",
@@ -25,7 +25,7 @@
2525
"require": {
2626
"php": "^8.2",
2727
"craftcms/cms": "^5.0.0",
28-
"nystudio107/craft-plugin-vite": "^5.0.0"
28+
"nystudio107/craft-plugin-vite": "^5.0.2"
2929
},
3030
"require-dev": {
3131
"craftcms/cloud": "^2.0.0",

docs/docs/index.md

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ To install the plugin, follow these instructions.
3232

3333
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Vite.
3434

35-
4. Install Vite. Vite's *[Getting Started Guide](https://vitejs.dev/guide/)* provides various installation options.
35+
4. Install Vite. Vites *[Getting Started Guide](https://vitejs.dev/guide/)* provides various installation options.
3636

3737
## Vite Overview
3838

@@ -114,6 +114,7 @@ These are completely optional settings that you probably won’t need to change:
114114
* **`includeModulePreloadShim`** - whether or not
115115
the [shim for `modulepreload-polyfill`](https://vitejs.dev/guide/features.html#preload-directives-generation) should
116116
be included to polyfill `<link rel="modulepreload">`
117+
* **`includeScriptOnloadHandler`** - allows you to disable the adding of an `onload` handler on the `<script>` tags (useful when implementing a [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP))
117118

118119
If you’re using the [rollup-plugin-critical](https://github.com/nystudio107/rollup-plugin-critical) to
119120
generate [critical CSS](https://nystudio107.com/blog/implementing-critical-css), use these settings:
@@ -130,9 +131,9 @@ hosted on a CDN or such.
130131

131132
### Vite 5.0 or later
132133

133-
As of Vite 5.0 or later, there's been a [change to where the `manifest.json`](https://vitejs.dev/guide/migration#manifest-files-are-now-generated-in-vite-directory-by-default) is generated by default.
134+
As of Vite 5.0 or later, theres been a [change to where the `manifest.json`](https://vitejs.dev/guide/migration#manifest-files-are-now-generated-in-vite-directory-by-default) is generated by default.
134135

135-
It is now placed inside a `.vite/` directory by default. You can accomodate this in either of the following ways:
136+
It is now placed inside a `.vite/` directory by default. You can accommodate this in either of the following ways:
136137

137138
* Change the `manifest` setting in your `vite.config.js` file to `manifest.json` (it can not either be a `bool` or a file path `string`)
138139
* Change the `manifestPath` setting in your `config/vite.php` file to `'@webroot/dist/.vite/manifest.json'`
@@ -231,7 +232,7 @@ the [module/nomodule](https://philipwalton.com/articles/deploying-es2015-code-in
231232

232233
Your entry scripts are what you list in the `build.rollupOptions.input` section of the config.
233234

234-
Vite is typically used with frameworks which take care of the HMR via the dev server. However, in order to get your entry scripts to HMR you need to add this snippet to each entry script:
235+
Vite is typically used with frameworks which take care of the HMR via the dev server. However, to get your entry scripts to HMR you need to add this snippet to each entry script:
235236

236237
```js
237238
// Accept HMR as per: https://vitejs.dev/guide/api-hmr.html
@@ -242,9 +243,9 @@ if (import.meta.hot) {
242243
}
243244
```
244245
245-
If you don't do the above, you'll get a full page reload whenever you modify one of your entry scripts.
246+
If you dont do the above, youll get a full page reload whenever you modify one of your entry scripts.
246247
247-
Anything your scripts import will be automatically HMR'd by the dev server.
248+
Anything your scripts import will be automatically HMRd by the dev server.
248249
249250
#### Live Reload of Twig Config
250251
@@ -409,7 +410,7 @@ web_environment:
409410

410411
Then be sure to set `criticalUrl` to `http://localhost` as part of your rollup configuration.
411412

412-
Finally note that as of DDEV 1.19 you are able to specify Node (and Composer) versions directly via `/.ddev/config.yaml`. See more at https://ddev.readthedocs.io/en/stable/users/cli-usage/#nodejs-npm-nvm-and-yarn
413+
Finally note that as of DDEV 1.19 you are able to specify Node.js (and Composer) versions directly via `/.ddev/config.yaml`. See more at https://ddev.readthedocs.io/en/stable/users/cli-usage/#nodejs-npm-nvm-and-yarn
413414

414415
### Vite-Processed Assets
415416

@@ -504,7 +505,7 @@ Vite automatically supports the direct linking to TypeScript (as in the above ex
504505
files formats via plugins. You just link directly to them, that’s it.
505506
506507
::: tip CSS is Asynchronous by default
507-
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`:
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, youll want to change that to avoid Flash Of Unstyled Content (FOUC) by setting the setting the second argument to `false`:
508509
```twig
509510
{{ craft.vite.script("src/js/app.ts", false) }}
510511
```
@@ -564,7 +565,7 @@ resource must match.
564565
565566
**N.B.:** If you use a service such as [CloudFlare](https://www.cloudflare.com/) with **Auto Minify** enabled, this alters the payload that is being delivered dynamically, which will cause the SRI check to fail, and your files will not load.
566567
567-
The same is true for any modifications to the built JavaScript. External changes to the built files is exactly what SRI is designed to thwart. So you will need to either disable any options that dynamically alter your built files, or don't use SRI.
568+
The same is true for any modifications to the built JavaScript. External changes to the built files is exactly what SRI is designed to thwart. So you will need to either disable any options that dynamically alter your built files, or dont use SRI.
568569
569570
##### Script `onload` events
570571
@@ -725,7 +726,7 @@ export default ({command}) => ({
725726
});
726727
```
727728
728-
If you need to access assets that are in the `public/` directory from Twig, there is a second parameter you can pass to `craft.vite.asset` to inidicate that the asset is coming from the `public/` directory:
729+
To access assets that are in the `public/` directory from Twig, there is a second parameter you can pass to `craft.vite.asset` to inidicate that the asset is coming from the `public/` directory:
729730
730731
```twig
731732
{{ craft.vite.asset("src/images/quote-open.svg", true) }}
@@ -757,6 +758,26 @@ This assumes your `vite.config.js` looks something like this:
757758
},
758759
```
759760
761+
### The `.integrity()` function
762+
763+
The Vite plugin includes an `.integrity()` function that will return the `integrity` hash if you’re using the [vite-plugin-manifest-sri](https://www.npmjs.com/package/vite-plugin-manifest-sri) plugin for [sub-resource integrity](https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity).
764+
765+
You may need the hash to build your [Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP), if you're using a [hash with `script-src`](https://content-security-policy.com/hash/) to do so..
766+
767+
You pass in a relative path to the entry, just as you do for JavaScript files in Vite. For example:
768+
769+
```twig
770+
{{ craft.vite.integrity("src/js/app.ts") }}
771+
```
772+
773+
This will return the integrity hash from the manifest:
774+
775+
```
776+
sha384-OFM4tseEj4P0uGf60m1BYV0vqDU2Ljj2ugL5zZBvHlsEpYIoEbTPfQuRsz9lgr75
777+
```
778+
779+
If there is no `integrity` hash, or the manifest entry is not found, it will return an empty string.
780+
760781
### The `.inline()` function
761782
762783
The Vite plugin also includes a `.inline()` function that inlines the contents of a local file (via path) or remote
@@ -825,13 +846,13 @@ If `null` is passed in as the first parameter, it’ll use the automatic templat
825846
826847
### The `.getCssInlineTags()` function
827848
828-
If you want to inline an existing CSS file by URL or path, you do it by path:
849+
To inline an existing CSS file by URL or path, you do it by path:
829850
830851
```twig
831852
{{ craft.vite.getCssInlineTags("@webroot/path/to/css/file.css") }}
832853
```
833854
834-
or by URL (but keep in mind, this will generate an additional blocking XHR):
855+
Or by URL (but keep in mind, this will generate an additional blocking XHR):
835856
836857
```twig
837858
{{ craft.vite.getCssInlineTags("@web/path/to/css/file.css") }}

0 commit comments

Comments
 (0)