Skip to content

Commit 043590d

Browse files
committed
feat!: migrate to userStyle option
1 parent 32d296b commit 043590d

22 files changed

Lines changed: 15 additions & 387 deletions

File tree

docs/plugins/development/palette.md

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ export default {
3232

3333
## Palette and Style
3434

35-
This plugin provides a `@vuepress/plugin-palette/palette` (palette file) and a `@vuepress/plugin-palette/style` (style file) for import in your theme styles.
35+
This plugin provides a `@vuepress/plugin-palette/palette` (palette file) for import in your theme styles.
3636

3737
The palette file is used to define style variables, so it's typically imported at the beginning of your theme styles. For example, users can define [CSS variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties), [SASS variables](https://sass-lang.com/documentation/variables), [LESS variables](http://lesscss.org/features/#variables-feature), or [Stylus variables](https://stylus-lang.com/docs/variables.html) in the palette, and then you can use those variables in your theme styles.
3838

39-
The style file is used to override default styles or add extra styles, so it's typically imported at the end of your theme styles.
40-
41-
## Usage
39+
## Cookbook
4240

4341
Use this plugin in your theme, assuming you're using SASS:
4442

@@ -83,25 +81,6 @@ Then users can customize variables in `.vuepress/styles/palette.scss`:
8381
$color: green;
8482
```
8583

86-
### Usage of Style
87-
88-
Import the plugin's style file after your theme's styles, for example, in the `clientConfigFile`:
89-
90-
```ts
91-
// import your theme's style file
92-
import 'path/to/your/theme/style'
93-
// import the plugin's style file
94-
import '@vuepress/plugin-palette/style'
95-
```
96-
97-
Then users can add extra styles in `.vuepress/styles/index.scss` and override your theme's default styles:
98-
99-
```scss
100-
h1 {
101-
font-size: 2.5rem;
102-
}
103-
```
104-
10584
## Options
10685

10786
### preset
@@ -152,42 +131,6 @@ h1 {
152131

153132
You should import the palette file via `'@vuepress/plugin-palette/palette'` alias, so you don't need to change this option in most cases.
154133

155-
### userStyleFile
156-
157-
- Type: `string`
158-
159-
- Default:
160-
- css: `'.vuepress/styles/index.css'`
161-
- less: `'.vuepress/styles/index.less'`
162-
- sass: `'.vuepress/styles/index.scss'`
163-
- stylus: `'.vuepress/styles/index.styl'`
164-
165-
- Details:
166-
167-
File path of the user style file, relative to source directory.
168-
169-
The default value depends on the [preset](#preset) option.
170-
171-
This file is where users override default styles or add extra styles, and it's recommended to keep the default file path as a convention.
172-
173-
### tempStyleFile
174-
175-
- Type: `string`
176-
177-
- Default:
178-
- css: `'styles/index.css'`
179-
- less: `'styles/index.less'`
180-
- sass: `'styles/index.scss'`
181-
- stylus: `'styles/index.styl'`
182-
183-
- Details:
184-
185-
File path of the generated style temp file, relative to temp directory.
186-
187-
The default value depends on the [preset](#preset) option.
188-
189-
You should import the style file via `'@vuepress/plugin-palette/style'` alias, so you don't need to change this option in most cases.
190-
191134
### importCode
192135

193136
- Type: `(filePath: string) => string`
@@ -204,4 +147,4 @@ h1 {
204147

205148
The default value depends on the [preset](#preset) option.
206149

207-
This option is used for generating [tempPaletteFile](#temppalettefile) and [tempStyleFile](#tempstylefile), and you don't need to change this option in most cases.
150+
This option is used for generating [tempPaletteFile](#temppalettefile) , and you don't need to change this option in most cases.

docs/plugins/development/sass-palette/config.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,10 @@ As a plugin developer, you should use this file to provide default CSS variables
7272

7373
For example, you can use this to generate a `$theme-color-light` variable based on the `$theme-color` provided by the user.
7474

75-
### style
76-
77-
- Type: `string`
78-
- Details: The path to the user's custom style file, relative to the source directory. This is used for standard CSS/Sass customization.
79-
8075
## Alias
8176

8277
The following aliases are available for import:
8378

8479
- **config**: `@sass-palette/${id}-config` (Derived from `id`)
8580
- **palette**: `@sass-palette/${id}-palette` (Derived from `id`)
86-
- **style**: `@sass-palette/${id}-style` (Only available when the `style` option is set)
8781
- **helper**: `@sass-palette/helper`

docs/plugins/development/sass-palette/guide.md

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,3 @@ $code-c-bg: abc-config.$highlighter == 'shiki'? #fff: #f8f8f8;
241241
```
242242

243243
:::
244-
245-
## User Styles
246-
247-
Theme developers can use the `style` option to allow users to customize the site's appearance with standard CSS/Sass.
248-
249-
You must manually include the user style file by importing the alias `@sass-palette/${id}-style`. This should be imported **after** your theme's base styles to ensure user overrides take precedence.
250-
251-
::: tip
252-
`@sass-palette/${id}-style` is a direct alias to the user's style file and can be imported in JS, TS, or Sass.
253-
:::

docs/zh/plugins/development/palette.md

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,11 @@ export default {
3232

3333
## 调色板和样式
3434

35-
该插件会提供一个 `@vuepress/plugin-palette/palette`(调色板文件)和一个 `@vuepress/plugin-palette/style`(样式文件),用于在你的主题样式中引入。
35+
该插件会提供一个 `@vuepress/plugin-palette/palette`(调色板文件),用于在你的主题样式中引入。
3636

3737
调色板文件用于定义样式变量,因此它通常会在你主题样式的开头引入。举例来说,用户可以在调色板中定义 [CSS 变量](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties)[SASS 变量](https://sass-lang.com/documentation/variables)[LESS 变量](http://lesscss.org/features/#variables-feature)[Stylus 变量](https://stylus-lang.com/docs/variables.html),然后你可以在你的主题样式中使用这些变量。
3838

39-
样式文件用于覆盖默认样式或添加额外样式,因此它通常会在你主题样式的末尾引入。
40-
41-
## 使用
39+
## 教程
4240

4341
在你的主题中使用该插件,假设你使用 SASS 作为 CSS 预处理器:
4442

@@ -78,25 +76,6 @@ $color: red !default;
7876
$color: green;
7977
```
8078

81-
### 使用样式
82-
83-
在你主题的样式之后引入该插件的样式文件,比如在 `clientConfigFile` 中:
84-
85-
```ts
86-
// 引入你主题本身的样式文件
87-
import 'path/to/your/theme/style'
88-
// 引入该插件的样式文件
89-
import '@vuepress/plugin-palette/style'
90-
```
91-
92-
然后,用户就可以在 `.vuepress/styles/index.scss` 中添加额外样式,并可以覆盖你主题的默认样式:
93-
94-
```scss
95-
h1 {
96-
font-size: 2.5rem;
97-
}
98-
```
99-
10079
## 配置项
10180

10281
### preset
@@ -147,42 +126,6 @@ h1 {
147126

148127
你应该通过 `'@vuepress/plugin-palette/palette'` 别名引入调色板文件,因此大部分情况下你不需要修改该配置项。
149128

150-
### userStyleFile
151-
152-
- 类型: `string`
153-
154-
- 默认值:
155-
- css: `'.vuepress/styles/index.css'`
156-
- less: `'.vuepress/styles/index.less'`
157-
- sass: `'.vuepress/styles/index.scss'`
158-
- stylus: `'.vuepress/styles/index.styl'`
159-
160-
- 详情:
161-
162-
用户样式文件的路径,相对于源文件目录。
163-
164-
默认值依赖于 [preset](#preset) 配置项。
165-
166-
此文件用于用户覆盖默认样式或添加额外样式,建议保持默认文件路径作为约定。
167-
168-
### tempStyleFile
169-
170-
- 类型: `string`
171-
172-
- 默认值:
173-
- css: `'styles/index.css'`
174-
- less: `'styles/index.less'`
175-
- sass: `'styles/index.scss'`
176-
- stylus: `'styles/index.styl'`
177-
178-
- 详情:
179-
180-
生成的样式临时文件的路径,相对于临时文件目录。
181-
182-
默认值依赖于 [preset](#preset) 配置项。
183-
184-
你应该通过 `'@vuepress/plugin-palette/style'` 别名引入样式文件,因此大部分情况下你不需要修改该配置项。
185-
186129
### importCode
187130

188131
- 类型: `(filePath: string) => string`
@@ -199,4 +142,4 @@ h1 {
199142

200143
默认值依赖于 [preset](#preset) 配置项。
201144

202-
该配置项用于生成 [tempPaletteFile](#temppalettefile)[tempStyleFile](#tempstylefile),大部分情况下你不需要修改该配置项。
145+
该配置项用于生成 [tempPaletteFile](#temppalettefile),大部分情况下你不需要修改该配置项。

docs/zh/plugins/development/sass-palette/config.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,10 @@ icon: settings-2
7272

7373
例如:你可以利用它基于用户提供的 `$theme-color` 来生成一个 `$theme-color-light` 变量。
7474

75-
### style
76-
77-
- 类型:`string`
78-
- 详情:用户自定义样式文件的路径,相对于源码目录。这通常用于标准的 CSS/Sass 样式覆盖。
79-
8075
## 别名 (Alias)
8176

8277
可用的导入别名如下:
8378

8479
- **config**`@sass-palette/${id}-config` (基于 `id` 生成)
8580
- **palette**`@sass-palette/${id}-palette` (基于 `id` 生成)
86-
- **style**`@sass-palette/${id}-style` (仅在设置了 `style` 选项时可用)
8781
- **helper**`@sass-palette/helper`

docs/zh/plugins/development/sass-palette/guide.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,3 @@ $code-c-bg: abc-config.$highlighter == 'shiki'? #fff: #f8f8f8;
246246
```
247247

248248
:::
249-
250-
## 用户样式
251-
252-
如果你是主题开发者,你可能希望为用户提供一种自定义主题或站点样式的方法。
253-
254-
在这种情况下,你应该在使用此插件时将 `style` 选项设置为用户样式文件。
255-
256-
随后,你需要手动导入 `@sass-palette/${id}-style`,并确保将其放置在 **你的主题样式之后**
257-
258-
::: tip
259-
`@sass-palette/${id}-style` 是用户样式文件的别名,你可以在 JS/TS/SASS 中导入它。
260-
:::
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
export * from './palettePlugin.js'
22
export * from './preparePaletteFile.js'
3-
export * from './prepareStyleFile.js'
43
export * from './presetOptions.js'

plugins/development/plugin-palette/src/node/palettePlugin.ts

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { watch } from 'chokidar'
33
import type { Plugin } from 'vuepress/core'
44

55
import { preparePaletteFile } from './preparePaletteFile.js'
6-
import { prepareStyleFile } from './prepareStyleFile.js'
76
import { presetOptions } from './presetOptions.js'
87

98
/**
@@ -35,20 +34,6 @@ export interface PalettePluginOptions {
3534
*/
3635
tempPaletteFile?: string
3736

38-
/**
39-
* File path of the user style file, relative to source directory
40-
*
41-
* 用户样式文件的路径,相对于源文件目录
42-
*/
43-
userStyleFile?: string
44-
45-
/**
46-
* File path of the generated style temp file, relative to temp directory
47-
*
48-
* 生成的样式临时文件的路径,相对于临时文件目录
49-
*/
50-
tempStyleFile?: string
51-
5237
/**
5338
* Function to generate import code
5439
*
@@ -77,15 +62,12 @@ export const palettePlugin = ({
7762
preset = 'css',
7863
userPaletteFile = presetOptions[preset].userPaletteFile,
7964
tempPaletteFile = presetOptions[preset].tempPaletteFile,
80-
userStyleFile = presetOptions[preset].userStyleFile,
81-
tempStyleFile = presetOptions[preset].tempStyleFile,
8265
importCode = presetOptions[preset].importCode,
8366
}: PalettePluginOptions = {}): Plugin => ({
8467
name: '@vuepress/plugin-palette',
8568

8669
alias: (app) => ({
8770
'@vuepress/plugin-palette/palette': app.dir.temp(tempPaletteFile),
88-
'@vuepress/plugin-palette/style': app.dir.temp(tempStyleFile),
8971
}),
9072

9173
extendsBundlerOptions: (bundlerOptions, app) => {
@@ -125,18 +107,11 @@ export const palettePlugin = ({
125107
},
126108

127109
onPrepared: async (app) => {
128-
await Promise.all([
129-
preparePaletteFile(app, {
130-
userPaletteFile,
131-
tempPaletteFile,
132-
importCode,
133-
}),
134-
prepareStyleFile(app, {
135-
userStyleFile,
136-
tempStyleFile,
137-
importCode,
138-
}),
139-
])
110+
await preparePaletteFile(app, {
111+
userPaletteFile,
112+
tempPaletteFile,
113+
importCode,
114+
})
140115
},
141116

142117
onWatched: (app, watchers) => {
@@ -145,11 +120,6 @@ export const palettePlugin = ({
145120
ignoreInitial: true,
146121
})
147122

148-
const styleWatcher = watch(userStyleFile, {
149-
cwd: app.dir.source(),
150-
ignoreInitial: true,
151-
})
152-
153123
const handlePaletteChange = (): void => {
154124
void preparePaletteFile(app, {
155125
userPaletteFile,
@@ -158,19 +128,9 @@ export const palettePlugin = ({
158128
})
159129
}
160130

161-
const handleStyleChange = (): void => {
162-
void prepareStyleFile(app, {
163-
userStyleFile,
164-
tempStyleFile,
165-
importCode,
166-
})
167-
}
168-
169131
paletteWatcher.on('add', handlePaletteChange)
170132
paletteWatcher.on('unlink', handlePaletteChange)
171-
styleWatcher.on('add', handleStyleChange)
172-
styleWatcher.on('unlink', handleStyleChange)
173133

174-
watchers.push(paletteWatcher, styleWatcher)
134+
watchers.push(paletteWatcher)
175135
},
176136
})

plugins/development/plugin-palette/src/node/prepareStyleFile.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)