diff --git a/packages/uni-stat/lib/uni.plugin.js b/packages/uni-stat/lib/uni.plugin.js index eabd9ff7ee15a6645dd98b318c8c26bc8726e1a9..6726d040b811469d91024cdba47734b6a7d8657d 100644 --- a/packages/uni-stat/lib/uni.plugin.js +++ b/packages/uni-stat/lib/uni.plugin.js @@ -15,40 +15,38 @@ var index = () => [ name: 'uni:stat', enforce: 'pre', config(config, env) { - if (uniCliShared.isSsr(env.command, config)) { - return; - } isNVue = config.nvue; const inputDir = process.env.UNI_INPUT_DIR; const platform = process.env.UNI_PLATFORM; - isEnable = uniCliShared.getUniStatistics(inputDir, platform).enable === true; - if (process.env.NODE_ENV === 'production') { - const manifestJson = uniCliShared.parseManifestJsonOnce(inputDir); - if (!manifestJson.appid) { - console.log(); - console.warn(uniCliShared.M['stat.warn.appid']); - console.log(); - isEnable = false; - } - } const titlesJson = Object.create(null); - if (isEnable) { - uniCliShared.parsePagesJson(inputDir, platform).pages.forEach((page) => { - var _a; - const style = page.style || {}; - const titleText = - // MP - style.navigationBarTitleText || - ( - // H5 || App - (_a = style.navigationBar) === null || _a === void 0 ? void 0 : _a.titleText) || - ''; - if (titleText) { - titlesJson[page.path] = titleText; + uniCliShared.parsePagesJson(inputDir, platform).pages.forEach((page) => { + var _a; + const style = page.style || {}; + const titleText = + // MP + style.navigationBarTitleText || + ( + // H5 || App + (_a = style.navigationBar) === null || _a === void 0 ? void 0 : _a.titleText) || + ''; + if (titleText) { + titlesJson[page.path] = titleText; + } + }); + // ssr 时不开启 + if (!uniCliShared.isSsr(env.command, config)) { + isEnable = uniCliShared.getUniStatistics(inputDir, platform).enable === true; + if (process.env.NODE_ENV === 'production') { + const manifestJson = uniCliShared.parseManifestJsonOnce(inputDir); + if (!manifestJson.appid) { + console.log(); + console.warn(uniCliShared.M['stat.warn.appid']); + console.log(); + isEnable = false; } - }); + } + debug__default["default"]('uni:stat')('isEnable', isEnable); } - debug__default["default"]('uni:stat')('isEnable', isEnable); process.env.UNI_STAT_TITLE_JSON = JSON.stringify(titlesJson); return { define: { diff --git a/packages/uni-stat/src/plugin/index.ts b/packages/uni-stat/src/plugin/index.ts index 6338e0913a08831cc9561c7ae8d9ab4f3de90cf8..e703fbefbc696b98687860f00f1963b4ac286aa4 100644 --- a/packages/uni-stat/src/plugin/index.ts +++ b/packages/uni-stat/src/plugin/index.ts @@ -16,38 +16,36 @@ export default () => [ name: 'uni:stat', enforce: 'pre', config(config, env) { - if (isSsr(env.command, config)) { - return - } isNVue = (config as any).nvue const inputDir = process.env.UNI_INPUT_DIR! const platform = process.env.UNI_PLATFORM! - isEnable = getUniStatistics(inputDir, platform).enable === true - if (process.env.NODE_ENV === 'production') { - const manifestJson = parseManifestJsonOnce(inputDir) - if (!manifestJson.appid) { - console.log() - console.warn(M['stat.warn.appid']) - console.log() - isEnable = false - } - } const titlesJson = Object.create(null) - if (isEnable) { - parsePagesJson(inputDir, platform).pages.forEach((page: any) => { - const style = page.style || {} - const titleText = - // MP - style.navigationBarTitleText || - // H5 || App - style.navigationBar?.titleText || - '' - if (titleText) { - titlesJson[page.path] = titleText + parsePagesJson(inputDir, platform).pages.forEach((page: any) => { + const style = page.style || {} + const titleText = + // MP + style.navigationBarTitleText || + // H5 || App + style.navigationBar?.titleText || + '' + if (titleText) { + titlesJson[page.path] = titleText + } + }) + // ssr 时不开启 + if (!isSsr(env.command, config)) { + isEnable = getUniStatistics(inputDir, platform).enable === true + if (process.env.NODE_ENV === 'production') { + const manifestJson = parseManifestJsonOnce(inputDir) + if (!manifestJson.appid) { + console.log() + console.warn(M['stat.warn.appid']) + console.log() + isEnable = false } - }) + } + debug('uni:stat')('isEnable', isEnable) } - debug('uni:stat')('isEnable', isEnable) process.env.UNI_STAT_TITLE_JSON = JSON.stringify(titlesJson) return { define: {