mirror of
https://github.com/youzan/vant.git
synced 2025-10-17 00:14:18 +00:00
feat: add vite-plugin-html to modify template
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { join } from 'path';
|
||||
import { get } from 'lodash';
|
||||
import hljs from 'highlight.js';
|
||||
import vitePluginMd from 'vite-plugin-md';
|
||||
import vitePluginVue from '@vitejs/plugin-vue';
|
||||
import vitePluginJsx from '@vitejs/plugin-vue-jsx';
|
||||
import { setBuildTarget } from '../common';
|
||||
import { setBuildTarget, getVantConfig } from '../common';
|
||||
import {
|
||||
SITE_DESKTOP_SHARED_FILE,
|
||||
SITE_MOBILE_SHARED_FILE,
|
||||
} from '../common/constant';
|
||||
import { injectHtml } from 'vite-plugin-html';
|
||||
import type { InlineConfig } from 'vite';
|
||||
|
||||
function markdownHighlight(str: string, lang: string) {
|
||||
@@ -36,9 +38,34 @@ function markdownCardWrapper(htmlCode: string) {
|
||||
.join('');
|
||||
}
|
||||
|
||||
function getSiteConfig(vantConfig: any) {
|
||||
const siteConfig = vantConfig.site;
|
||||
|
||||
if (siteConfig.locales) {
|
||||
return siteConfig.locales[siteConfig.defaultLang || 'en-US'];
|
||||
}
|
||||
|
||||
return siteConfig;
|
||||
}
|
||||
|
||||
function getTitle(config: { title: string; description?: string }) {
|
||||
let { title } = config;
|
||||
|
||||
if (config.description) {
|
||||
title += ` - ${config.description}`;
|
||||
}
|
||||
|
||||
return title;
|
||||
}
|
||||
|
||||
export function getViteConfigForSiteDev(): InlineConfig {
|
||||
setBuildTarget('package');
|
||||
|
||||
const vantConfig = getVantConfig();
|
||||
const siteConfig = getSiteConfig(vantConfig);
|
||||
const title = getTitle(siteConfig);
|
||||
const baiduAnalytics = get(vantConfig, 'site.baiduAnalytics');
|
||||
|
||||
return {
|
||||
root: join(__dirname, '../../site'),
|
||||
|
||||
@@ -64,6 +91,13 @@ export function getViteConfigForSiteDev(): InlineConfig {
|
||||
},
|
||||
}),
|
||||
vitePluginJsx(),
|
||||
injectHtml({
|
||||
data: {
|
||||
...siteConfig,
|
||||
title,
|
||||
baiduAnalytics,
|
||||
},
|
||||
}),
|
||||
],
|
||||
|
||||
resolve: {
|
||||
|
Reference in New Issue
Block a user