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
+
## 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))
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'`
@@ -231,7 +232,7 @@ the [module/nomodule](https://philipwalton.com/articles/deploying-es2015-code-in
231
232
232
233
Your entry scripts are what you list in the `build.rollupOptions.input` section of the config.
233
234
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:
235
236
236
237
```js
237
238
// Accept HMR as per: https://vitejs.dev/guide/api-hmr.html
@@ -242,9 +243,9 @@ if (import.meta.hot) {
242
243
}
243
244
```
244
245
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 don’t do the above, you’ll get a full page reload whenever you modify one of your entry scripts.
246
247
247
-
Anything your scripts import will be automatically HMR'd by the dev server.
248
+
Anything your scripts import will be automatically HMR’d by the dev server.
248
249
249
250
#### Live Reload of Twig Config
250
251
@@ -409,7 +410,7 @@ web_environment:
409
410
410
411
Then be sure to set `criticalUrl` to `http://localhost` as part of your rollup configuration.
411
412
412
-
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
413
+
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
413
414
414
415
### Vite-Processed Assets
415
416
@@ -504,7 +505,7 @@ Vite automatically supports the direct linking to TypeScript (as in the above ex
504
505
files formats via plugins. You just link directly to them, that’s it.
505
506
506
507
::: 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, you’ll want to change that to avoid Flash Of Unstyled Content (FOUC) by setting the setting the second argument to `false`:
508
509
```twig
509
510
{{ craft.vite.script("src/js/app.ts", false) }}
510
511
```
@@ -564,7 +565,7 @@ resource must match.
564
565
565
566
**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.
566
567
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 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:
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:
@@ -757,6 +758,26 @@ This assumes your `vite.config.js` looks something like this:
757
758
},
758
759
```
759
760
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:
0 commit comments