diff --git a/packages/uni-stat/lib/uni.plugin.js b/packages/uni-stat/lib/uni.plugin.js index b87c898863329ae8a3590dded15330635276c859..21ee3030dc7d364217276fc49f1beba19e203fc0 100644 --- a/packages/uni-stat/lib/uni.plugin.js +++ b/packages/uni-stat/lib/uni.plugin.js @@ -14,39 +14,37 @@ var index = [ name: 'uni:stat', enforce: 'pre', config(config, env) { - if (uniCliShared.isSsr(env.command, config)) { - return; - } 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 e6227d3f7792803bff07a630eb1f16361cba6493..cbfc380f2541dae8f8272a4c7af9860c04291c96 100644 --- a/packages/uni-stat/src/plugin/index.ts +++ b/packages/uni-stat/src/plugin/index.ts @@ -5,6 +5,7 @@ import { getUniStatistics, parseManifestJsonOnce, parsePagesJson, + isSsr, } from '@dcloudio/uni-cli-shared' export default [ @@ -13,7 +14,7 @@ export default [ return { name: 'uni:stat', enforce: 'pre', - config() { + config(config, env) { const inputDir = process.env.UNI_INPUT_DIR! const platform = process.env.UNI_PLATFORM! const titlesJson = Object.create(null) @@ -29,19 +30,22 @@ export default [ titlesJson[page.path] = titleText } }) - - 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 + // 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: {