In my "personal page" project I'm using NuxtJS, with it's @nuxt/content
module for content and Vuetify UI framework.
Recently found a problem: Vuetify component inside markdown files are not rendered when generating static site, but rendered correctly when running project in development mode. I've checked for issues in @nuxt/content about this problem and found 2 issues: #221 and #700
Mainly discussion was inside issue #221.
Shortly as I understand from issue:
Vuetify loader doesn't check content of markdown files, that's why while running nuxt generate
Vuetify components(that may be used in any component without import) are not rendered while used inside markdown files.
At nuxt dev
mode Vuetify component are rendered correctly because treeshake is disabled for development mode
Inside markdown file I used only one component - <v-alert>
, so finaly solution was next:
import Vue from 'vue'
import { VAlert } from 'vuetify/lib'
Vue.component('VAlert', VAlert)
I need to use this code at page which will display markdown files content. With it nuxt generate
result is what I want - Vuetify component successfully rendered if used inside markdown file.
But this code also bring one problem: if I running it with nuxt dev
I'm getting error Unexpected token 'export'
when I visit page that displays markdown with Vuetify components.
Finally the question is: How to remove these imports from page with template for showing markdown content? Probably something like "conditional import" (make these imports executed only when running nuxt generate
) or anything else?
Of course I can comment/uncomment each time I run project in development mode, but I'm not sure it's the right way.