Skip to content

Commit a5f58f7

Browse files
committed
feat($core): alias - plugin API
1 parent d910859 commit a5f58f7

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

packages/@vuepress/core/lib/plugin-api/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ const PLUGIN_OPTION_META_MAP = {
1717
CLIENT_ROOT_MIXIN: { name: 'clientRootMixin', types: [String] },
1818
ADDITIONAL_PAGES: { name: 'additionalPages', types: [Function, Array] },
1919
GLOBAL_UI_COMPONENTS: { name: 'globalUIComponents', types: [String, Array] },
20-
DEFINE: { name: 'define', types: [Function, Object] }
20+
DEFINE: { name: 'define', types: [Function, Object] },
21+
ALIAS: { name: 'alias', types: [Function, Object] }
2122
}
2223

2324
const PLUGIN_OPTION_MAP = {}

packages/@vuepress/core/lib/plugin-api/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,8 @@ module.exports = class PluginAPI {
156156
clientRootMixin,
157157
additionalPages,
158158
globalUIComponents,
159-
define
159+
define,
160+
alias
160161
}) {
161162
const isInternalPlugin = pluginName.startsWith('@vuepress/internal-')
162163
if (shortcut) {
@@ -181,5 +182,6 @@ module.exports = class PluginAPI {
181182
.registerOption(PLUGIN_OPTION_MAP.ADDITIONAL_PAGES.key, additionalPages, pluginName)
182183
.registerOption(PLUGIN_OPTION_MAP.GLOBAL_UI_COMPONENTS.key, globalUIComponents, pluginName)
183184
.registerOption(PLUGIN_OPTION_MAP.DEFINE.key, define, pluginName)
185+
.registerOption(PLUGIN_OPTION_MAP.ALIAS.key, alias, pluginName)
184186
}
185187
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict'
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
const Option = require('../abstract/Option')
8+
9+
/**
10+
* define option.
11+
*/
12+
13+
module.exports = class DefineOption extends Option {
14+
apply (config) {
15+
super.syncApply()
16+
const aliases = this.appliedValues
17+
aliases.forEach((alias) => {
18+
Object.keys(alias).forEach(key => {
19+
config.resolve.alias.set('key', alias[key])
20+
})
21+
})
22+
}
23+
}

packages/@vuepress/core/lib/plugin-api/override/instantiateOption.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const EnhanceAppFilesOption = require('./EnhanceAppFilesOption')
22
const ClientDynamicModulesOption = require('./ClientDynamicModulesOption')
33
const GlobalUIComponentsOption = require('./GlobalUIComponentsOption')
44
const DefineOption = require('./DefineOption')
5+
const AliasOption = require('./AliasOption')
56
const Option = require('../abstract/Option')
67
const { PLUGIN_OPTION_MAP } = require('../constants')
78

@@ -19,6 +20,9 @@ module.exports = function instantiateOption (name) {
1920
case PLUGIN_OPTION_MAP.DEFINE.name:
2021
return new DefineOption(name)
2122

23+
case PLUGIN_OPTION_MAP.ALIAS.name:
24+
return new AliasOption(name)
25+
2226
default: return new Option(name)
2327
}
2428
}

packages/@vuepress/core/lib/webpack/createBaseConfig.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ module.exports = function createBaseConfig ({
295295
}])
296296

297297
pluginAPI.options.define.apply(config)
298+
pluginAPI.options.alias.apply(config)
298299

299300
return config
300301
}

0 commit comments

Comments
 (0)