rollup-plugin-sass icon indicating copy to clipboard operation
rollup-plugin-sass copied to clipboard

Any hint on how to write hash in final file name?

Open frederikhors opened this issue 5 years ago • 4 comments

Any hint on how to write hash in final file name?

frederikhors avatar Jun 01 '19 18:06 frederikhors

Use the output: callback option and generate a hash name from the callback parameters?

differui avatar Jun 02 '19 13:06 differui

And how to "generate a hash name"?

frederikhors avatar Jun 16 '19 18:06 frederikhors

Here's how I do it (based on rollup's own implementation):

import sha256 from 'hash.js/lib/hash/sha/256'

sass({
  output: (style) => {
    const hash = sha256().update(styles).digest('hex')
    const fileName = `styles-${hash.substring(0, 8)}.css`
    mkdirSync('path/to/output/dir', {recursive: true})
    writeFileSync(`path/to/output/dir/${fileName}`, styles)
  }
})

SKalt avatar Oct 06 '19 15:10 SKalt

Moving to 'triaged' - For now the above solutions will suffice but we need to leverage rollup's existing lifecycle related config options (output.chunkFileNames, etc.) to achieve the same thing. New ticket created: #122 .

elycruz avatar Oct 07 '23 18:10 elycruz