Skip to content

Commit

Permalink
feat(rollup-plugin): hash should respect file content
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed Dec 23, 2024
1 parent 347e9c7 commit c18621a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/rollup-plugin/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ export type PluginOptions = $ReadOnly<{
...
}>;

function replaceFileName(original: string) {
function replaceFileName(original: string, css: string) {
if (!original.includes('[hash]')) {
return original;
}
const hash = crypto
.createHash('sha256')
.update(crypto.randomBytes(16))
.update(css)
.digest('hex')
.slice(0, 8);
return original.replace(/\[hash\]/g, hash);
Expand Down Expand Up @@ -92,7 +95,7 @@ export default function stylexPlugin({
// This is the intended API, but Flow doesn't support this pattern.
// $FlowExpectedError[object-this-reference]
this.emitFile({
fileName: replaceFileName(fileName),
fileName: replaceFileName(fileName, processedCSS),
source: processedCSS,
type: 'asset',
});
Expand Down

0 comments on commit c18621a

Please sign in to comment.