From 894e0131520a7f86595aeadf64162c6d4455963d Mon Sep 17 00:00:00 2001 From: "Mr.Hope" Date: Thu, 20 Nov 2025 16:02:03 +0800 Subject: [PATCH] fix(plugin-palette): fix plugin usage with default theme --- .../plugin-palette/src/node/palettePlugin.ts | 37 +++++++++++++++++++ .../src/node/sassPalettePlugin.ts | 2 +- .../src/client/styles/_variables.scss | 2 +- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/plugins/development/plugin-palette/src/node/palettePlugin.ts b/plugins/development/plugin-palette/src/node/palettePlugin.ts index 005e734786..89415eaa79 100644 --- a/plugins/development/plugin-palette/src/node/palettePlugin.ts +++ b/plugins/development/plugin-palette/src/node/palettePlugin.ts @@ -1,3 +1,4 @@ +import { addViteConfig, chainWebpack } from '@vuepress/helper' import { watch } from 'chokidar' import type { Plugin } from 'vuepress/core' import { preparePaletteFile } from './preparePaletteFile.js' @@ -90,6 +91,42 @@ export const palettePlugin = ({ '@vuepress/plugin-palette/style': app.dir.temp(tempStyleFile), }), + extendsBundlerOptions: (bundlerOptions, app) => { + if (preset !== 'sass') return + + // silent import deprecation for vite + addViteConfig(bundlerOptions, app, { + css: { + preprocessorOptions: { + sass: { + silenceDeprecations: ['import'], + }, + scss: { + silenceDeprecations: ['import'], + }, + }, + }, + }) + // silent import deprecation for webpack + chainWebpack(bundlerOptions, app, (webpackOptions) => { + webpackOptions.module + .rule('scss') + .use('sass-loader') + .tap((loaderOptions) => ({ + ...loaderOptions, + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + sassOptions: { + ...loaderOptions.sassOptions, + silenceDeprecations: [ + 'import', + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access + ...(loaderOptions.sassOptions?.silenceDeprecations ?? []), + ], + }, + })) + }) + }, + onPrepared: async (app) => { await Promise.all([ preparePaletteFile(app, { diff --git a/plugins/development/plugin-sass-palette/src/node/sassPalettePlugin.ts b/plugins/development/plugin-sass-palette/src/node/sassPalettePlugin.ts index c6d57600dd..2eba30f9fa 100644 --- a/plugins/development/plugin-sass-palette/src/node/sassPalettePlugin.ts +++ b/plugins/development/plugin-sass-palette/src/node/sassPalettePlugin.ts @@ -89,7 +89,7 @@ export const sassPalettePlugin = }, extendsBundlerOptions: (bundlerOptions: unknown): void => { - // switch to modern api and silent import deprecation for vite + // silent import deprecation for vite addViteConfig(bundlerOptions, app, { css: { preprocessorOptions: { diff --git a/themes/theme-default/src/client/styles/_variables.scss b/themes/theme-default/src/client/styles/_variables.scss index 39b6916ed4..da9f7dfedb 100644 --- a/themes/theme-default/src/client/styles/_variables.scss +++ b/themes/theme-default/src/client/styles/_variables.scss @@ -1,5 +1,5 @@ /* stylelint-disable scss/dollar-variable-pattern */ -@forward '@vuepress/plugin-palette/palette'; +@import '@vuepress/plugin-palette/palette'; // responsive breakpoints $MQNarrow: 959px !default;