Skip to content

Commit

Permalink
fix($core): Index.styl is not injected at the end of the style bund…
Browse files Browse the repository at this point in the history
…le (close: #1523)

BTW, A theme cannot require the theme's styles at the layout but need use `Index.styl`  instead.
  • Loading branch information
ulivz committed Apr 6, 2019
1 parent 5876001 commit dabf506
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,22 @@ module.exports = (options, ctx) => ({
? `@import(${JSON.stringify(userPalette.replace(/[\\]+/g, '/'))})`
: ''

const nullComment = '// null'

// user's palette can override theme's palette.
let paletteContent = themePaletteContent + userPaletteContent
let paletteContent = '// Theme\'s Palette\n'
+ (themePaletteContent || nullComment)
+ '\n\n// User\'s Palette\n'
+ (userPaletteContent || nullComment)

if (ctx.themeAPI.existsParentTheme) {
const parentThemePalette = path.resolve(ctx.themeAPI.parentTheme.path, 'styles/palette.styl')
const parentThemePaletteContent = fs.existsSync(parentThemePalette)
? `@import(${JSON.stringify(parentThemePalette.replace(/[\\]+/g, '/'))})`
: ''
paletteContent = parentThemePaletteContent + paletteContent
paletteContent = '// Parent Theme\'s Palette\n'
+ (parentThemePaletteContent || nullComment)
+ '\n\n' + paletteContent
}

await writeTemp('palette.styl', paletteContent)
Expand Down
13 changes: 11 additions & 2 deletions packages/@vuepress/core/lib/node/internal-plugins/style/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,23 @@ module.exports = (options, ctx) => ({
? `@import(${JSON.stringify(userStyle.replace(/[\\]+/g, '/'))})`
: ''

let styleContent = themeStyleContent + userStyleContent
const nullComment = '// null'

// user's styles can override theme's styles.
let styleContent = '// Theme\'s Styles\n'
+ (themeStyleContent || nullComment)
+ '\n\n// User\'s Styles\n'
+ (userStyleContent || nullComment)

if (themeAPI.existsParentTheme) {
const parentThemeStyle = path.resolve(themeAPI.parentTheme.path, 'styles/index.styl')
const parentThemeStyleContent = fs.existsSync(parentThemeStyle)
? `@import(${JSON.stringify(parentThemeStyle.replace(/[\\]+/g, '/'))})`
: ''
styleContent = parentThemeStyleContent + styleContent

styleContent = '// Parent Theme\'s Styles\n'
+ (parentThemeStyleContent || nullComment)
+ '\n\n' + styleContent
}

await writeTemp('style.styl', styleContent)
Expand Down
2 changes: 0 additions & 2 deletions packages/@vuepress/theme-default/layouts/404.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,3 @@ export default {
}
}
</script>

<style src="../styles/theme.styl" lang="stylus"></style>
1 change: 0 additions & 1 deletion packages/@vuepress/theme-default/layouts/Layout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,3 @@ export default {
</script>

<style src="prismjs/themes/prism-tomorrow.css"></style>
<style src="../styles/theme.styl" lang="stylus"></style>

0 comments on commit dabf506

Please sign in to comment.