From c18621a48397e84d65174044908fb74362138914 Mon Sep 17 00:00:00 2001 From: kanno <812137533@qq.com> Date: Mon, 23 Dec 2024 12:09:43 +0800 Subject: [PATCH] feat(rollup-plugin): hash should respect file content --- packages/rollup-plugin/src/index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/rollup-plugin/src/index.js b/packages/rollup-plugin/src/index.js index c5b55fe9d..a31f33d5f 100644 --- a/packages/rollup-plugin/src/index.js +++ b/packages/rollup-plugin/src/index.js @@ -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); @@ -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', });