Skip to content

Commit

Permalink
feat(bundler-vite): dynamically handle plugins and themes for vite (c…
Browse files Browse the repository at this point in the history
…lose #585)
  • Loading branch information
Mister-Hope committed Apr 19, 2022
1 parent 81d520b commit d9598a0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
4 changes: 2 additions & 2 deletions docs/reference/plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The following hooks will be processed in dev / build:

Name of the plugin.

It will be used for identifying plugins to avoid using a same plugin multiple times, so make sure to use a unique plugin name.
It will be used for identifying plugins to handle plugin correctly for specific bundlers and to avoid using a same plugin multiple times, so make sure it's the same as plugin package name.

It should follow the naming convention:

Expand Down Expand Up @@ -180,7 +180,7 @@ module.exports = {
Page options extension.
This hook accepts a function that will receive the options of `createPage`.
This hook can be used for modifying page options
- Example:
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/reference/plugin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

插件的名称。

它会被用来识别插件,以避免多次使用同一个插件,因此应确保你的插件名称是独一无二的
它会被用来识别插件,以帮助特定打包工具处理插件并避免多次使用同一个插件,因此应确保你的插件名称符合发布的包名称

它应遵从如下命名约定:

Expand Down
43 changes: 15 additions & 28 deletions packages/@vuepress/bundler-vite/src/plugins/createMainPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,13 @@
import type { App } from '@vuepress/core'
import { fs } from '@vuepress/utils'
import { fs, requireResolve } from '@vuepress/utils'
import * as history from 'connect-history-api-fallback'
import type { Connect, Plugin } from 'vite'
import type { ViteBundlerOptions } from '../types'
import { resolveAlias } from './resolveAlias'
import { resolveDefine } from './resolveDefine'

// packages that include client code, which should not
// be optimized nor externalized
const clientPackages = [
'@vuepress/client',
'@vuepress/plugin-active-header-links',
'@vuepress/plugin-back-to-top',
'@vuepress/plugin-container',
'@vuepress/plugin-docsearch',
'@vuepress/plugin-external-link-icon',
'@vuepress/plugin-git',
'@vuepress/plugin-google-analytics',
'@vuepress/plugin-medium-zoom',
'@vuepress/plugin-nprogress',
'@vuepress/plugin-palette',
'@vuepress/plugin-prismjs',
'@vuepress/plugin-pwa',
'@vuepress/plugin-pwa-popup',
'@vuepress/plugin-register-components',
'@vuepress/plugin-search',
'@vuepress/plugin-shiki',
'@vuepress/plugin-theme-data',
'@vuepress/plugin-toc',
'@vuepress/shared',
'@vuepress/theme-default',
]
// built-in packages that include client code, which should not be optimized nor externalized
const BUILT_IN_PACKAGES = ['@vuepress/client', '@vuepress/shared']

export const createMainPlugin = ({
app,
Expand Down Expand Up @@ -102,10 +79,20 @@ import '@vuepress/client/lib/app.js'
},
optimizeDeps: {
include: ['@vuepress/shared'],
exclude: clientPackages,
exclude: [
...BUILT_IN_PACKAGES,
...app.pluginApi.plugins
.map((plugin) => plugin.name)
.filter(requireResolve),
],
},
ssr: {
noExternal: clientPackages,
noExternal: [
...BUILT_IN_PACKAGES,
...app.pluginApi.plugins
.map((plugin) => plugin.name)
.filter(requireResolve),
],
},
}
},
Expand Down

0 comments on commit d9598a0

Please sign in to comment.