提交 5061f561 编写于 作者: fxy060608's avatar fxy060608

feat(stat): support uni-cloud-stat

上级 91f75d1e
......@@ -57,7 +57,8 @@ const {
nvueJsPreprocessOptions,
nvueCssPreprocessOptions,
nvueHtmlPreprocessOptions,
getPlatformGlobal
getPlatformGlobal,
getPlatformStat
} = require('./platform')
module.exports = {
......@@ -106,5 +107,6 @@ module.exports = {
nvueJsPreprocessOptions,
nvueCssPreprocessOptions,
nvueHtmlPreprocessOptions,
getPlatformGlobal
getPlatformGlobal,
getPlatformStat
}
......@@ -159,6 +159,13 @@ module.exports = {
getPlatformSass () {
return SASS
},
getPlatformStat () {
if (!process.env.UNI_USING_STAT) {
return ''
}
return process.env.UNI_USING_STAT === '2' ? 'import \'@dcloudio/uni-stat/dist/uni-cloud-stat.es.js\';'
: 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';'
},
getBabelParserOptions () {
return {
sourceType: 'module',
......
......@@ -12,7 +12,8 @@ const {
} = require('vue-loader/lib/codegen/utils')
const {
normalizePath
normalizePath,
getPlatformStat
} = require('@dcloudio/uni-cli-shared')
const appVuePath = path.resolve(process.env.UNI_INPUT_DIR, 'App.vue')
......@@ -47,7 +48,7 @@ module.exports = function (content, map) {
const loaderContext = this
const statCode = process.env.UNI_USING_STAT ? 'import \'@dcloudio/uni-stat\';' : ''
const statCode = getPlatformStat()
if (this.resourceQuery) {
const params = loaderUtils.parseQuery(this.resourceQuery)
......
......@@ -2,7 +2,8 @@ const path = require('path')
const webpack = require('webpack')
const {
getMainEntry
getMainEntry,
getPlatformStat
} = require('@dcloudio/uni-cli-shared')
const vueLoader = require('@dcloudio/uni-cli-shared/lib/vue-loader')
......@@ -58,7 +59,7 @@ const v3 = {
const isAppService = !!vueOptions.pluginOptions['uni-app-plus'].service
const isAppView = !!vueOptions.pluginOptions['uni-app-plus'].view
const statCode = process.env.UNI_USING_STAT ? 'import \'@dcloudio/uni-stat\';' : ''
const statCode = getPlatformStat()
const beforeCode = 'import \'uni-pages\';'
......
......@@ -323,9 +323,6 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt
.UNI_INPUT_DIR), // css中的'@/static/logo.png'会被转换成'./@/static/logo.png'加载
vue$: getPlatformVue(vueOptions),
'uni-pages': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json'),
'@dcloudio/uni-stat': process.env.UNI_USING_VUE3 ? require.resolve(
'@dcloudio/vue-cli-plugin-uni/packages/uni-stat') : require
.resolve('@dcloudio/uni-stat'),
'uni-stat-config': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json') +
'?' +
JSON.stringify({
......
......@@ -50,7 +50,8 @@ process.env.UNI_USING_V3_SCOPED = true
process.env.UNI_CLOUD_PROVIDER = JSON.stringify([])
// 导出到小程序插件
process.env.UNI_MP_PLUGIN_EXPORT = JSON.stringify(Object.keys(platformOptions.plugins || {}).map(pluginName => platformOptions.plugins[pluginName].export))
process.env.UNI_MP_PLUGIN_EXPORT = JSON.stringify(Object.keys(platformOptions.plugins || {}).map(pluginName =>
platformOptions.plugins[pluginName].export))
const isH5 = !process.env.UNI_SUB_PLATFORM && process.env.UNI_PLATFORM === 'h5'
const isProduction = process.env.NODE_ENV === 'production'
......@@ -308,7 +309,7 @@ if (
)
if (uniStatistics.enable === true) {
process.env.UNI_USING_STAT = true
process.env.UNI_USING_STAT = uniStatistics.version === '2' ? '2' : '1'
if (!process.UNI_STAT_CONFIG.appid && process.env.NODE_ENV === 'production') {
console.log()
console.warn(uniI18n.__('pluginUni.uniStatisticsNoAppid', {
......
......@@ -4,7 +4,8 @@ const webpack = require('webpack')
const {
getMainEntry,
getH5Options
getH5Options,
getPlatformStat
} = require('@dcloudio/uni-cli-shared')
const {
......@@ -91,7 +92,7 @@ module.exports = {
webpackConfig (webpackConfig) {
let useBuiltIns = 'usage'
const statCode = process.env.UNI_USING_STAT ? 'import \'@dcloudio/uni-stat\';' : ''
const statCode = getPlatformStat()
try {
const babelConfig = require(path.resolve(process.env.UNI_CLI_CONTEXT, 'babel.config.js'))
......
......@@ -6,7 +6,8 @@ const {
getMainEntry,
normalizePath,
getPlatformExts,
getPlatformCssnano
getPlatformCssnano,
getPlatformStat
} = require('@dcloudio/uni-cli-shared')
const WebpackUniAppPlugin = require('../../packages/webpack-uni-app-loader/plugin/index')
......@@ -162,7 +163,7 @@ module.exports = {
parseEntry()
const statCode = process.env.UNI_USING_STAT ? 'import \'@dcloudio/uni-stat\';' : ''
const statCode = getPlatformStat()
let beforeCode = 'import \'uni-pages\';'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册