mirror of
https://github.com/wahyd4/vuepress.git
synced 2026-08-09 05:16:23 +10:00
refactor: Extract default-theme-only webpack aliases
This commit is contained in:
@@ -30,6 +30,14 @@ class PluginContext {
|
||||
get publicPath () {
|
||||
return this._options.publicPath
|
||||
}
|
||||
|
||||
get themeConfig () {
|
||||
return this._options.themeConfig
|
||||
}
|
||||
|
||||
get siteConfig () {
|
||||
return this._options.siteConfig
|
||||
}
|
||||
}
|
||||
|
||||
Object.assign(PluginContext.prototype, {
|
||||
|
||||
@@ -89,13 +89,6 @@ module.exports = async function resolveOptions (sourceDir) {
|
||||
// resolve theme config
|
||||
const themeConfig = siteConfig.themeConfig || {}
|
||||
|
||||
// resolve algolia
|
||||
const isAlgoliaSearch = (
|
||||
themeConfig.algolia ||
|
||||
Object.keys(siteConfig.locales && themeConfig.locales || {})
|
||||
.some(base => themeConfig.locales[base].algolia)
|
||||
)
|
||||
|
||||
// resolve markdown
|
||||
const markdown = createMarkdown(siteConfig)
|
||||
|
||||
@@ -122,7 +115,6 @@ module.exports = async function resolveOptions (sourceDir) {
|
||||
themeLayoutPath,
|
||||
themeNotFoundPath,
|
||||
themePlugins,
|
||||
isAlgoliaSearch,
|
||||
markdown
|
||||
}
|
||||
|
||||
|
||||
@@ -8,13 +8,14 @@ const registerGlobalComponentsPlugin = require('../../../plugin-register-global-
|
||||
const activeHeaderLinksPlugin = require('../../../plugin-active-header-links/index')
|
||||
|
||||
module.exports = function (options) {
|
||||
const { siteConfig, themeConfig, sourceDir, themePath } = options
|
||||
const { siteConfig, themeConfig, sourceDir, themePath, themePlugins } = options
|
||||
const pluginContext = new PluginContext(options)
|
||||
const plugin = new Plugin(pluginContext)
|
||||
|
||||
plugin
|
||||
// user plugin
|
||||
.useByConfigs(siteConfig.plugins)
|
||||
.useByConfigs(themePlugins)
|
||||
// built-in plugins
|
||||
.use(enhanceAppPlugin)
|
||||
.use(registerGlobalComponentsPlugin, {
|
||||
|
||||
@@ -44,10 +44,6 @@ module.exports = function createBaseConfig ({
|
||||
.set('@app', path.resolve(__dirname, '../app'))
|
||||
.set('@temp', path.resolve(__dirname, '../app/.temp'))
|
||||
.set('@dynamic', path.resolve(__dirname, '../app/.temp/dynamic-modules'))
|
||||
.set('@default-theme', path.resolve(__dirname, '../default-theme'))
|
||||
.set('@AlgoliaSearchBox', isAlgoliaSearch
|
||||
? path.resolve(__dirname, '../default-theme/AlgoliaSearchBox.vue')
|
||||
: path.resolve(__dirname, './noopModule.js'))
|
||||
.end()
|
||||
.extensions
|
||||
.merge(['.js', '.jsx', '.vue', '.json', '.styl'])
|
||||
|
||||
@@ -5,10 +5,12 @@ export default {
|
||||
mounted () {
|
||||
window.addEventListener('scroll', this.onScroll)
|
||||
},
|
||||
|
||||
methods: {
|
||||
onScroll: throttle(function () {
|
||||
this.setActiveHash()
|
||||
}, 300),
|
||||
|
||||
setActiveHash () {
|
||||
const sidebarLinks = [].slice.call(document.querySelectorAll('.sidebar-link'))
|
||||
const anchors = [].slice.call(document.querySelectorAll('.header-anchor'))
|
||||
@@ -41,6 +43,7 @@ export default {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
beforeDestroy () {
|
||||
window.removeEventListener('scroll', this.onScroll)
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
export default ({ Vue }) => {
|
||||
Vue.component('Badge', () => import('./components/Badge.vue'))
|
||||
}
|
||||
@@ -1,8 +1,11 @@
|
||||
const path = require('path')
|
||||
const plugin = require('./plugin')
|
||||
|
||||
// Theme API.
|
||||
module.exports = {
|
||||
layout: path.resolve(__dirname, 'src/Layout.vue'),
|
||||
notFound: path.resolve(__dirname, 'src/NotFound.vue'),
|
||||
plugins: []
|
||||
plugins: [
|
||||
plugin
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export default {}
|
||||
@@ -0,0 +1,24 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports = (options, context) => ({
|
||||
name: 'default-theme',
|
||||
|
||||
chainWebpack (config, isServer) {
|
||||
const { themeConfig, siteConfig } = context
|
||||
|
||||
// resolve algolia
|
||||
const isAlgoliaSearch = (
|
||||
themeConfig.algolia ||
|
||||
Object.keys(siteConfig.locales && themeConfig.locales || {})
|
||||
.some(base => themeConfig.locales[base].algolia)
|
||||
)
|
||||
|
||||
config.resolve
|
||||
.alias
|
||||
.set('@default-theme', path.resolve('.'))
|
||||
.set('@AlgoliaSearchBox', isAlgoliaSearch
|
||||
? path.resolve(__dirname, './src/AlgoliaSearchBox.vue')
|
||||
: path.resolve(__dirname, './noopModule.js'))
|
||||
.end()
|
||||
}
|
||||
})
|
||||
@@ -1,5 +1,4 @@
|
||||
const testPlugin = require('../../../@vuepress/plugin-test/index')
|
||||
const translationComparisonPlugin = require('../../../../../vuepress-plugin-translation-ui/src/index')
|
||||
|
||||
module.exports = {
|
||||
dest: 'vuepress',
|
||||
@@ -29,8 +28,7 @@ module.exports = {
|
||||
serviceWorker: true,
|
||||
theme: 'default',
|
||||
plugins: [
|
||||
testPlugin,
|
||||
translationComparisonPlugin
|
||||
testPlugin
|
||||
],
|
||||
themeConfig: {
|
||||
repo: 'vuejs/vuepress',
|
||||
|
||||
@@ -12,7 +12,7 @@ All options listed on this page apply to the default theme only. If you are usin
|
||||
|
||||
## Homepage
|
||||
|
||||
The default theme provides a homepage layout (which is used on [the homepage of this very website](../../README.md)). To use it, specify `home: true` plus some other metadata in your root `README.md`'s [YAML front matter](../guide/markdown.md#front-matter). This is the actual data used on this site:
|
||||
The default theme provides a homepage layout (which is used on [the homepage of this very website](../README.md)). To use it, specify `home: true` plus some other metadata in your root `README.md`'s [YAML front matter](../guide/markdown.md#front-matter). This is the actual data used on this site:
|
||||
|
||||
``` yaml
|
||||
---
|
||||
|
||||
Reference in New Issue
Block a user