From 494bba97b899ce8c690a76e01e6957a0768f126b Mon Sep 17 00:00:00 2001 From: bluwy Date: Wed, 8 Jun 2022 13:41:32 +0800 Subject: [PATCH] docs: clarify cssHash in dev --- docs/config.md | 2 +- docs/faq.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/config.md b/docs/config.md index fa06ed14f..c64bb772b 100644 --- a/docs/config.md +++ b/docs/config.md @@ -83,7 +83,7 @@ These options are specific to the Svelte compiler and are generally shared acros - **Type:** `CompileOptions` - See [svelte.compile](https://svelte.dev/docs#svelte_compile) - The options to be passed to the Svelte compiler. A few options are set by default, including `dev` and `css`. However, some options are non-configurable, like `filename`, `format`, `generate`, and `cssHash` (in dev). + The options to be passed to the Svelte compiler. A few options are set by default, including `dev` and `css`. However, some options are non-configurable, like `filename`, `format`, `generate`, and `cssHash` ([in dev](./faq.md#why-cant-csshash-be-set-in-development-mode)). ### preprocess diff --git a/docs/faq.md b/docs/faq.md index 47cef9659..4808d3813 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -73,6 +73,12 @@ Bad: ``` +### Why can't `cssHash` be set in development mode? + +`cssHash` is fixed in development for CSS HMR in Svelte components, ensuring that the hash value is stable based on the file name so that styles are only updated when changed. + +However, `cssHash` is respected in production builds as HMR is a dev-only feature. + ### How do I add a Svelte preprocessor from a Vite plugin? If you are building a Vite plugin that transforms CSS or JS, you can add a `api.sveltePreprocess: PreprocessorGroup` to your Vite plugin definition and it will be added to the list of Svelte preprocessors used at runtime.