How to ass cssHash i see warning : [vite-plugin-svelte] The following Svelte compilerOptions are controlled by vite-plugin-svelte and essential to its functionality #13855
-
Hello, please help me The goal is to change classes like this : <div class="xx s-OTmmHBhb3fXp" data-svelte-h="svelte-g8ovga">c</div> to this : <div class="xx s-OTmmHBhb3fXp" data-svelte-h="meaw-g8ovga">c</div> I add the code to compilerOptions: {
cssHash: ({ hash, name, filename, css }) => {
// default behavior
//return `svelte-${hash(css)}`;
// stable hashes for HMR
return `wohh-${hash(filename)}`;
}
}, Final code like this: import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */
const config = {
+ compilerOptions: {
+ cssHash: ({ hash, name, filename, css }) => {
+ // default behavior
+ //return `svelte-${hash(css)}`;
+
+ // stable hashes for HMR
+ return `svelte-${hash(filename)}`;
+ }
+
},
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: [vitePreprocess({})],
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
},
};
export default config; i will see WARNING like thsis:
in NOT like this: import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
export default defineConfig({
plugins: [
sveltekit({
compilerOptions: {
cssHash: ({ hash }) => hash('foo')
}
})
],
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "src/scss/variables.scss" as *;'
}
}
}
}); or this: import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';
export default defineConfig({
plugins: [sveltekit()],
test: {
include: ['src/**/*.{test,spec}.{js,ts}']
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "src/scss/variables.scss" as *;'
}
}
},
compilerOptions: {
cssHash: ({ hash }) => hash('foo')
}
}); |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
And if i want to change the cssHash on dev also dosen't work idk why and why work only on prod? import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';
const compilerOptions = {};
// if (process.env.NODE_ENV === 'production') {
compilerOptions.cssHash = ({ hash, css }) => `ai-${hash(css)}`;
// }
/** @type {import('@sveltejs/kit').Config} */
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: [vitePreprocess({})],
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
},
compilerOptions
};
export default config; |
Beta Was this translation helpful? Give feedback.
-
It looks like you are trying to customize the Firstly, the warning you are seeing about import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/kit/vite';
const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: [vitePreprocess({})],
kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter(),
compilerOptions: {
cssHash: ({ hash, filename, css }) => {
// customize your cssHash here
return `meaw-${hash(filename)}`;
}
}
},
};
export default config; In this example, I've moved the As for changing the const config = {
// ...
kit: {
// ...
compilerOptions: {
cssHash: ({ hash, filename, css }) => {
if (process.env.NODE_ENV === 'production') {
return `ai-${hash(css)}`;
} else {
// customize your development cssHash here
return `dev-${hash(css)}`;
}
},
},
},
};
export default config; This way, you can have different |
Beta Was this translation helpful? Give feedback.
-
So.. what's the ideal solution for this? |
Beta Was this translation helpful? Give feedback.
It looks like you are trying to customize the
cssHash
in a SvelteKit project, but you are encountering some issues. Let me try to help you with that.Firstly, the warning you are seeing about
cssHash
is likely because you are trying to override it in the wrong place. ThecssHash
should be set in thecompilerOptions
underkit
in yoursvelte.config.js
, not at the top level ofcompilerOptions
. Here's how you can update yoursvelte.config.js
: