|
1 | 1 | --- |
2 | | -title: Migrating to v3 |
3 | | -description: Guide for migrating from v2 to v3 |
| 2 | +title: Migration Guide |
| 3 | +description: Guide for migrating between major versions |
4 | 4 | --- |
5 | 5 |
|
| 6 | +## Migrating to v4 |
| 7 | + |
| 8 | +v4 of `@nuxtjs/color-mode` requires Nuxt 3+ and drops support for Nuxt Bridge. It also introduces several breaking changes to improve the module. |
| 9 | + |
| 10 | +### Main Changes |
| 11 | + |
| 12 | +#### 1. No Default Class Suffix |
| 13 | + |
| 14 | +The default `classSuffix` has been removed. If you were relying on the default `-mode` suffix, you'll need to explicitly set it in your configuration: |
| 15 | + |
| 16 | +```ts |
| 17 | +export default defineNuxtConfig({ |
| 18 | + colorMode: { |
| 19 | + classSuffix: '-mode' |
| 20 | + } |
| 21 | +}) |
| 22 | +``` |
| 23 | + |
| 24 | +Or update your CSS classes to remove the suffix: |
| 25 | + |
| 26 | +```diff |
| 27 | +- .dark-mode { } |
| 28 | +- .light-mode { } |
| 29 | ++ .dark { } |
| 30 | ++ .light { } |
| 31 | +``` |
| 32 | + |
| 33 | +#### 2. CommonJS Support Dropped |
| 34 | + |
| 35 | +The module no longer provides CommonJS builds. Ensure your project is using ESM (which is the default for Nuxt 3). |
| 36 | + |
| 37 | +#### 3. Read-Only Color Mode Value |
| 38 | + |
| 39 | +You can no longer directly set `colorMode.value`. Use `colorMode.preference` instead: |
| 40 | + |
| 41 | +```diff |
| 42 | +<script setup> |
| 43 | +const colorMode = useColorMode() |
| 44 | + |
| 45 | +- colorMode.value = 'dark' |
| 46 | ++ colorMode.preference = 'dark' |
| 47 | +</script> |
| 48 | +``` |
| 49 | + |
| 50 | +The `value` property is now read-only and reflects the actual color mode being used (which may differ from `preference` when using system preference detection). |
| 51 | + |
| 52 | +#### 4. Removed `hid` Option |
| 53 | + |
| 54 | +The defunct `hid` configuration option has been removed. If you were using it in your config, simply remove it: |
| 55 | + |
| 56 | +```diff |
| 57 | +export default defineNuxtConfig({ |
| 58 | + colorMode: { |
| 59 | +- hid: 'nuxt-color-mode-script', |
| 60 | + preference: 'system', |
| 61 | + } |
| 62 | +}) |
| 63 | +``` |
| 64 | + |
| 65 | +#### 5. Nuxt Bridge Support Dropped |
| 66 | + |
| 67 | +Support for Nuxt Bridge has been removed. If you're still using Nuxt Bridge, you should continue using v3. Otherwise, upgrade to Nuxt 3+. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## Migrating to v3 |
| 72 | + |
6 | 73 | v3 of `@nuxtjs/color-mode` requires either Nuxt Bridge or Nuxt 3+. If you are using Nuxt 2 without Bridge, you should continue to use v2. |
7 | 74 |
|
8 | 75 | ## Main Changes |
|
0 commit comments