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
import{createHash}from'crypto';constcontentHash=(getHash)=>{return{name: 'content-hash',generateBundle: function(options={},bundle={},isWrite=false){if(!isWrite){return}constupdateBundle=(key,value)=>{if(!value.code){//Maybe add asset support laterreturn;}constcurrentHash=getHash(key)if(currentHash===value.fileName){return;}constnewKey=key.replace(currentHash,createHash('sha256').update(value.code).digest('hex').substring(0,10))console.log(currentHash,key,newKey)value.fileName=newKey//TODO: if file exists we would throw this out of the bundle! no need to rewrite that filebundle[newKey]=valuedeletebundle[key]Object.values(bundle).map(currentValue=>{if(currentValue.imports.includes(key)){currentValue.imports=[...currentValue.imports.filter(x=>x!==key),newKey]}if(currentValue.dynamicImports.includes(key)){currentValue.dynamicImports=[...currentValue.dynamicImports.filter(x=>x!==key),newKey]}if(currentValue.implicitlyLoadedBefore.includes(key)){currentValue.implicitlyLoadedBefore=[...currentValue.implicitlyLoadedBefore.filter(x=>x!==key),newKey]}if(currentValue.code.indexOf(key)>-1){currentValue.code=currentValue.code.split(key).join(newKey)updateBundle(currentValue.fileName,currentValue)}})}for(const[key,value]ofObject.entries(bundle)){// only works with none asset chunks assets have sourceupdateBundle(key,value)}console.log(bundle)}}}exportdefault{input: 'main.js',output: {dir: 'dist',chunkFileNames: '[name]-[hash].js',format: 'systemjs'},plugins: [contentHash(fileName=>{constsplit=fileName.split('-');consthasHash=split.length>1returnhasHash ? split.pop().split('.')[0] : fileName;})]}
it works at present i think this will solve it when it is a bit more designed
The text was updated successfully, but these errors were encountered:
am working on a plugin to solve that https://github.com/direktspeed/plugins/tree/plugin-content-hash
@rollup/plugin-content-hash
Example
rollup.config.js
it works at present i think this will solve it when it is a bit more designed
The text was updated successfully, but these errors were encountered: