mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-10-08 01:39:57 +08:00
feat(cli): support add baiduAnalytics to site
This commit is contained in:
parent
d89c63ff13
commit
141c0ed2c1
@ -9,6 +9,17 @@
|
|||||||
<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" />
|
||||||
<link href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css" rel="stylesheet" />
|
<link href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css" rel="stylesheet" />
|
||||||
|
<% if (htmlWebpackPlugin.options.baiduAnalytics) { %>
|
||||||
|
<script>
|
||||||
|
var _hmt = _hmt || [];
|
||||||
|
(function() {
|
||||||
|
var hm = document.createElement("script");
|
||||||
|
hm.src = "https://hm.baidu.com/hm.js?<%= htmlWebpackPlugin.options.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>
|
||||||
|
@ -8,6 +8,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 (htmlWebpackPlugin.options.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?<%= htmlWebpackPlugin.options.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,6 +2,7 @@ import merge from 'webpack-merge';
|
|||||||
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import WebpackBar from 'webpackbar';
|
import WebpackBar from 'webpackbar';
|
||||||
|
import { get } from 'lodash';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { baseConfig } from './webpack.base';
|
import { baseConfig } from './webpack.base';
|
||||||
import { getVantConfig, getWebpackConfig } from '../common';
|
import { getVantConfig, getWebpackConfig } from '../common';
|
||||||
@ -11,8 +12,11 @@ import {
|
|||||||
SITE_DESKTOP_SHARED_FILE
|
SITE_DESKTOP_SHARED_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
|
const vantConfig = getVantConfig();
|
||||||
|
const baiduAnalytics = get(vantConfig, 'site.baiduAnalytics');
|
||||||
|
|
||||||
function getSiteConfig() {
|
function getSiteConfig() {
|
||||||
const siteConfig = getVantConfig().site;
|
const siteConfig = vantConfig.site;
|
||||||
|
|
||||||
if (siteConfig.locales) {
|
if (siteConfig.locales) {
|
||||||
return siteConfig.locales[siteConfig.defaultLang || 'en-US'];
|
return siteConfig.locales[siteConfig.defaultLang || 'en-US'];
|
||||||
@ -78,14 +82,16 @@ export const siteDevBaseConfig = merge(baseConfig as any, {
|
|||||||
logo: siteConfig.logo,
|
logo: siteConfig.logo,
|
||||||
chunks: ['chunks', 'site-desktop'],
|
chunks: ['chunks', 'site-desktop'],
|
||||||
template: join(__dirname, '../../site/desktop/index.html'),
|
template: join(__dirname, '../../site/desktop/index.html'),
|
||||||
filename: 'index.html'
|
filename: 'index.html',
|
||||||
|
baiduAnalytics
|
||||||
}),
|
}),
|
||||||
new HtmlWebpackPlugin({
|
new HtmlWebpackPlugin({
|
||||||
title,
|
title,
|
||||||
logo: siteConfig.logo,
|
logo: siteConfig.logo,
|
||||||
chunks: ['chunks', 'site-mobile'],
|
chunks: ['chunks', 'site-mobile'],
|
||||||
template: join(__dirname, '../../site/mobile/index.html'),
|
template: join(__dirname, '../../site/mobile/index.html'),
|
||||||
filename: 'mobile.html'
|
filename: 'mobile.html',
|
||||||
|
baiduAnalytics
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
@ -14,6 +14,9 @@ module.exports = {
|
|||||||
versions: [
|
versions: [
|
||||||
{ label: '1.x', link: 'https://youzan.github.io/vant/1.x/' }
|
{ label: '1.x', link: 'https://youzan.github.io/vant/1.x/' }
|
||||||
],
|
],
|
||||||
|
baiduAnalytics: {
|
||||||
|
seed: 'ad6b5732c36321f2dafed737ac2da92f'
|
||||||
|
},
|
||||||
locales: {
|
locales: {
|
||||||
'zh-CN': {
|
'zh-CN': {
|
||||||
title: 'Vant',
|
title: 'Vant',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user