diff --git a/docs/add-this/src/.vuepress/config.ts b/docs/add-this/src/.vuepress/config.ts index 1927e040a242..ea3adfa6f301 100644 --- a/docs/add-this/src/.vuepress/config.ts +++ b/docs/add-this/src/.vuepress/config.ts @@ -203,22 +203,31 @@ export default defineHopeConfig({ plugins: [ ["add-this", { pubid: "ra-5f829c59e6c6bc9a" }], - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/blog2/src/.vuepress/config.ts b/docs/blog2/src/.vuepress/config.ts index d122c7e9d21a..c8b30bcad53d 100644 --- a/docs/blog2/src/.vuepress/config.ts +++ b/docs/blog2/src/.vuepress/config.ts @@ -171,22 +171,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/comment2/src/.vuepress/config.ts b/docs/comment2/src/.vuepress/config.ts index 232335d27677..e8371a2647c2 100644 --- a/docs/comment2/src/.vuepress/config.ts +++ b/docs/comment2/src/.vuepress/config.ts @@ -248,22 +248,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/components/src/.vuepress/config.ts b/docs/components/src/.vuepress/config.ts index 239beef646bd..844a5468377d 100644 --- a/docs/components/src/.vuepress/config.ts +++ b/docs/components/src/.vuepress/config.ts @@ -194,22 +194,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/copy-code2/src/.vuepress/config.ts b/docs/copy-code2/src/.vuepress/config.ts index 0a37ef45da7b..5ebd5f464480 100644 --- a/docs/copy-code2/src/.vuepress/config.ts +++ b/docs/copy-code2/src/.vuepress/config.ts @@ -203,22 +203,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/feed2/src/.vuepress/config.ts b/docs/feed2/src/.vuepress/config.ts index 0a6174e02e47..6d1d659d1009 100644 --- a/docs/feed2/src/.vuepress/config.ts +++ b/docs/feed2/src/.vuepress/config.ts @@ -231,22 +231,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/lightgallery/src/.vuepress/config.ts b/docs/lightgallery/src/.vuepress/config.ts index 4c78a760f5da..4a19846c815c 100644 --- a/docs/lightgallery/src/.vuepress/config.ts +++ b/docs/lightgallery/src/.vuepress/config.ts @@ -177,22 +177,31 @@ export default defineHopeConfig({ plugins: [ ["lightgallery", { selector: ".theme-hope-content :not(a) > img" }], - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/md-enhance/src/.vuepress/config.ts b/docs/md-enhance/src/.vuepress/config.ts index 87845bd8bfbb..868fe7ce79eb 100644 --- a/docs/md-enhance/src/.vuepress/config.ts +++ b/docs/md-enhance/src/.vuepress/config.ts @@ -351,22 +351,31 @@ export default defineHopeConfig({ }, }, ], - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/photo-swipe/src/.vuepress/config.ts b/docs/photo-swipe/src/.vuepress/config.ts index 0f6c18ca7f27..a5d4bd18674d 100644 --- a/docs/photo-swipe/src/.vuepress/config.ts +++ b/docs/photo-swipe/src/.vuepress/config.ts @@ -203,22 +203,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/pwa2/src/.vuepress/config.ts b/docs/pwa2/src/.vuepress/config.ts index 67f190dab513..fe69aeaccbee 100644 --- a/docs/pwa2/src/.vuepress/config.ts +++ b/docs/pwa2/src/.vuepress/config.ts @@ -200,22 +200,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/reading-time2/src/.vuepress/config.ts b/docs/reading-time2/src/.vuepress/config.ts index 4b2925dfbab1..f858e8f645d0 100644 --- a/docs/reading-time2/src/.vuepress/config.ts +++ b/docs/reading-time2/src/.vuepress/config.ts @@ -142,22 +142,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/sass-palette/src/.vuepress/config.ts b/docs/sass-palette/src/.vuepress/config.ts index e6dfb4be135b..339f9db6413c 100644 --- a/docs/sass-palette/src/.vuepress/config.ts +++ b/docs/sass-palette/src/.vuepress/config.ts @@ -174,22 +174,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/seo2/src/.vuepress/config.ts b/docs/seo2/src/.vuepress/config.ts index f894908c7e00..943973b5d237 100644 --- a/docs/seo2/src/.vuepress/config.ts +++ b/docs/seo2/src/.vuepress/config.ts @@ -199,22 +199,31 @@ export default defineHopeConfig({ }, plugins: [ - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/docs/theme/src/.vuepress/config.ts b/docs/theme/src/.vuepress/config.ts index baa101f7b2f0..8c89e1d88001 100644 --- a/docs/theme/src/.vuepress/config.ts +++ b/docs/theme/src/.vuepress/config.ts @@ -214,23 +214,32 @@ export default defineHopeConfig({ }, }, ], - (_options, app) => { - addViteOptimizeDepsInclude(app, [ - "axios", - "three", - "three/examples/jsm/controls/OrbitControls", - "three/examples/jsm/loaders/STLLoader", - ]); - - return { - name: "theme-enhance", - alias: { - "@theme-hope/components/HomeHero": path.resolve( - __dirname, - "./components/HopeHero" - ), - }, - }; + { + name: "theme-enhance", + alias: { + "@theme-hope/components/HomeHero": path.resolve( + __dirname, + "./components/HopeHero" + ), + }, + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + + addViteOptimizeDepsInclude(app, [ + "axios", + "three", + "three/examples/jsm/controls/OrbitControls", + "three/examples/jsm/loaders/STLLoader", + ]); + }, }, ], }); diff --git a/packages/add-this/src/node/plugin.ts b/packages/add-this/src/node/plugin.ts index 25f218bcb43d..51f9a87d2baf 100644 --- a/packages/add-this/src/node/plugin.ts +++ b/packages/add-this/src/node/plugin.ts @@ -10,8 +10,8 @@ import type { AddThisOptions } from "../shared"; /** * `vuepress-plugin-add-this` Plugin */ -export const addThisPlugin: Plugin = (options, app) => { - if (!options.pubid) { +export const addThisPlugin: Plugin = ({ pubid }) => { + if (!pubid) { console.error("[AddThis]: Please provide a pubid to let plugin work"); return { @@ -19,22 +19,22 @@ export const addThisPlugin: Plugin = (options, app) => { }; } - addViteSsrNoExternal(app, "vuepress-plugin-add-this"); - addViteOptimizeDepsExclude(app, "vuepress-plugin-add-this"); - return { name: "vuepress-plugin-add-this", - define: { - PUB_ID: options.pubid, - }, + define: () => ({ PUB_ID: pubid }), - globalUIComponents: "AddThis", + onInitialized: (app): void => { + addViteSsrNoExternal(app, "vuepress-plugin-add-this"); + addViteOptimizeDepsExclude(app, "vuepress-plugin-add-this"); + }, clientAppRootComponentFiles: path.resolve( __dirname, "../client/root-components/AddThis.js" ), + + globalUIComponents: "AddThis", }; }; diff --git a/packages/blog2/__tests__/demo/.vuepress/config.ts b/packages/blog2/__tests__/demo/.vuepress/config.ts index 7e77f09e7a06..1dd7077085a0 100644 --- a/packages/blog2/__tests__/demo/.vuepress/config.ts +++ b/packages/blog2/__tests__/demo/.vuepress/config.ts @@ -1,9 +1,10 @@ +import { addViteOptimizeDepsInclude } from "@mr-hope/vuepress-shared"; import { defineUserConfig } from "@vuepress/cli"; import { blog } from "vuepress-plugin-blog2"; import type { DefaultThemeOptions } from "@vuepress/theme-default"; export default defineUserConfig({ - base: process.env.VuePress_BASE || "/", + base: "/", dest: "./dist", locales: { @@ -56,5 +57,19 @@ export default defineUserConfig({ }, ], }), + { + name: "enhance", + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + }, + }, ], }); diff --git a/packages/blog2/src/node/plugin.ts b/packages/blog2/src/node/plugin.ts index 85fb4b02c24e..73ddaa277d57 100644 --- a/packages/blog2/src/node/plugin.ts +++ b/packages/blog2/src/node/plugin.ts @@ -1,6 +1,5 @@ import { addViteSsrNoExternal, - addViteOptimizeDepsInclude, addViteOptimizeDepsExclude, } from "@mr-hope/vuepress-shared"; import { @@ -17,16 +16,7 @@ import { getPageMap, logger } from "./utils"; import type { Plugin, PluginConfig } from "@vuepress/core"; import type { BlogOptions } from "../shared"; -export const blogPlugin: Plugin = (options, app) => { - if (app.env.isDev) - addViteOptimizeDepsInclude(app, "@mr-hope/vuepress-shared/lib/client"); - - addViteSsrNoExternal(app, [ - "@mr-hope/vuepress-shared", - "vuepress-plugin-blog2", - ]); - addViteOptimizeDepsExclude(app, "vuepress-plugin-blog2"); - +export const blogPlugin: Plugin = (options) => { const { metaScope = "_blog" } = options; let generatePageKeys: string[] = []; @@ -38,7 +28,7 @@ export const blogPlugin: Plugin = (options, app) => { BLOG_META_SCOPE: metaScope, }), - extendsPage(page): void { + extendsPage: (page): void => { const { getInfo = (): Record => ({}) } = options; page.routeMeta = { @@ -47,7 +37,13 @@ export const blogPlugin: Plugin = (options, app) => { }; }, - onInitialized(app): Promise { + onInitialized: (app): Promise => { + addViteSsrNoExternal(app, [ + "@mr-hope/vuepress-shared", + "vuepress-plugin-blog2", + ]); + addViteOptimizeDepsExclude(app, "vuepress-plugin-blog2"); + const pageMap = getPageMap(options, app); return Promise.all([ @@ -62,7 +58,7 @@ export const blogPlugin: Plugin = (options, app) => { }); }, - onWatched(app, watchers): void { + onWatched: (app, watchers): void => { if (options.hotReload) { const pageDataWatcher = chokidar.watch("pages/**/*.js", { cwd: app.dir.temp(), diff --git a/packages/comment2/__tests__/demo/.vuepress/config.ts b/packages/comment2/__tests__/demo/.vuepress/config.ts index f10c9c35968b..41a623077c33 100644 --- a/packages/comment2/__tests__/demo/.vuepress/config.ts +++ b/packages/comment2/__tests__/demo/.vuepress/config.ts @@ -1,10 +1,10 @@ +import { addViteOptimizeDepsInclude } from "@mr-hope/vuepress-shared"; import { defineUserConfig } from "@vuepress/cli"; import { path } from "@vuepress/utils"; import type { DefaultThemeOptions } from "@vuepress/theme-default"; export default defineUserConfig({ - base: process.env.VuePress_BASE || "/", - + base: "/", title: "Comment Plugin", description: "Comment Plugin for VuePress", @@ -26,4 +26,21 @@ export default defineUserConfig({ }, ], }, + + plugins: [ + { + name: "enhance", + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + }, + }, + ], }); diff --git a/packages/comment2/src/node/plugin.ts b/packages/comment2/src/node/plugin.ts index 8d75fa1a75f4..3d03aded8435 100644 --- a/packages/comment2/src/node/plugin.ts +++ b/packages/comment2/src/node/plugin.ts @@ -11,7 +11,7 @@ import { useSassPalettePlugin } from "vuepress-plugin-sass-palette"; import { walineLocales } from "./locales"; import type { CommentOptions } from "../shared"; -import type { Plugin, PluginConfig, PluginObject } from "@vuepress/core"; +import type { Plugin, PluginConfig } from "@vuepress/core"; /** Comment Plugin */ export const commentPlugin: Plugin = (options, app) => { @@ -24,23 +24,14 @@ export const commentPlugin: Plugin = (options, app) => { // remove locales so that they won't be injected in client twice if ("walineLocales" in options) delete options.walineLocales; - if (app.env.isDev) - addViteOptimizeDepsInclude(app, "@mr-hope/vuepress-shared/lib/client"); - - addViteSsrNoExternal(app, [ - "@mr-hope/vuepress-shared", - "vuepress-plugin-comment2", - ]); - addViteOptimizeDepsExclude(app, "vuepress-plugin-comment2"); - - if (isWaline) { - addViteOptimizeDepsInclude(app, "@waline/client"); - addViteSsrExternal(app, "@waline/client"); - } - useSassPalettePlugin(app, { id: "hope" }); - const config: PluginObject = { + // TODO: Wait for Vssue to support vue3 + // if (options.type === "vssue") + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + // app.use("@vssue/vuepress-plugin-vssue", options); + + return { name: "vuepress-plugin-comment2", alias: { @@ -54,15 +45,21 @@ export const commentPlugin: Plugin = (options, app) => { WALINE_LOCALES: userWalineLocales, }), - clientAppEnhanceFiles: path.resolve(__dirname, "../client/appEnhance.js"), - }; + onInitialized: (app): void => { + addViteSsrNoExternal(app, [ + "@mr-hope/vuepress-shared", + "vuepress-plugin-comment2", + ]); + addViteOptimizeDepsExclude(app, "vuepress-plugin-comment2"); - // TODO: Wait for Vssue to support vue3 - // if (options.type === "vssue") - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - // config.plugins!.push(["@vssue/vuepress-plugin-vssue", options]); + if (isWaline) { + addViteOptimizeDepsInclude(app, "@waline/client"); + addViteSsrExternal(app, "@waline/client"); + } + }, - return config; + clientAppEnhanceFiles: path.resolve(__dirname, "../client/appEnhance.js"), + }; }; export const comment = ( diff --git a/packages/components/src/node/plugins.ts b/packages/components/src/node/plugins.ts index 4e3578031b30..1adab4014174 100644 --- a/packages/components/src/node/plugins.ts +++ b/packages/components/src/node/plugins.ts @@ -17,18 +17,6 @@ import type { Plugin, PluginConfig } from "@vuepress/core"; import type { ComponentOptions } from "../shared"; export const componentsPlugin: Plugin = (options, app) => { - if (app.env.isDev) - addViteOptimizeDepsInclude(app, "@mr-hope/vuepress-shared/lib/client"); - - addViteSsrNoExternal(app, [ - "@mr-hope/vuepress-shared", - "@mr-hope/vuepress-plugin-components", - ]); - addViteOptimizeDepsExclude(app, "@mr-hope/vuepress-plugin-components"); - - if (options.backToTop) addViteOptimizeDepsInclude(app, "lodash.debounce"); - if (options.fullScreen) addViteOptimizeDepsInclude(app, "@vueuse/core"); - useSassPalettePlugin(app, { id: "hope" }); return { @@ -74,6 +62,17 @@ export const componentsPlugin: Plugin = (options, app) => { ), }, + onInitialized: (app): void => { + addViteSsrNoExternal(app, [ + "@mr-hope/vuepress-shared", + "@mr-hope/vuepress-plugin-components", + ]); + addViteOptimizeDepsExclude(app, "@mr-hope/vuepress-plugin-components"); + + if (options.backToTop) addViteOptimizeDepsInclude(app, "lodash.debounce"); + if (options.fullScreen) addViteOptimizeDepsInclude(app, "@vueuse/core"); + }, + clientAppEnhanceFiles: path.resolve(__dirname, "../client/appEnhance.js"), clientAppRootComponentFiles: options.backToTop diff --git a/packages/copy-code2/__tests__/demo/.vuepress/config.ts b/packages/copy-code2/__tests__/demo/.vuepress/config.ts index c2fd0e69cb3d..fdba6a9a067e 100644 --- a/packages/copy-code2/__tests__/demo/.vuepress/config.ts +++ b/packages/copy-code2/__tests__/demo/.vuepress/config.ts @@ -1,9 +1,9 @@ +import { addViteOptimizeDepsInclude } from "@mr-hope/vuepress-shared"; import { defineUserConfig } from "@vuepress/cli"; import type { DefaultThemeOptions } from "@vuepress/theme-default"; export default defineUserConfig({ - base: process.env.VuePress_BASE || "/", - + base: "/", title: "Copy Code", description: "VuePress 的复制代码插件", @@ -41,5 +41,21 @@ export default defineUserConfig({ }, }, - plugins: ["copy-code2"], + plugins: [ + "copy-code2", + { + name: "enhance", + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + }, + }, + ], }); diff --git a/packages/copy-code2/src/node/plugin.ts b/packages/copy-code2/src/node/plugin.ts index cd8a3c194050..25b91610b8c7 100644 --- a/packages/copy-code2/src/node/plugin.ts +++ b/packages/copy-code2/src/node/plugin.ts @@ -1,7 +1,6 @@ import { addViteSsrNoExternal, addViteOptimizeDepsExclude, - addViteOptimizeDepsInclude, getLocales, } from "@mr-hope/vuepress-shared"; import { path } from "@vuepress/utils"; @@ -12,15 +11,6 @@ import type { Plugin, PluginConfig } from "@vuepress/core"; import type { CopyCodeOptions } from "../shared"; export const copyCodePlugin: Plugin = (options, app) => { - if (app.env.isDev) - addViteOptimizeDepsInclude(app, "@mr-hope/vuepress-shared/lib/client"); - - addViteSsrNoExternal(app, [ - "@mr-hope/vuepress-shared", - "vuepress-plugin-copy-code2", - ]); - addViteOptimizeDepsExclude(app, "vuepress-plugin-copy-code2"); - useSassPalettePlugin(app, { id: "hope" }); return { @@ -31,6 +21,14 @@ export const copyCodePlugin: Plugin = (options, app) => { CODE_COPY_LOCALES: getLocales(app, copyCodeLocales, options.locales), }), + onInitialized: (app): void => { + addViteSsrNoExternal(app, [ + "@mr-hope/vuepress-shared", + "vuepress-plugin-copy-code2", + ]); + addViteOptimizeDepsExclude(app, "vuepress-plugin-copy-code2"); + }, + clientAppSetupFiles: path.resolve(__dirname, "../client/appSetup.js"), }; }; diff --git a/packages/feed2/src/node/plugin.ts b/packages/feed2/src/node/plugin.ts index 6774fa5c4f36..7fc027688466 100644 --- a/packages/feed2/src/node/plugin.ts +++ b/packages/feed2/src/node/plugin.ts @@ -33,11 +33,9 @@ export const feedPlugin: Plugin = (options, app) => { return { name: "vuepress-plugin-feed2", - onPrepared(): void { - injectLinkstoHead(app, feedOptions); - }, + onPrepared: (app): void => injectLinkstoHead(app, feedOptions), - async onGenerated(app): Promise { + onGenerated: async (app): Promise => { const { filter = ({ frontmatter, filePathRelative }: Page): boolean => !( diff --git a/packages/lightgallery/__tests__/demo/.vuepress/config.ts b/packages/lightgallery/__tests__/demo/.vuepress/config.ts index 751b6dd742d8..f4fcdd44220d 100644 --- a/packages/lightgallery/__tests__/demo/.vuepress/config.ts +++ b/packages/lightgallery/__tests__/demo/.vuepress/config.ts @@ -1,8 +1,9 @@ +import { addViteOptimizeDepsInclude } from "@mr-hope/vuepress-shared"; import { defineUserConfig } from "@vuepress/cli"; import type { DefaultThemeOptions } from "@vuepress/theme-default"; export default defineUserConfig({ - base: process.env.VuePress_BASE || "/", + base: "/", bundler: process.env.BUNDLER ?? "@vuepress/webpack", head: [ ["link", { rel: "icon", href: "/favicon.ico" }], @@ -30,5 +31,21 @@ export default defineUserConfig({ }, }, - plugins: [["lightgallery", { plugins: ["video"] }]], + plugins: [ + ["lightgallery", { plugins: ["video"] }], + { + name: "enhance", + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + }, + }, + ], }); diff --git a/packages/lightgallery/src/node/plugin.ts b/packages/lightgallery/src/node/plugin.ts index 5c4cfd498fca..f7a3e8a24636 100644 --- a/packages/lightgallery/src/node/plugin.ts +++ b/packages/lightgallery/src/node/plugin.ts @@ -15,14 +15,6 @@ export const lightgalleryPlugin: Plugin = ( ) => { const plugins = options.plugins || ["pager", "share", "zoom"]; - addViteOptimizeDepsInclude(app, [ - "lightgallery", - ...plugins.map((name) => `lightgallery/plugins/${name}`), - ]); - - addViteSsrNoExternal(app, "vuepress-plugin-lightgallery"); - addViteOptimizeDepsExclude(app, "vuepress-plugin-lightgallery"); - useSassPalettePlugin(app, { id: "hope" }); return { @@ -42,6 +34,16 @@ export const lightgalleryPlugin: Plugin = ( LIGHT_GALLERY_ZOOM: plugins.includes("zoom"), }), + onInitialized: (app): void => { + addViteOptimizeDepsInclude(app, [ + "lightgallery", + ...plugins.map((name) => `lightgallery/plugins/${name}`), + ]); + + addViteSsrNoExternal(app, "vuepress-plugin-lightgallery"); + addViteOptimizeDepsExclude(app, "vuepress-plugin-lightgallery"); + }, + clientAppRootComponentFiles: path.resolve( __dirname, "../client/root-components/LightGallery.js" diff --git a/packages/md-enhance/__tests__/demo/.vuepress/config.ts b/packages/md-enhance/__tests__/demo/.vuepress/config.ts index 46528c1bcd9d..c131fa9617cd 100644 --- a/packages/md-enhance/__tests__/demo/.vuepress/config.ts +++ b/packages/md-enhance/__tests__/demo/.vuepress/config.ts @@ -1,3 +1,4 @@ +import { addViteOptimizeDepsInclude } from "@mr-hope/vuepress-shared"; import { defineUserConfig } from "@vuepress/cli"; import type { DefaultThemeOptions } from "@vuepress/theme-default"; @@ -102,5 +103,19 @@ export default defineUserConfig({ }, }, ], + { + name: "enhance", + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + }, + }, ], }); diff --git a/packages/md-enhance/src/node/plugin.ts b/packages/md-enhance/src/node/plugin.ts index d654094f206d..c13aef47ac17 100644 --- a/packages/md-enhance/src/node/plugin.ts +++ b/packages/md-enhance/src/node/plugin.ts @@ -47,38 +47,6 @@ export const mdEnhancePlugin: Plugin = ( ? options.presentation.plugins : []; - if (app.env.isDev) - addViteOptimizeDepsInclude(app, "@mr-hope/vuepress-shared/lib/client"); - - addViteSsrNoExternal(app, [ - "@mr-hope/vuepress-shared", - "vuepress-plugin-md-enhance", - ]); - addViteOptimizeDepsExclude(app, "vuepress-plugin-md-enhance"); - - if (flowchartEnable) { - addViteOptimizeDepsInclude(app, "flowchart.js"); - addViteSsrExternal(app, "flowchart.js"); - } - - if (mermaidEnable) { - addViteOptimizeDepsInclude(app, "mermaid"); - addViteSsrExternal(app, "mermaid"); - } - - if (presentationEnable) { - addViteOptimizeDepsInclude(app, [ - "reveal.js/dist/reveal.esm.js", - "reveal.js/plugin/markdown/markdown.esm.js", - "reveal.js/plugin/highlight/highlight.esm.js", - "reveal.js/plugin/math/math.esm.js", - "reveal.js/plugin/search/search.esm.js", - "reveal.js/plugin/notes/notes.esm.js", - "reveal.js/plugin/zoom/zoom.esm.js", - ]); - addViteSsrExternal(app, "reveal.js"); - } - useSassPalettePlugin(app, { id: "hope" }); usePlugins(app, options); @@ -129,13 +97,6 @@ export const mdEnhancePlugin: Plugin = ( REVEAL_PLUGIN_ZOOM: revealPlugins.includes("zoom"), }), - ...(demoEnable - ? { - clientAppSetupFiles: path.resolve(__dirname, "../client/appSetup.js"), - } - : {}), - clientAppEnhanceFiles: path.resolve(__dirname, "../client/appEnhance.js"), - extendsMarkdown: (markdownIt): void => { if (options.lazyLoad || options.enableAll) markdownIt.use(lazyLoad); @@ -161,6 +122,42 @@ export const mdEnhancePlugin: Plugin = ( }); if (presentationEnable) markdownIt.use(presentation); }, + + onInitialized: (app): void => { + addViteSsrNoExternal(app, [ + "@mr-hope/vuepress-shared", + "vuepress-plugin-md-enhance", + ]); + addViteOptimizeDepsExclude(app, "vuepress-plugin-md-enhance"); + + if (flowchartEnable) { + addViteOptimizeDepsInclude(app, "flowchart.js"); + addViteSsrExternal(app, "flowchart.js"); + } + + if (mermaidEnable) { + addViteOptimizeDepsInclude(app, "mermaid"); + addViteSsrExternal(app, "mermaid"); + } + + if (presentationEnable) { + addViteOptimizeDepsInclude(app, [ + "reveal.js/dist/reveal.esm.js", + ...revealPlugins.map( + (plugin) => `reveal.js/plugin/${plugin}/${plugin}.esm.js` + ), + ]); + addViteSsrExternal(app, "reveal.js"); + } + }, + + clientAppEnhanceFiles: path.resolve(__dirname, "../client/appEnhance.js"), + + ...(demoEnable + ? { + clientAppSetupFiles: path.resolve(__dirname, "../client/appSetup.js"), + } + : {}), }; }; diff --git a/packages/photo-swipe/__tests__/demo/.vuepress/config.ts b/packages/photo-swipe/__tests__/demo/.vuepress/config.ts index 76de41d7f95b..d861e0c6e855 100644 --- a/packages/photo-swipe/__tests__/demo/.vuepress/config.ts +++ b/packages/photo-swipe/__tests__/demo/.vuepress/config.ts @@ -1,8 +1,9 @@ +import { addViteOptimizeDepsInclude } from "@mr-hope/vuepress-shared"; import { defineUserConfig } from "@vuepress/cli"; import type { DefaultThemeOptions } from "@vuepress/theme-default"; export default defineUserConfig({ - base: process.env.VuePress_BASE || "/", + base: "/", head: [ ["link", { rel: "icon", href: "/favicon.ico" }], @@ -30,5 +31,21 @@ export default defineUserConfig({ }, }, - plugins: ["photo-swipe"], + plugins: [ + "photo-swipe", + { + name: "enhance", + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + }, + }, + ], }); diff --git a/packages/photo-swipe/src/node/plugin.ts b/packages/photo-swipe/src/node/plugin.ts index 50f95d795c0b..2fd2a70f2263 100644 --- a/packages/photo-swipe/src/node/plugin.ts +++ b/packages/photo-swipe/src/node/plugin.ts @@ -1,10 +1,10 @@ -import { path } from "@vuepress/utils"; import { addViteOptimizeDepsInclude, addViteSsrNoExternal, getLocales, addViteOptimizeDepsExclude, } from "@mr-hope/vuepress-shared"; +import { path } from "@vuepress/utils"; import { useSassPalettePlugin } from "vuepress-plugin-sass-palette"; import { photoSwipeLocales } from "./locales"; @@ -12,20 +12,6 @@ import type { Plugin, PluginConfig } from "@vuepress/core"; import type { PhotoSwipeOptions } from "../shared"; export const photoSwipePlugin: Plugin = (options, app) => { - addViteOptimizeDepsInclude(app, [ - "photoswipe", - "photoswipe/dist/photoswipe-ui-default", - ]); - - if (app.env.isDev) - addViteOptimizeDepsInclude(app, "@mr-hope/vuepress-shared/lib/client"); - - addViteSsrNoExternal(app, [ - "@mr-hope/vuepress-shared", - "vuepress-plugin-photo-swipe", - ]); - addViteOptimizeDepsExclude(app, "vuepress-plugin-photo-swipe"); - useSassPalettePlugin(app, { id: "hope" }); return { @@ -39,6 +25,19 @@ export const photoSwipePlugin: Plugin = (options, app) => { PHOTO_SWIPE_OPTIONS: options.options || {}, }), + onInitialized: (app): void => { + addViteOptimizeDepsInclude(app, [ + "photoswipe", + "photoswipe/dist/photoswipe-ui-default", + ]); + + addViteSsrNoExternal(app, [ + "@mr-hope/vuepress-shared", + "vuepress-plugin-photo-swipe", + ]); + addViteOptimizeDepsExclude(app, "vuepress-plugin-photo-swipe"); + }, + clientAppRootComponentFiles: path.resolve( __dirname, "../client/root-components/ImageViewer.js" diff --git a/packages/pwa2/__tests__/demo/.vuepress/config.ts b/packages/pwa2/__tests__/demo/.vuepress/config.ts index a5f2772e1b7d..22d395b7dba1 100644 --- a/packages/pwa2/__tests__/demo/.vuepress/config.ts +++ b/packages/pwa2/__tests__/demo/.vuepress/config.ts @@ -1,8 +1,9 @@ +import { addViteOptimizeDepsInclude } from "@mr-hope/vuepress-shared"; import { defineUserConfig } from "@vuepress/cli"; import type { DefaultThemeOptions } from "@vuepress/theme-default"; export default defineUserConfig({ - base: process.env.VuePress_BASE || "/", + base: "/", locales: { "/": { @@ -26,5 +27,21 @@ export default defineUserConfig({ }, }, - plugins: [["pwa2"]], + plugins: [ + "pwa2", + { + name: "enhance", + onInitialized: (app) => { + if (app.env.isDev) + addViteOptimizeDepsInclude(app, [ + "@mr-hope/vuepress-shared/lib/client", + "dayjs", + "dayjs/plugin/localizedFormat", + "dayjs/plugin/objectSupport", + "dayjs/plugin/timezone", + "dayjs/plugin/utc", + ]); + }, + }, + ], }); diff --git a/packages/pwa2/src/node/plugin.ts b/packages/pwa2/src/node/plugin.ts index 089b7db4e821..69da39b94b68 100644 --- a/packages/pwa2/src/node/plugin.ts +++ b/packages/pwa2/src/node/plugin.ts @@ -12,7 +12,7 @@ import { injectLinkstoHead } from "./injectHead"; import { getManifest, genManifest } from "./genManifest"; import { genServiceWorker } from "./genServiceWorker"; -import type { Plugin, PluginConfig, PluginObject } from "@vuepress/core"; +import type { Plugin, PluginConfig } from "@vuepress/core"; import type { PWAOptions } from "../shared"; import { appendBase } from "./helper"; @@ -23,29 +23,11 @@ export const pwaPlugin: Plugin = (options, app) => { const manifest = getManifest(app, options); - addViteOptimizeDepsInclude(app, ["mitt", "register-service-worker"]); - - if (app.env.isDev) - addViteOptimizeDepsInclude(app, "@mr-hope/vuepress-shared/lib/client"); - - addViteSsrNoExternal(app, [ - "@mr-hope/vuepress-shared", - "vuepress-plugin-pwa2", - ]); - addViteOptimizeDepsExclude(app, "vuepress-plugin-pwa2"); - - useCustomDevServer( - app, - "/manifest.webmanifest", - async () => JSON.stringify(await manifest), - "Unexpected manifest generate error" - ); - useSassPalettePlugin(app, { id: "hope" }); app.options.head = injectLinkstoHead(options, base, app.options.head); - const config: PluginObject = { + return { name: "vuepress-plugin-pwa2", define: () => ({ @@ -53,25 +35,38 @@ export const pwaPlugin: Plugin = (options, app) => { SW_PATH: options.swPath || "service-worker.js", }), + onInitialized: (app): void => { + addViteOptimizeDepsInclude(app, ["mitt", "register-service-worker"]); + + addViteSsrNoExternal(app, [ + "@mr-hope/vuepress-shared", + "vuepress-plugin-pwa2", + ]); + addViteOptimizeDepsExclude(app, "vuepress-plugin-pwa2"); + + useCustomDevServer( + app, + "/manifest.webmanifest", + async () => JSON.stringify(await manifest), + "Unexpected manifest generate error" + ); + }, + + onGenerated: async (app): Promise => { + await genManifest(app, manifest); + await genServiceWorker(app, options); + }, + clientAppRootComponentFiles: [ options.popupComponent || path.resolve(__dirname, "../client/global-components/SWUpdatePopup.js"), + ...(options.showInstall !== false + ? [path.resolve(__dirname, "../client/global-components/PWAInstall.js")] + : []), ], clientAppSetupFiles: path.resolve(__dirname, "../client/appSetup.js"), - - async onGenerated(): Promise { - await genManifest(app, manifest); - await genServiceWorker(app, options); - }, }; - - if (options.showInstall !== false) - (config.clientAppRootComponentFiles as string[]).push( - path.resolve(__dirname, "../client/global-components/PWAInstall.js") - ); - - return config; }; export const pwa = (options: PWAOptions | false): PluginConfig => [ diff --git a/packages/reading-time2/src/node/plugin.ts b/packages/reading-time2/src/node/plugin.ts index d591f4afee78..16c452158674 100644 --- a/packages/reading-time2/src/node/plugin.ts +++ b/packages/reading-time2/src/node/plugin.ts @@ -6,11 +6,11 @@ import type { Page, Plugin, PluginConfig } from "@vuepress/core"; import type { ReadingTime, ReadingTimeOptions } from "../shared"; /** Reading time plugin */ -export const readingTimePlugin: Plugin = (options, app) => { +export const readingTimePlugin: Plugin = (options) => { return { name: "vuepress-plugin-reading-time2", - define: (): Record => ({ + define: (app): Record => ({ READING_TIME_LOCALES: getLocales( app, readingTimeLocales, diff --git a/packages/sass-palette/src/node/plugin.ts b/packages/sass-palette/src/node/plugin.ts index 7d52f5edb648..98d4b98f58b5 100644 --- a/packages/sass-palette/src/node/plugin.ts +++ b/packages/sass-palette/src/node/plugin.ts @@ -33,8 +33,6 @@ export const sassPalettePlugin: Plugin = ( const userPalette = app.dir.source(palette); const userStyle = style ? app.dir.source(style) : null; - injectConfigModule(app, id); - return { name: `vuepress-plugin-sass-palette?${id}`, @@ -62,6 +60,8 @@ export const sassPalettePlugin: Plugin = ( }, onInitialized: (): Promise => { + injectConfigModule(app, id); + return Promise.all([ prepareLoadFile(app, id), prepareInjectFile(app, id), diff --git a/packages/seo2/src/node/plugin.ts b/packages/seo2/src/node/plugin.ts index c153c73a0b20..29a0c96b9ca8 100644 --- a/packages/seo2/src/node/plugin.ts +++ b/packages/seo2/src/node/plugin.ts @@ -12,7 +12,7 @@ import type { SeoOptions, } from "../shared"; -export const seoPlugin: Plugin = (options, app) => { +export const seoPlugin: Plugin = (options) => { if (!options.hostname) { logger.error("Option 'hostname' is required!"); @@ -22,7 +22,7 @@ export const seoPlugin: Plugin = (options, app) => { return { name: "vuepress-plugin-seo2", - extendsPage(page): void { + extendsPage: (page, app): void => { // generate summary if (!page.frontmatter.description) page.frontmatter.summary = @@ -59,9 +59,7 @@ export const seoPlugin: Plugin = (options, app) => { page.frontmatter.head = head; }, - async onGenerated(): Promise { - await generateRobotsTxt(app.dir); - }, + onGenerated: (app): Promise => generateRobotsTxt(app.dir), }; }; diff --git a/packages/sitemap2/src/node/plugin.ts b/packages/sitemap2/src/node/plugin.ts index 2dc7bd15fac5..4fc2b09224ab 100644 --- a/packages/sitemap2/src/node/plugin.ts +++ b/packages/sitemap2/src/node/plugin.ts @@ -4,7 +4,7 @@ import { generateSiteMap } from "./generateSitemap"; import type { Plugin, PluginConfig, PluginObject } from "@vuepress/core"; import type { SitemapOptions } from "../shared"; -export const sitemapPlugin: Plugin = (options, app) => { +export const sitemapPlugin: Plugin = (options) => { const plugin: PluginObject = { name: "vuepress-plugin-sitemap2", }; @@ -18,9 +18,8 @@ export const sitemapPlugin: Plugin = (options, app) => { return { ...plugin, - async onGenerated(): Promise { - await generateSiteMap(app, options as SitemapOptions); - }, + onGenerated: (app): Promise => + generateSiteMap(app, options as SitemapOptions), }; }; diff --git a/packages/theme/src/node/theme.ts b/packages/theme/src/node/theme.ts index 938adce47bc7..f897ff575be4 100644 --- a/packages/theme/src/node/theme.ts +++ b/packages/theme/src/node/theme.ts @@ -22,7 +22,6 @@ export const themeHope: Theme = ( ) => { const enableBlog = Boolean(plugins.blog); - updateBundlerOptions(app); handleThemeData(app, themeOptions); usePlugin(app, plugins); @@ -52,9 +51,10 @@ export const themeHope: Theme = ( app.env.isDev ), - async onPrepared(): Promise { - await writeThemeColorScss(app, themeOptions as HopeThemeConfig); - }, + onInitialized: (app): void => updateBundlerOptions(app), + + onPrepared: (): Promise => + writeThemeColorScss(app, themeOptions as HopeThemeConfig), plugins: getPluginConfig(app, plugins, themeOptions as HopeThemeConfig),