Skip to content

perf: improve webpack perf #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export default defineComponent({
const enableArtalk = computed(() => isString(artalkOptions.value.server))

const initArtalk = async (): Promise<void> => {
if (__VUEPRESS_SSR__) return

const [{ default: Artalk }] = await Promise.all([
import(/* webpackChunkName: "artalk" */ 'artalk/dist/Artalk.mjs'),
wait(artalkOptions.value.delay ?? 800),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ export default defineComponent({
)

onMounted(async () => {
if (__VUEPRESS_SSR__) return

await import(/* webpackChunkName: "giscus" */ 'giscus')
loaded.value = true
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export default defineComponent({
const enableTwikoo = computed(() => Boolean(twikooOptions.value.envId))

const initTwikoo = async (): Promise<void> => {
if (__VUEPRESS_SSR__) return

const [{ init }] = await Promise.all([
import(/* webpackChunkName: "twikoo" */ 'twikoo'),
wait(twikooOptions.value.delay ?? 800),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,17 @@ export const usePhotoSwipe = ({
)
}

useEventListener('click', initPhotoSwipe, { passive: true })
useEventListener('wheel', () => {
if (options.value.scrollToClose) photoSwipe?.close()
})

onMounted(() => {
if (__VUEPRESS_SSR__) return

const rIC =
'requestIdleCallback' in window ? window.requestIdleCallback : setTimeout

useEventListener('click', initPhotoSwipe, { passive: true })
useEventListener('wheel', () => {
if (options.value.scrollToClose) photoSwipe?.close()
})
rIC(() => {
photoSwipeLoader = import(
/* webpackChunkName: "photo-swipe" */ 'photoswipe'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { onMounted } from 'vue'

export const useKatexCopy = (): void => {
onMounted(async () => {
if (__VUEPRESS_SSR__) return

await import(
/* webpackChunkName: "katex" */ 'katex/dist/contrib/copy-tex.min.js'
)
Expand Down
3 changes: 2 additions & 1 deletion plugins/markdown/plugin-markdown-math/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"extends": "../../../tsconfig.build.json",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./lib"
"outDir": "./lib",
"types": ["vuepress/client-types", "vite/client", "webpack-env"]
},
"include": ["./src"],
"references": [{ "path": "../../../tools/helper/tsconfig.build.json" }]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ export const prepareRevealJsEntry = async (
await app.writeTemp(
'revealjs/index.js',
`\
export const useRevealJs = () => Promise.all([
import(/* webpackChunkName: "reveal" */ "${getModulePath(
'reveal.js/dist/reveal.esm.js',
import.meta,
)}").then(({ default: RevealJs }) => RevealJs),
import(/* webpackChunkName: "reveal" */ "${getModulePath(
'reveal.js/plugin/markdown/markdown.esm.js',
import.meta,
)}").then(({ default: plugin }) => plugin),
${revealPlugins
.map(
(plugin) =>
` import(/* webpackChunkName: "reveal" */ "${getModulePath(
`reveal.js/plugin/${plugin}/${plugin}.esm.js`,
import.meta,
)}").then(({ default: plugin }) => plugin)`,
)
.join(',\n')}
]);
export const useRevealJs = () => Promise.all(
__VUEPRESS_SSR__
? []
: [
import(/* webpackChunkName: "reveal" */ "${getModulePath(
'reveal.js/dist/reveal.esm.js',
import.meta,
)}").then(({ default: RevealJs }) => RevealJs),
import(/* webpackChunkName: "reveal" */ "${getModulePath(
'reveal.js/plugin/markdown/markdown.esm.js',
import.meta,
)}").then(({ default: plugin }) => plugin),
${revealPlugins
.map(
(plugin) =>
` import(/* webpackChunkName: "reveal" */ "${getModulePath(
`reveal.js/plugin/${plugin}/${plugin}.esm.js`,
import.meta,
)}").then(({ default: plugin }) => plugin)`,
)
.join(',\n')}
]
);
`,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export const DocSearch = defineComponent({
* Import docsearch js and initialize
*/
const initialize = async (): Promise<void> => {
if (__VUEPRESS_SSR__) return

const { default: docsearch } = await import('@docsearch/js')

const { searchParameters } = options.value
Expand Down
Loading