Skip to content

Commit

Permalink
feat: 支持环境变量开关 markdown 渲染
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed Mar 5, 2022
1 parent 33cde40 commit 0a4401b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
VITE_APP_TITLE = Vite App 🦕


# markdown 渲染支持
VITE_APP_MARKDOWN = true


# 开发时 Inspect 调试支持
VITE_APP_INSPECT = true

Expand Down
19 changes: 19 additions & 0 deletions presets/plugins/markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { env } from './../shared/env'
import Prism from 'markdown-it-prism'
import Markdown from 'vite-plugin-md'

export const markdownWrapperClasses = env.VITE_APP_MARKDOWN
? 'prose md:prose-lg lg:prose-lg dark:prose-invert text-left p-10 prose-slate prose-img:rounded-xl prose-headings:underline prose-a:text-blue-600'
: ''

export default () => {
return (
env.VITE_APP_MARKDOWN &&
Markdown({
wrapperClasses: markdownWrapperClasses,
markdownItSetup(md) {
md.use(Prism)
}
})
)
}
2 changes: 2 additions & 0 deletions presets/shared/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const useEnv = () => {
const {
VITE_APP_TITLE,
VITE_APP_INSPECT,
VITE_APP_MARKDOWN,
VITE_APP_API_AUTO_IMPORT,
VITE_APP_MOCK_IN_PRODUCTION,
VITE_APP_DIR_API_AUTO_IMPORT,
Expand All @@ -31,6 +32,7 @@ const useEnv = () => {
VITE_APP_TITLE,
VITE_APP_COMPRESSINON_ALGORITHM,
VITE_APP_INSPECT: stringToBoolean(VITE_APP_INSPECT),
VITE_APP_MARKDOWN: stringToBoolean(VITE_APP_MARKDOWN),
VITE_APP_API_AUTO_IMPORT: stringToBoolean(
VITE_APP_API_AUTO_IMPORT
),
Expand Down
18 changes: 5 additions & 13 deletions presets/tov.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { markdownWrapperClasses } from './plugins/markdown'
import { resolve } from 'path'
import { env } from './shared/env'
import Vue from '@vitejs/plugin-vue'
import Prism from 'markdown-it-prism'
import Markdown from 'vite-plugin-md'
import Pages from 'vite-plugin-pages'
import Icons from 'unplugin-icons/vite'
import Inspect from 'vite-plugin-inspect'
import Markdown from './plugins/markdown'
import Windicss from 'vite-plugin-windicss'
import vueJsx from '@vitejs/plugin-vue-jsx'
import ViteRestart from 'vite-plugin-restart'
Expand All @@ -25,14 +25,11 @@ import {
ElementPlusResolver,
VueUseComponentsResolver
} from 'unplugin-vue-components/resolvers'
import OptimizationPersist from 'vite-plugin-optimize-persist'
import PkgConfig from 'vite-plugin-package-config'
import { GenerateTitle } from './plugins/html'
import { FixLayoutsHmr } from './plugins/layouts'
import PkgConfig from 'vite-plugin-package-config'
import { AutoImportResolvers } from './shared/resolvers'

const markdownWrapperClasses =
'prose md:prose-lg lg:prose-lg dark:prose-invert text-left p-10 prose-slate prose-img:rounded-xl prose-headings:underline prose-a:text-blue-600'
import OptimizationPersist from 'vite-plugin-optimize-persist'

export default () => {
return [
Expand All @@ -47,12 +44,7 @@ export default () => {
include: [/\.vue$/, /\.md$/]
}),
// markdown 编译插件
Markdown({
wrapperClasses: markdownWrapperClasses,
markdownItSetup(md) {
md.use(Prism)
}
}),
Markdown(),
// 文件路由
Pages({
extensions: ['vue', 'md', 'tsx']
Expand Down

0 comments on commit 0a4401b

Please sign in to comment.