This repository was archived by the owner on Aug 9, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,13 @@ interface PluginOptions {
38
38
* @default true
39
39
*/
40
40
active ?: boolean
41
+
42
+ /**
43
+ * Commonly assets will be prefixed with a public path, such as "/" or "/assets".
44
+ * Setting this option to the public path allows plugin-sri to resolve those imports.
45
+ * @default ""
46
+ */
47
+ publicPath ?: string
41
48
}
42
49
43
50
const invalidHashAlgorithms = [ 'sha1' , 'md5' ]
@@ -47,6 +54,7 @@ export default (options?: PluginOptions): Plugin => {
47
54
const hashAlgorithms = options ?. algorithms || [ 'sha384' ]
48
55
const crossorigin = options ?. crossorigin || 'anonymous'
49
56
const active = options ?. active ?? true
57
+ const publicPath = options ?. publicPath ?? ''
50
58
51
59
return {
52
60
name : 'subresource-integrity' ,
@@ -69,6 +77,7 @@ export default (options?: PluginOptions): Plugin => {
69
77
const url = $ ( el ) . attr ( 'href' ) || $ ( el ) . attr ( 'src' )
70
78
if ( ! url ) return
71
79
80
+ const url = ( $ ( el ) . attr ( 'href' ) || $ ( el ) . attr ( 'src' ) ) ?. replace ( publicPath , '' )
72
81
let buf : Buffer
73
82
if ( url . startsWith ( 'http:' ) ) {
74
83
buf = await ( await fetch ( url ) ) . buffer ( )
You can’t perform that action at this time.
0 commit comments