feat(@vant/cli): add enableVConsole option (#9527)

This commit is contained in:
neverland 2021-09-20 17:18:08 +08:00 committed by GitHub
parent 3a8bb909fd
commit 751a263999
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -260,6 +260,13 @@ module.exports = {
配置 HTML 中的 meta 标签,对象的 key 为 namevalue 为 content。
### site.enableVConsole
- Type: `boolean`
- Default: `false`
是否在 dev 时开启 [vConsole](https://github.com/Tencent/vConsole) 调试,用于移动端 debug。
## Babel
通过根目录下的`babel.config.js`文件可以对 Babel 进行配置。

View File

@ -13,6 +13,12 @@
<meta http-equiv="Cache-Control" content="no-cache" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<% if (enableVConsole) { %>
<script src="https://unpkg.com/vconsole/dist/vconsole.min.js"></script>
<script>
var vConsole = new window.VConsole();
</script>
<% } %>
<% if (baiduAnalytics) { %>
<script>
// avoid to load analytics in iframe

View File

@ -4,7 +4,7 @@ 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, getVantConfig } from '../common';
import { setBuildTarget, getVantConfig, isDev } from '../common';
import {
SITE_DIST_DIR,
SITE_MOBILE_SHARED_FILE,
@ -79,6 +79,7 @@ export function getViteConfigForSiteDev(): InlineConfig {
const siteConfig = getSiteConfig(vantConfig);
const title = getTitle(siteConfig);
const baiduAnalytics = get(vantConfig, 'site.baiduAnalytics');
const enableVConsole = isDev() && get(vantConfig, 'site.enableVConsole');
return {
root: SITE_SRC_DIR,
@ -110,6 +111,7 @@ export function getViteConfigForSiteDev(): InlineConfig {
...siteConfig,
title,
baiduAnalytics,
enableVConsole,
meta: getHTMLMeta(vantConfig),
},
}),