Skip to content

Commit a9069ab

Browse files
committed
Merge branch 'release/4.0.10' into v4
2 parents de42712 + 76048ee commit a9069ab

File tree

9 files changed

+2138
-638
lines changed

9 files changed

+2138
-638
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+
## 4.0.10 - 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
## 4.0.9 - 2024.03.02
617
### Added
718
* Add documentation for Craft Cloud usage with Vite ([#83](https://github.com/nystudio107/craft-vite/pull/83))

Makefile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
MAJOR_VERSION?=4
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": "4.0.9",
5+
"version": "4.0.10",
66
"keywords": [
77
"craft",
88
"cms",
@@ -24,7 +24,7 @@
2424
],
2525
"require": {
2626
"craftcms/cms": "^4.0.0",
27-
"nystudio107/craft-plugin-vite": "^4.0.10"
27+
"nystudio107/craft-plugin-vite": "^4.0.12"
2828
},
2929
"require-dev": {
3030
"craftcms/cloud": "^1.41.0",

docs/docs/.vitepress/config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ export default defineConfig({
2424
algolia: {
2525
appId: 'AE3HRUJFEW',
2626
apiKey: 'c5dcc2be096fff3a4714c3a877a056fa',
27-
indexName: 'vite'
27+
indexName: 'vite',
28+
searchParameters: {
29+
facetFilters: ["version:v4"],
30+
},
2831
},
2932
lastUpdatedText: 'Last Updated',
3033
sidebar: [],

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'`
@@ -232,7 +233,7 @@ the [module/nomodule](https://philipwalton.com/articles/deploying-es2015-code-in
232233

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

235-
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:
236+
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:
236237

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

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

413-
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
414+
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
414415

415416
### Vite-Processed Assets
416417

@@ -505,7 +506,7 @@ Vite automatically supports the direct linking to TypeScript (as in the above ex
505506
files formats via plugins. You just link directly to them, that’s it.
506507
507508
::: 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+
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`:
509510
```twig
510511
{{ craft.vite.script("src/js/app.ts", false) }}
511512
```
@@ -565,7 +566,7 @@ resource must match.
565566
566567
**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.
567568
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 don't use SRI.
569+
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.
569570
570571
##### Script `onload` events
571572
@@ -726,7 +727,7 @@ export default ({command}) => ({
726727
});
727728
```
728729
729-
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:
730+
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:
730731
731732
```twig
732733
{{ craft.vite.asset("src/images/quote-open.svg", true) }}
@@ -758,6 +759,26 @@ This assumes your `vite.config.js` looks something like this:
758759
},
759760
```
760761
762+
### The `.integrity()` function
763+
764+
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).
765+
766+
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..
767+
768+
You pass in a relative path to the entry, just as you do for JavaScript files in Vite. For example:
769+
770+
```twig
771+
{{ craft.vite.integrity("src/js/app.ts") }}
772+
```
773+
774+
This will return the integrity hash from the manifest:
775+
776+
```
777+
sha384-OFM4tseEj4P0uGf60m1BYV0vqDU2Ljj2ugL5zZBvHlsEpYIoEbTPfQuRsz9lgr75
778+
```
779+
780+
If there is no `integrity` hash, or the manifest entry is not found, it will return an empty string.
781+
761782
### The `.inline()` function
762783
763784
The Vite plugin also includes a `.inline()` function that inlines the contents of a local file (via path) or remote
@@ -826,13 +847,13 @@ If `null` is passed in as the first parameter, it’ll use the automatic templat
826847
827848
### The `.getCssInlineTags()` function
828849
829-
If you want to inline an existing CSS file by URL or path, you do it by path:
850+
To inline an existing CSS file by URL or path, you do it by path:
830851
831852
```twig
832853
{{ craft.vite.getCssInlineTags("@webroot/path/to/css/file.css") }}
833854
```
834855
835-
or by URL (but keep in mind, this will generate an additional blocking XHR):
856+
Or by URL (but keep in mind, this will generate an additional blocking XHR):
836857
837858
```twig
838859
{{ craft.vite.getCssInlineTags("@web/path/to/css/file.css") }}

0 commit comments

Comments
 (0)