You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,17 @@
2
2
3
3
All notable changes to this project will be documented in this file.
4
4
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
+
5
16
## 4.0.9 - 2024.03.02
6
17
### Added
7
18
* Add documentation for Craft Cloud usage with Vite ([#83](https://github.com/nystudio107/craft-vite/pull/83))
Copy file name to clipboardExpand all lines: docs/docs/index.md
+33-12Lines changed: 33 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,7 +32,7 @@ To install the plugin, follow these instructions.
32
32
33
33
3. In the Control Panel, go to Settings → Plugins and click the “Install” button for Vite.
34
34
35
-
4. Install Vite. Vite's *[Getting Started Guide](https://vitejs.dev/guide/)* provides various installation options.
35
+
4. Install Vite. Vite’s *[Getting Started Guide](https://vitejs.dev/guide/)* provides various installation options.
36
36
37
37
## Vite Overview
38
38
@@ -114,6 +114,7 @@ These are completely optional settings that you probably won’t need to change:
114
114
***`includeModulePreloadShim`** - whether or not
115
115
the [shim for `modulepreload-polyfill`](https://vitejs.dev/guide/features.html#preload-directives-generation) should
116
116
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))
117
118
118
119
If you’re using the [rollup-plugin-critical](https://github.com/nystudio107/rollup-plugin-critical) to
119
120
generate [critical CSS](https://nystudio107.com/blog/implementing-critical-css), use these settings:
@@ -130,9 +131,9 @@ hosted on a CDN or such.
130
131
131
132
### Vite 5.0 or later
132
133
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, 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
135
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:
136
137
137
138
* 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`)
138
139
* 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
232
233
233
234
Your entry scripts are what you list in the `build.rollupOptions.input` section of the config.
234
235
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:
236
237
237
238
```js
238
239
// Accept HMR as per: https://vitejs.dev/guide/api-hmr.html
@@ -243,9 +244,9 @@ if (import.meta.hot) {
243
244
}
244
245
```
245
246
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 don’t do the above, you’ll get a full page reload whenever you modify one of your entry scripts.
247
248
248
-
Anything your scripts import will be automatically HMR'd by the dev server.
249
+
Anything your scripts import will be automatically HMR’d by the dev server.
249
250
250
251
#### Live Reload of Twig Config
251
252
@@ -410,7 +411,7 @@ web_environment:
410
411
411
412
Then be sure to set `criticalUrl` to `http://localhost` as part of your rollup configuration.
412
413
413
-
Finally note that as ofDDEV1.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 ofDDEV1.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
414
415
415
416
### Vite-Processed Assets
416
417
@@ -505,7 +506,7 @@ Vite automatically supports the direct linking to TypeScript (as in the above ex
505
506
files formats via plugins. You just link directly to them, that’s it.
506
507
507
508
::: 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, you’ll want to change that to avoid Flash Of Unstyled Content (FOUC) by setting the setting the second argument to `false`:
509
510
```twig
510
511
{{ craft.vite.script("src/js/app.ts", false) }}
511
512
```
@@ -565,7 +566,7 @@ resource must match.
565
566
566
567
**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.
567
568
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 don’t use SRI.
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:
@@ -758,6 +759,26 @@ This assumes your `vite.config.js` looks something like this:
758
759
},
759
760
```
760
761
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:
0 commit comments