mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-09-05 23:49:44 +08:00
feat: add vite-plugin-html to modify template
This commit is contained in:
parent
ee1ee0fe29
commit
a2b942be8c
@ -92,6 +92,7 @@
|
|||||||
"ts-jest": "^27.0.5",
|
"ts-jest": "^27.0.5",
|
||||||
"typescript": "^4.3.5",
|
"typescript": "^4.3.5",
|
||||||
"vite": "^2.5.3",
|
"vite": "^2.5.3",
|
||||||
|
"vite-plugin-html": "^2.1.0",
|
||||||
"vite-plugin-md": "^0.11.0",
|
"vite-plugin-md": "^0.11.0",
|
||||||
"vue-loader": "^16.5.0",
|
"vue-loader": "^16.5.0",
|
||||||
"vue-router": "^4.0.0",
|
"vue-router": "^4.0.0",
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
|
<title><%= title %></title>
|
||||||
|
<meta name="description" content="<%= description %>" />
|
||||||
|
<link rel="icon" type="image/png" href="<%= logo %>" />
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"
|
||||||
@ -9,6 +12,18 @@
|
|||||||
<meta http-equiv="Cache-Control" content="no-cache" />
|
<meta http-equiv="Cache-Control" content="no-cache" />
|
||||||
<meta http-equiv="Pragma" content="no-cache" />
|
<meta http-equiv="Pragma" content="no-cache" />
|
||||||
<meta http-equiv="Expires" content="0" />
|
<meta http-equiv="Expires" content="0" />
|
||||||
|
<% if (baiduAnalytics) { %>
|
||||||
|
<script>
|
||||||
|
var _hmt = _hmt || [];
|
||||||
|
(function() {
|
||||||
|
var hm = document.createElement('script');
|
||||||
|
hm.src =
|
||||||
|
'https://hm.baidu.com/hm.js?<%= baiduAnalytics.seed %>';
|
||||||
|
var s = document.getElementsByTagName('script')[0];
|
||||||
|
s.parentNode.insertBefore(hm, s);
|
||||||
|
})();
|
||||||
|
</script>
|
||||||
|
<% } %>
|
||||||
</head>
|
</head>
|
||||||
<body ontouchstart>
|
<body ontouchstart>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
@ -2,16 +2,9 @@
|
|||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title><%= htmlWebpackPlugin.options.title %></title>
|
<title><%- title %></title>
|
||||||
<meta
|
<meta name="description" content="<%- description %>" />
|
||||||
name="description"
|
<link rel="icon" type="image/png" href="<%- logo %>" />
|
||||||
content="<%= htmlWebpackPlugin.options.description %>"
|
|
||||||
/>
|
|
||||||
<link
|
|
||||||
rel="icon"
|
|
||||||
type="image/png"
|
|
||||||
href="<%= htmlWebpackPlugin.options.logo %>"
|
|
||||||
/>
|
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"
|
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover"
|
||||||
@ -19,6 +12,20 @@
|
|||||||
<meta http-equiv="Cache-Control" content="no-cache" />
|
<meta http-equiv="Cache-Control" content="no-cache" />
|
||||||
<meta http-equiv="Pragma" content="no-cache" />
|
<meta http-equiv="Pragma" content="no-cache" />
|
||||||
<meta http-equiv="Expires" content="0" />
|
<meta http-equiv="Expires" content="0" />
|
||||||
|
<% if (baiduAnalytics) { %>
|
||||||
|
<script>
|
||||||
|
// avoid to load analytics in iframe
|
||||||
|
if (window.top === window) {
|
||||||
|
var _hmt = _hmt || [];
|
||||||
|
(function () {
|
||||||
|
var hm = document.createElement('script');
|
||||||
|
hm.src = 'https://hm.baidu.com/hm.js?<%- baiduAnalytics.seed %>';
|
||||||
|
var s = document.getElementsByTagName('script')[0];
|
||||||
|
s.parentNode.insertBefore(hm, s);
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
<% } %>
|
||||||
</head>
|
</head>
|
||||||
<body ontouchstart>
|
<body ontouchstart>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
|
import { get } from 'lodash';
|
||||||
import hljs from 'highlight.js';
|
import hljs from 'highlight.js';
|
||||||
import vitePluginMd from 'vite-plugin-md';
|
import vitePluginMd from 'vite-plugin-md';
|
||||||
import vitePluginVue from '@vitejs/plugin-vue';
|
import vitePluginVue from '@vitejs/plugin-vue';
|
||||||
import vitePluginJsx from '@vitejs/plugin-vue-jsx';
|
import vitePluginJsx from '@vitejs/plugin-vue-jsx';
|
||||||
import { setBuildTarget } from '../common';
|
import { setBuildTarget, getVantConfig } from '../common';
|
||||||
import {
|
import {
|
||||||
SITE_DESKTOP_SHARED_FILE,
|
SITE_DESKTOP_SHARED_FILE,
|
||||||
SITE_MOBILE_SHARED_FILE,
|
SITE_MOBILE_SHARED_FILE,
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
import { injectHtml } from 'vite-plugin-html';
|
||||||
import type { InlineConfig } from 'vite';
|
import type { InlineConfig } from 'vite';
|
||||||
|
|
||||||
function markdownHighlight(str: string, lang: string) {
|
function markdownHighlight(str: string, lang: string) {
|
||||||
@ -36,9 +38,34 @@ function markdownCardWrapper(htmlCode: string) {
|
|||||||
.join('');
|
.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 {
|
export function getViteConfigForSiteDev(): InlineConfig {
|
||||||
setBuildTarget('package');
|
setBuildTarget('package');
|
||||||
|
|
||||||
|
const vantConfig = getVantConfig();
|
||||||
|
const siteConfig = getSiteConfig(vantConfig);
|
||||||
|
const title = getTitle(siteConfig);
|
||||||
|
const baiduAnalytics = get(vantConfig, 'site.baiduAnalytics');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
root: join(__dirname, '../../site'),
|
root: join(__dirname, '../../site'),
|
||||||
|
|
||||||
@ -64,6 +91,13 @@ export function getViteConfigForSiteDev(): InlineConfig {
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
vitePluginJsx(),
|
vitePluginJsx(),
|
||||||
|
injectHtml({
|
||||||
|
data: {
|
||||||
|
...siteConfig,
|
||||||
|
title,
|
||||||
|
baiduAnalytics,
|
||||||
|
},
|
||||||
|
}),
|
||||||
],
|
],
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
|
@ -2574,6 +2574,11 @@ async-retry@1.3.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
retry "0.12.0"
|
retry "0.12.0"
|
||||||
|
|
||||||
|
async@0.9.x:
|
||||||
|
version "0.9.2"
|
||||||
|
resolved "https://registry.nlark.com/async/download/async-0.9.2.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fasync%2Fdownload%2Fasync-0.9.2.tgz#aea74d5e61c1f899613bf64bda66d4c78f2fd17d"
|
||||||
|
integrity sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0=
|
||||||
|
|
||||||
async@^2.6.1, async@^2.6.2:
|
async@^2.6.1, async@^2.6.2:
|
||||||
version "2.6.3"
|
version "2.6.3"
|
||||||
resolved "https://registry.yarnpkg.com/async/-/async-2.6.3.tgz#d72625e2344a3656e3a3ad4fa749fa83299d82ff"
|
resolved "https://registry.yarnpkg.com/async/-/async-2.6.3.tgz#d72625e2344a3656e3a3ad4fa749fa83299d82ff"
|
||||||
@ -3961,6 +3966,16 @@ dot-prop@^5.1.0, dot-prop@^5.2.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
is-obj "^2.0.0"
|
is-obj "^2.0.0"
|
||||||
|
|
||||||
|
dotenv-expand@^5.1.0:
|
||||||
|
version "5.1.0"
|
||||||
|
resolved "https://registry.npm.taobao.org/dotenv-expand/download/dotenv-expand-5.1.0.tgz#3fbaf020bfd794884072ea26b1e9791d45a629f0"
|
||||||
|
integrity sha1-P7rwIL/XlIhAcuomsel5HUWmKfA=
|
||||||
|
|
||||||
|
dotenv@^10.0.0:
|
||||||
|
version "10.0.0"
|
||||||
|
resolved "https://registry.nlark.com/dotenv/download/dotenv-10.0.0.tgz#3d4227b8fb95f81096cdd2b66653fb2c7085ba81"
|
||||||
|
integrity sha1-PUInuPuV+BCWzdK2ZlP7LHCFuoE=
|
||||||
|
|
||||||
duplexer3@^0.1.4:
|
duplexer3@^0.1.4:
|
||||||
version "0.1.4"
|
version "0.1.4"
|
||||||
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
|
resolved "https://registry.yarnpkg.com/duplexer3/-/duplexer3-0.1.4.tgz#ee01dd1cac0ed3cbc7fdbea37dc0a8f1ce002ce2"
|
||||||
@ -3971,6 +3986,13 @@ ee-first@1.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
|
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
|
||||||
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
|
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
|
||||||
|
|
||||||
|
ejs@^3.1.6:
|
||||||
|
version "3.1.6"
|
||||||
|
resolved "https://registry.npm.taobao.org/ejs/download/ejs-3.1.6.tgz?cache=0&sync_timestamp=1612643435705&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fejs%2Fdownload%2Fejs-3.1.6.tgz#5bfd0a0689743bb5268b3550cceeebbc1702822a"
|
||||||
|
integrity sha1-W/0KBol0O7UmizVQzO7rvBcCgio=
|
||||||
|
dependencies:
|
||||||
|
jake "^10.6.1"
|
||||||
|
|
||||||
electron-to-chromium@^1.3.811:
|
electron-to-chromium@^1.3.811:
|
||||||
version "1.3.813"
|
version "1.3.813"
|
||||||
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.813.tgz#751a007d71c00faed8b5e9edaf3634c14b9c5a1f"
|
resolved "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.813.tgz#751a007d71c00faed8b5e9edaf3634c14b9c5a1f"
|
||||||
@ -4538,6 +4560,13 @@ file-entry-cache@^6.0.1:
|
|||||||
dependencies:
|
dependencies:
|
||||||
flat-cache "^3.0.4"
|
flat-cache "^3.0.4"
|
||||||
|
|
||||||
|
filelist@^1.0.1:
|
||||||
|
version "1.0.2"
|
||||||
|
resolved "https://registry.npm.taobao.org/filelist/download/filelist-1.0.2.tgz?cache=0&sync_timestamp=1612641447730&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Ffilelist%2Fdownload%2Ffilelist-1.0.2.tgz#80202f21462d4d1c2e214119b1807c1bc0380e5b"
|
||||||
|
integrity sha1-gCAvIUYtTRwuIUEZsYB8G8A4Dls=
|
||||||
|
dependencies:
|
||||||
|
minimatch "^3.0.4"
|
||||||
|
|
||||||
filename-reserved-regex@^2.0.0:
|
filename-reserved-regex@^2.0.0:
|
||||||
version "2.0.0"
|
version "2.0.0"
|
||||||
resolved "https://registry.nlark.com/filename-reserved-regex/download/filename-reserved-regex-2.0.0.tgz#abf73dfab735d045440abfea2d91f389ebbfa229"
|
resolved "https://registry.nlark.com/filename-reserved-regex/download/filename-reserved-regex-2.0.0.tgz#abf73dfab735d045440abfea2d91f389ebbfa229"
|
||||||
@ -4686,6 +4715,15 @@ front-matter@^4.0.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
js-yaml "^3.13.1"
|
js-yaml "^3.13.1"
|
||||||
|
|
||||||
|
fs-extra@^10.0.0:
|
||||||
|
version "10.0.0"
|
||||||
|
resolved "https://registry.nlark.com/fs-extra/download/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
|
||||||
|
integrity sha1-n/YbZV3eU/s0qC34S7IUzoAuF8E=
|
||||||
|
dependencies:
|
||||||
|
graceful-fs "^4.2.0"
|
||||||
|
jsonfile "^6.0.1"
|
||||||
|
universalify "^2.0.0"
|
||||||
|
|
||||||
fs-extra@^8.1.0:
|
fs-extra@^8.1.0:
|
||||||
version "8.1.0"
|
version "8.1.0"
|
||||||
resolved "https://registry.npm.taobao.org/fs-extra/download/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
|
resolved "https://registry.npm.taobao.org/fs-extra/download/fs-extra-8.1.0.tgz#49d43c45a88cd9677668cb7be1b46efdb8d2e1c0"
|
||||||
@ -5134,6 +5172,19 @@ html-minifier-terser@^5.0.1:
|
|||||||
relateurl "^0.2.7"
|
relateurl "^0.2.7"
|
||||||
terser "^4.6.3"
|
terser "^4.6.3"
|
||||||
|
|
||||||
|
html-minifier-terser@^5.1.1:
|
||||||
|
version "5.1.1"
|
||||||
|
resolved "https://registry.nlark.com/html-minifier-terser/download/html-minifier-terser-5.1.1.tgz#922e96f1f3bb60832c2634b79884096389b1f054"
|
||||||
|
integrity sha1-ki6W8fO7YIMsJjS3mIQJY4mx8FQ=
|
||||||
|
dependencies:
|
||||||
|
camel-case "^4.1.1"
|
||||||
|
clean-css "^4.2.3"
|
||||||
|
commander "^4.1.1"
|
||||||
|
he "^1.2.0"
|
||||||
|
param-case "^3.0.3"
|
||||||
|
relateurl "^0.2.7"
|
||||||
|
terser "^4.6.3"
|
||||||
|
|
||||||
html-tags@^3.1.0:
|
html-tags@^3.1.0:
|
||||||
version "3.1.0"
|
version "3.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140"
|
resolved "https://registry.yarnpkg.com/html-tags/-/html-tags-3.1.0.tgz#7b5e6f7e665e9fb41f30007ed9e0d41e97fb2140"
|
||||||
@ -5839,6 +5890,16 @@ istanbul-reports@^3.0.2:
|
|||||||
html-escaper "^2.0.0"
|
html-escaper "^2.0.0"
|
||||||
istanbul-lib-report "^3.0.0"
|
istanbul-lib-report "^3.0.0"
|
||||||
|
|
||||||
|
jake@^10.6.1:
|
||||||
|
version "10.8.2"
|
||||||
|
resolved "https://registry.npm.taobao.org/jake/download/jake-10.8.2.tgz#ebc9de8558160a66d82d0eadc6a2e58fbc500a7b"
|
||||||
|
integrity sha1-68nehVgWCmbYLQ6txqLlj7xQCns=
|
||||||
|
dependencies:
|
||||||
|
async "0.9.x"
|
||||||
|
chalk "^2.4.2"
|
||||||
|
filelist "^1.0.1"
|
||||||
|
minimatch "^3.0.4"
|
||||||
|
|
||||||
jest-canvas-mock@^2.3.1:
|
jest-canvas-mock@^2.3.1:
|
||||||
version "2.3.1"
|
version "2.3.1"
|
||||||
resolved "https://registry.nlark.com/jest-canvas-mock/download/jest-canvas-mock-2.3.1.tgz#9535d14bc18ccf1493be36ac37dd349928387826"
|
resolved "https://registry.nlark.com/jest-canvas-mock/download/jest-canvas-mock-2.3.1.tgz#9535d14bc18ccf1493be36ac37dd349928387826"
|
||||||
@ -9572,6 +9633,11 @@ universalify@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
|
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
|
||||||
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==
|
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==
|
||||||
|
|
||||||
|
universalify@^2.0.0:
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.npm.taobao.org/universalify/download/universalify-2.0.0.tgz?cache=0&sync_timestamp=1603180004159&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Funiversalify%2Fdownload%2Funiversalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
|
||||||
|
integrity sha1-daSYTv7cSwiXXFrrc/Uw0C3yVxc=
|
||||||
|
|
||||||
unpipe@1.0.0, unpipe@~1.0.0:
|
unpipe@1.0.0, unpipe@~1.0.0:
|
||||||
version "1.0.0"
|
version "1.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
|
resolved "https://registry.yarnpkg.com/unpipe/-/unpipe-1.0.0.tgz#b2bf4ee8514aae6165b4817829d21b2ef49904ec"
|
||||||
@ -9699,6 +9765,18 @@ vfile@^4.0.0:
|
|||||||
unist-util-stringify-position "^2.0.0"
|
unist-util-stringify-position "^2.0.0"
|
||||||
vfile-message "^2.0.0"
|
vfile-message "^2.0.0"
|
||||||
|
|
||||||
|
vite-plugin-html@^2.1.0:
|
||||||
|
version "2.1.0"
|
||||||
|
resolved "https://registry.nlark.com/vite-plugin-html/download/vite-plugin-html-2.1.0.tgz#77b6ee11d9cdbdf766b5731fd416bacf26744fce"
|
||||||
|
integrity sha1-d7buEdnNvfdmtXMf1Ba6zyZ0T84=
|
||||||
|
dependencies:
|
||||||
|
"@rollup/pluginutils" "^4.1.1"
|
||||||
|
dotenv "^10.0.0"
|
||||||
|
dotenv-expand "^5.1.0"
|
||||||
|
ejs "^3.1.6"
|
||||||
|
fs-extra "^10.0.0"
|
||||||
|
html-minifier-terser "^5.1.1"
|
||||||
|
|
||||||
vite-plugin-md@^0.11.0:
|
vite-plugin-md@^0.11.0:
|
||||||
version "0.11.0"
|
version "0.11.0"
|
||||||
resolved "https://registry.nlark.com/vite-plugin-md/download/vite-plugin-md-0.11.0.tgz#cb397270e1a27bc17588d43f1a8a6478055eceac"
|
resolved "https://registry.nlark.com/vite-plugin-md/download/vite-plugin-md-0.11.0.tgz#cb397270e1a27bc17588d43f1a8a6478055eceac"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user