feat(cli): support add baiduAnalytics to site

This commit is contained in:
陈嘉涵 2019-12-24 21:09:31 +08:00
parent d89c63ff13
commit 141c0ed2c1
4 changed files with 37 additions and 3 deletions

View File

@ -9,6 +9,17 @@
<meta http-Equiv="Pragma" Content="no-cache" />
<meta http-Equiv="Expires" Content="0" />
<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>
<body ontouchstart>
<div id="app"></div>

View File

@ -8,6 +8,20 @@
<meta http-Equiv="Cache-Control" Content="no-cache" />
<meta http-Equiv="Pragma" Content="no-cache" />
<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>
<body ontouchstart>
<div id="app"></div>

View File

@ -2,6 +2,7 @@ import merge from 'webpack-merge';
import HtmlWebpackPlugin from 'html-webpack-plugin';
// @ts-ignore
import WebpackBar from 'webpackbar';
import { get } from 'lodash';
import { join } from 'path';
import { baseConfig } from './webpack.base';
import { getVantConfig, getWebpackConfig } from '../common';
@ -11,8 +12,11 @@ import {
SITE_DESKTOP_SHARED_FILE
} from '../common/constant';
const vantConfig = getVantConfig();
const baiduAnalytics = get(vantConfig, 'site.baiduAnalytics');
function getSiteConfig() {
const siteConfig = getVantConfig().site;
const siteConfig = vantConfig.site;
if (siteConfig.locales) {
return siteConfig.locales[siteConfig.defaultLang || 'en-US'];
@ -78,14 +82,16 @@ export const siteDevBaseConfig = merge(baseConfig as any, {
logo: siteConfig.logo,
chunks: ['chunks', 'site-desktop'],
template: join(__dirname, '../../site/desktop/index.html'),
filename: 'index.html'
filename: 'index.html',
baiduAnalytics
}),
new HtmlWebpackPlugin({
title,
logo: siteConfig.logo,
chunks: ['chunks', 'site-mobile'],
template: join(__dirname, '../../site/mobile/index.html'),
filename: 'mobile.html'
filename: 'mobile.html',
baiduAnalytics
})
]
});

View File

@ -14,6 +14,9 @@ module.exports = {
versions: [
{ label: '1.x', link: 'https://youzan.github.io/vant/1.x/' }
],
baiduAnalytics: {
seed: 'ad6b5732c36321f2dafed737ac2da92f'
},
locales: {
'zh-CN': {
title: 'Vant',