elycruz / rollup-plugin-sass

Rollup .sass files.
MIT License
91 stars 33 forks source link

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

Open frederikhors opened 5 years ago

frederikhors commented 5 years ago

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

differui commented 5 years ago

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

frederikhors commented 5 years ago

And how to "generate a hash name"?

SKalt commented 5 years ago

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)
  }
})
elycruz commented 1 year ago

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 .