Skip to content

Commit

Permalink
fix: reduce final bundle size by setting plugins to false
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandros94 committed Apr 16, 2024
1 parent fae6654 commit 2aba34d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,26 @@ export default defineNuxtModule<ModuleOptions>({
from: resolve(runtimeDir, 'composables', 'use-nuxt-markdown'),
name: 'useNuxtMarkdown'
})

if (nuxtMarkdownOptions.component !== false)
addComponent({
filePath: resolve(runtimeDir, 'components', 'nuxt-markdown'),
global: options.global,
name: nuxtMarkdownOptions.component
})

nuxt.options.alias['#nuxt-markdown-render/anchor'] = nuxtMarkdownOptions.plugins.anchor !== false
? 'markdown-it-anchor'
: 'unenv/runtime/mock/empty'
nuxt.options.alias['#nuxt-markdown-render/github-alerts'] = nuxtMarkdownOptions.plugins.githubAlerts !== false
? 'markdown-it-github-alerts'
: 'unenv/runtime/mock/empty'
nuxt.options.alias['#nuxt-markdown-render/mdc'] = (nuxtMarkdownOptions.plugins.mdc !== false && nuxt.options.vue.runtimeCompiler)
? 'markdown-it-mdc'
: 'unenv/runtime/mock/empty'
nuxt.options.alias['#nuxt-markdown-render/shiki'] = nuxtMarkdownOptions.plugins.shiki !== false
? '@shikijs/markdown-it'
: 'unenv/runtime/mock/empty'
}
})

Expand Down
8 changes: 4 additions & 4 deletions src/runtime/plugins/nuxt-markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,25 @@ export default defineNuxtPlugin(async nuxtApp => {
}

if (mdc !== false && vueRuntimeCompiler)
md.use((await import('markdown-it-mdc').catch((err: any) => {
md.use((await import('#nuxt-markdown-render/mdc').catch((err: any) => {
// eslint-disable-next-line no-console
console.error('[nuxt-markdown-render]: `markdown-it-mdc` is an optional dependency for handling Markdown Components and is not properly installed. Please check your `package.json` or install it again.')
throw new Error(err)
})).default, mdc)
if (githubAlerts !== false)
md.use((await import('markdown-it-github-alerts').catch((err: any) => {
md.use((await import('#nuxt-markdown-render/github-alerts').catch((err: any) => {
// eslint-disable-next-line no-console
console.error('[nuxt-markdown-render]: `markdown-it-github-alerts` is an optional dependency to support Github styled Alerts and is not properly installed. Please check your `package.json` or install it again.')
throw new Error(err)
})).default, githubAlerts)
if (anchor !== false)
md.use((await import('markdown-it-anchor').catch((err: any) => {
md.use((await import('#nuxt-markdown-render/anchor').catch((err: any) => {
// eslint-disable-next-line no-console
console.error('[nuxt-markdown-render]: `markdown-it-anchor` is an optional dependency that adds id and other functionalities to headings and is not properly installed. Please check your `package.json` or install it again.')
throw new Error(err)
})).default, anchor)
if (shiki !== false && shiki !== undefined){
const shikiPlugin = (await import('@shikijs/markdown-it').catch((err: any) => {
const shikiPlugin = (await import('#nuxt-markdown-render/shiki').catch((err: any) => {
// eslint-disable-next-line no-console
console.error('[nuxt-markdown-render]: `@shikijs/markdown-it` is an optional dependency that provide powerful syntax highlight and is not properly installed. Please check your `package.json` or install it again.')
throw new Error(err)
Expand Down

0 comments on commit 2aba34d

Please sign in to comment.