Skip to content

Commit 0d77331

Browse files
committed
perf: specify optimizeDeps for vite dev
1 parent 4bbff4c commit 0d77331

File tree

4 files changed

+93
-52
lines changed

4 files changed

+93
-52
lines changed

packages/@vuepress/plugin-active-header-links/src/node/activeHeaderLinksPlugin.ts

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,36 @@ export interface ActiveHeaderLinksPluginOptions {
88
offset?: number
99
}
1010

11-
export const activeHeaderLinksPlugin: Plugin<ActiveHeaderLinksPluginOptions> = ({
12-
headerLinkSelector = '.sidebar-link',
13-
headerAnchorSelector = '.header-anchor',
14-
delay = 200,
15-
offset = 5,
16-
}) => ({
17-
name: '@vuepress/plugin-active-header-links',
11+
export const activeHeaderLinksPlugin: Plugin<ActiveHeaderLinksPluginOptions> = (
12+
{
13+
headerLinkSelector = '.sidebar-link',
14+
headerAnchorSelector = '.header-anchor',
15+
delay = 200,
16+
offset = 5,
17+
},
18+
app
19+
) => {
20+
if (app.env.isDev && app.options.bundler.endsWith('vite')) {
21+
app.options.bundlerConfig.viteOptions = require('vite').mergeConfig(
22+
app.options.bundlerConfig.viteOptions,
23+
{
24+
optimizeDeps: {
25+
exclude: ['ts-debounce'],
26+
},
27+
}
28+
)
29+
}
1830

19-
clientAppSetupFiles: path.resolve(__dirname, '../client/clientAppSetup.js'),
31+
return {
32+
name: '@vuepress/plugin-active-header-links',
2033

21-
define: {
22-
__AHL_HEADER_LINK_SELECTOR__: headerLinkSelector,
23-
__AHL_HEADER_ANCHOR_SELECTOR__: headerAnchorSelector,
24-
__AHL_DELAY__: delay,
25-
__AHL_OFFSET__: offset,
26-
},
27-
})
34+
clientAppSetupFiles: path.resolve(__dirname, '../client/clientAppSetup.js'),
35+
36+
define: {
37+
__AHL_HEADER_LINK_SELECTOR__: headerLinkSelector,
38+
__AHL_HEADER_ANCHOR_SELECTOR__: headerAnchorSelector,
39+
__AHL_DELAY__: delay,
40+
__AHL_OFFSET__: offset,
41+
},
42+
}
43+
}

packages/@vuepress/plugin-back-to-top/src/node/backToTopPlugin.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,24 @@ import { path } from '@vuepress/utils'
33

44
export type BackToTopPluginOptions = Record<never, never>
55

6-
export const backToTopPlugin: Plugin<BackToTopPluginOptions> = {
7-
name: '@vuepress/plugin-back-to-top',
6+
export const backToTopPlugin: Plugin<BackToTopPluginOptions> = (_, app) => {
7+
if (app.env.isDev && app.options.bundler.endsWith('vite')) {
8+
app.options.bundlerConfig.viteOptions = require('vite').mergeConfig(
9+
app.options.bundlerConfig.viteOptions,
10+
{
11+
optimizeDeps: {
12+
exclude: ['ts-debounce'],
13+
},
14+
}
15+
)
16+
}
817

9-
clientAppRootComponentFiles: path.resolve(
10-
__dirname,
11-
'../client/BackToTop.vue'
12-
),
18+
return {
19+
name: '@vuepress/plugin-back-to-top',
20+
21+
clientAppRootComponentFiles: path.resolve(
22+
__dirname,
23+
'../client/BackToTop.vue'
24+
),
25+
}
1326
}

packages/@vuepress/plugin-medium-zoom/src/node/mediumZoomPlugin.ts

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,35 @@ export interface MediumZoomPluginOptions {
88
delay?: number
99
}
1010

11-
export const mediumZoomPlugin: Plugin<MediumZoomPluginOptions> = ({
12-
selector = ':not(a) > img',
13-
zoomOptions = {},
14-
delay = 500,
15-
}) => ({
16-
name: '@vuepress/plugin-medium-zoom',
11+
export const mediumZoomPlugin: Plugin<MediumZoomPluginOptions> = (
12+
{ selector = ':not(a) > img', zoomOptions = {}, delay = 500 },
13+
app
14+
) => {
15+
if (app.env.isDev && app.options.bundler.endsWith('vite')) {
16+
app.options.bundlerConfig.viteOptions = require('vite').mergeConfig(
17+
app.options.bundlerConfig.viteOptions,
18+
{
19+
optimizeDeps: {
20+
exclude: ['medium-zoom'],
21+
},
22+
}
23+
)
24+
}
1725

18-
clientAppEnhanceFiles: path.resolve(
19-
__dirname,
20-
'../client/clientAppEnhance.js'
21-
),
26+
return {
27+
name: '@vuepress/plugin-medium-zoom',
2228

23-
define: {
24-
__MZ_SELECTOR__: selector,
25-
__MZ_ZOOM_OPTIONS__: zoomOptions,
26-
__MZ_DELAY__: delay,
27-
},
28-
})
29+
clientAppEnhanceFiles: path.resolve(
30+
__dirname,
31+
'../client/clientAppEnhance.js'
32+
),
33+
34+
define: {
35+
__MZ_SELECTOR__: selector,
36+
__MZ_ZOOM_OPTIONS__: zoomOptions,
37+
__MZ_DELAY__: delay,
38+
},
39+
}
40+
}
2941

3042
export default mediumZoomPlugin

packages/@vuepress/plugin-nprogress/src/node/nprogressPlugin.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import { path } from '@vuepress/utils'
33

44
export type NprogressPluginOptions = Record<never, never>
55

6-
export const nprogressPlugin: Plugin<NprogressPluginOptions> = {
7-
name: '@vuepress/plugin-nprogress',
6+
export const nprogressPlugin: Plugin<NprogressPluginOptions> = (_, app) => {
7+
if (app.env.isDev && app.options.bundler.endsWith('vite')) {
8+
app.options.bundlerConfig.viteOptions = require('vite').mergeConfig(
9+
app.options.bundlerConfig.viteOptions,
10+
{
11+
optimizeDeps: {
12+
include: ['nprogress'],
13+
},
14+
}
15+
)
16+
}
817

9-
clientAppSetupFiles: path.resolve(__dirname, '../client/clientAppSetup.js'),
18+
return {
19+
name: '@vuepress/plugin-nprogress',
1020

11-
onInitialized(app) {
12-
if (app.options.bundler.endsWith('vite')) {
13-
app.options.bundlerConfig.viteOptions = require('vite').mergeConfig(
14-
app.options.bundlerConfig.viteOptions,
15-
{
16-
optimizeDeps: {
17-
include: ['nprogress'],
18-
},
19-
}
20-
)
21-
}
22-
},
21+
clientAppSetupFiles: path.resolve(__dirname, '../client/clientAppSetup.js'),
22+
}
2323
}

0 commit comments

Comments
 (0)