-
-
Notifications
You must be signed in to change notification settings - Fork 13
2 Errors in different projects #9
Comments
The webpack pendant uses instead of |
I'm encountering this same issue while building with AWS Amplify 😭 |
Looks like this happens when you have
Those files aren't included in the |
@aral I tried to create a PR, but I don't have write access, here is a small change to the ////////////////////////////////////////////////////////////////////////////////
//
// @small-tech/vite-plugin-sri
//
// Subresource integrity (SRI) plugin for Vite (https://vitejs.dev/)
//
// Adds subresource integrity hashes to script and stylesheet
// imports from your index.html file at build time.
//
// If you’re looking for a generic Rollup plugin that does the same thing,
// see rollup-plugin-sri by Jonas Kruckenberg that this one was inspired by:
// https://github.com/JonasKruckenberg/rollup-plugin-sri
//
// Like this? Fund us!
// https://small-tech.org/fund-us
//
// Copyright ⓒ 2021-present Aral Balkan, Small Technology Foundation
// License: ISC.
//
////////////////////////////////////////////////////////////////////////////////
import { createHash } from 'crypto'
import cheerio from 'cheerio'
import fetch from 'node-fetch'
export default function sri () {
return {
name: 'vite-plugin-sri',
enforce: 'post',
apply: 'build',
async transformIndexHtml(html, context) {
const bundle = context.bundle
const calculateIntegrityHashes = async (element) => {
let source
let attributeName = element.attribs.src ? 'src' : 'href'
const resourcePath = element.attribs[attributeName]
if (resourcePath.startsWith('http')) {
// Load remote source from URL.
source = await (await fetch(resourcePath)).buffer()
} else {
// Load local source from bundle.
const resourcePathWithoutLeadingSlash = element.attribs[attributeName].slice(1)
const bundleItem = bundle[resourcePathWithoutLeadingSlash]
source = bundleItem && (bundleItem.code || bundleItem.source)
}
if (source) {
element.attribs.integrity = `sha384-${createHash('sha384').update(source).digest().toString('base64')}`
}
}
const $ = cheerio.load(html)
$.prototype.asyncForEach = async function (callback) {
for (let index = 0; index < this.length; index++) {
await callback(this[index], index, this);
}
}
// Implement SRI for scripts and stylesheets.
const scripts = $('script').filter('[src]')
const stylesheets = $('link[rel=stylesheet]').filter('[href]')
await scripts.asyncForEach(calculateIntegrityHashes)
await stylesheets.asyncForEach(calculateIntegrityHashes)
return $.html()
}
}
} |
I tried to use the plugin in advanced projects. In the first one i could build but not load the js file, the console in the browser says:
This is the generated script tag where the error comes from:
Why is there no integrity attribute on the generated vendor js file?
In my secound project it wasn't able to run the "npm run build" command successfully. No matter how much assets i deleted from my index.html. The console wrote me everytime:
For both projects i used the vue3 vite template. I don't know whats wrong there.
The text was updated successfully, but these errors were encountered: