Skip to content

Commit 2f53f2f

Browse files
committed
feat($default-theme): new file-level API: style.styl.
1. Fixed overriding css doesn't work at 0.11.0 (close: #639) 2. Split override.styl into two APIs: override.styl and style.styl, the former will focus on ONLY the style constants override, while the latter will focus on styles override or custom styles. See also: https://vuepress.vuejs.org/default-theme-config/#simple-css-override.
1 parent 16e917d commit 2f53f2f

File tree

5 files changed

+51
-2
lines changed

5 files changed

+51
-2
lines changed

docs/.vuepress/override.styl

Whitespace-only changes.

docs/default-theme-config/README.md

+33
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,39 @@ $borderColor = #eaecef
419419
$codeBgColor = #282c34
420420
```
421421

422+
### Existing issues <Badge text="< 0.12.0" type='error'/>
423+
424+
In order to override the default variables mentioned above, `override.styl` will be imported at the end of the `config.styl` in default theme, and this file will be used by multiple files, so once you wrote styles here, your style will be duplicated by multiple times. See [#637](https://github.com/vuejs/vuepress/issues/637).
425+
426+
In fact, `style constants override` and `styles override` are two things, the former should be executed before any CSS is compiled, while the latter should be generated at the end of the CSS bundle, which has the highest priority.
427+
428+
### Migrate your styles to `style.styl` <Badge text="0.12.0+"/>
429+
430+
Start from `0.12.0`, we split `override.styl` into two APIs: `override.styl` and `style.styl`:
431+
432+
If you wrote styles at `override.styl` in the past, e.g.
433+
434+
``` stylus
435+
// override.styl
436+
$textColor = red // style constants override
437+
438+
#my-style {} // styles override or custom styles.
439+
```
440+
441+
You'll need to separate the style part to `style.styl`:
442+
443+
``` stylus
444+
// override.styl
445+
// SHOULD ONLY focus on style constants override.
446+
$textColor = red
447+
```
448+
449+
``` stylus
450+
// style.styl
451+
// SHOULD focus on styles override or your custom styles.
452+
#my-style {}
453+
```
454+
422455
## Custom Page Class
423456

424457
Sometimes, you may need to add a unique class for a specific page so that you can target content on that page only in custom CSS. You can add a class to the theme container div with `pageClass` in `YAML front matter`:

lib/app/app.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import enhanceApp from '@temp/enhanceApp'
88
import themeEnhanceApp from '@temp/themeEnhanceApp'
99

1010
// generated from user config
11-
import('@temp/override.styl')
11+
import('@temp/style.styl')
1212

1313
// built-in components
1414
import Content from './components/Content'

lib/default-theme/styles/config.styl

+2
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ $MQMobileNarrow = 419px
1717

1818
// code
1919
$lineNumbersWrapperWidth = 3.5rem
20+
21+
@import '~@temp/override.styl'

lib/prepare/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const fs = require('fs-extra')
33
const resolveOptions = require('./resolveOptions')
44
const { genRoutesFile, genComponentRegistrationFile } = require('./codegen')
55
const { writeTemp, writeEnhanceTemp } = require('./util')
6+
const logger = require('../util/logger')
7+
const chalk = require('chalk')
68

79
module.exports = async function prepare (sourceDir) {
810
// 1. load options
@@ -24,7 +26,19 @@ module.exports = async function prepare (sourceDir) {
2426
// 4. handle user override
2527
const overridePath = path.resolve(sourceDir, '.vuepress/override.styl')
2628
const hasUserOverride = fs.existsSync(overridePath)
27-
await writeTemp(`override.styl`, hasUserOverride ? `@import(${JSON.stringify(overridePath)})` : ``)
29+
await writeTemp('override.styl', hasUserOverride ? `@import(${JSON.stringify(overridePath)})` : ``)
30+
31+
const stylePath = path.resolve(sourceDir, '.vuepress/style.styl')
32+
const hasUserStyle = fs.existsSync(stylePath)
33+
await writeTemp('style.styl', hasUserStyle ? `@import(${JSON.stringify(stylePath)})` : ``)
34+
35+
// Temporary tip, will be removed at next release.
36+
if (hasUserOverride && !hasUserStyle) {
37+
logger.tip(
38+
`${chalk.magenta('override.styl')} has been split into 2 APIs, we recommend you upgrade to continue.\n` +
39+
` See: ${chalk.magenta('https://vuepress.vuejs.org/default-theme-config/#simple-css-override')}`
40+
)
41+
}
2842

2943
// 5. handle enhanceApp.js
3044
const enhanceAppPath = path.resolve(sourceDir, '.vuepress/enhanceApp.js')

0 commit comments

Comments
 (0)