提交 752dc8cc 编写于 作者: fxy060608's avatar fxy060608

feat(stat): support uni-cloud-stat

上级 10bf5d18
......@@ -7,9 +7,14 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug);
var index = [
var index = () => [
uniCliShared.defineUniMainJsPlugin((opts) => {
let statVersion = '1';
let isEnable = false;
const stats = {
'@dcloudio/uni-stat': uniCliShared.resolveBuiltIn('@dcloudio/uni-stat/dist/uni-stat.es.js'),
'@dcloudio/uni-cloud-stat': uniCliShared.resolveBuiltIn('@dcloudio/uni-stat/dist/uni-cloud-stat.es.js'),
};
return {
name: 'uni:stat',
enforce: 'pre',
......@@ -33,7 +38,9 @@ var index = [
});
// ssr 时不开启
if (!uniCliShared.isSsr(env.command, config)) {
isEnable = uniCliShared.getUniStatistics(inputDir, platform).enable === true;
const statConfig = uniCliShared.getUniStatistics(inputDir, platform);
statVersion = statConfig.version === '2' ? '2' : '1';
isEnable = statConfig.enable === true;
if (process.env.NODE_ENV === 'production') {
const manifestJson = uniCliShared.parseManifestJsonOnce(inputDir);
if (!manifestJson.appid) {
......@@ -52,10 +59,14 @@ var index = [
},
};
},
resolveId(id) {
return stats[id] || null;
},
transform(code, id) {
if (isEnable && opts.filter(id)) {
return {
code: code + `;import '@dcloudio/uni-stat';`,
code: code +
`;import '@dcloudio/uni${statVersion === '2' ? '-cloud' : ''}-stat';`,
map: null,
};
}
......
......@@ -6,11 +6,21 @@ import {
parseManifestJsonOnce,
parsePagesJson,
isSsr,
resolveBuiltIn,
} from '@dcloudio/uni-cli-shared'
export default [
export default () => [
defineUniMainJsPlugin((opts) => {
let statVersion: '1' | '2' = '1'
let isEnable = false
const stats: Record<string, string> = {
'@dcloudio/uni-stat': resolveBuiltIn(
'@dcloudio/uni-stat/dist/uni-stat.es.js'
),
'@dcloudio/uni-cloud-stat': resolveBuiltIn(
'@dcloudio/uni-stat/dist/uni-cloud-stat.es.js'
),
}
return {
name: 'uni:stat',
enforce: 'pre',
......@@ -32,7 +42,9 @@ export default [
})
// ssr 时不开启
if (!isSsr(env.command, config)) {
isEnable = getUniStatistics(inputDir, platform).enable === true
const statConfig = getUniStatistics(inputDir, platform)
statVersion = statConfig.version === '2' ? '2' : '1'
isEnable = statConfig.enable === true
if (process.env.NODE_ENV === 'production') {
const manifestJson = parseManifestJsonOnce(inputDir)
if (!manifestJson.appid) {
......@@ -53,10 +65,17 @@ export default [
},
}
},
resolveId(id) {
return stats[id] || null
},
transform(code, id) {
if (isEnable && opts.filter(id)) {
return {
code: code + `;import '@dcloudio/uni-stat';`,
code:
code +
`;import '@dcloudio/uni${
statVersion === '2' ? '-cloud' : ''
}-stat';`,
map: null,
}
}
......
......@@ -12,7 +12,6 @@ const BUILT_IN_MODULES = {
vuex: 'dist/vuex.esm-bundler.js',
'vue-i18n': 'dist/vue-i18n.esm-bundler.js',
'@dcloudio/uni-app': 'dist/uni-app.es.js',
'@dcloudio/uni-stat': 'dist/uni-stat.es.js',
'@dcloudio/uni-cloud': 'dist/uni-cloud.es.js',
'@dcloudio/uni-i18n': 'dist/uni-i18n.es.js',
'@dcloudio/uni-shared': 'dist/uni-shared.es.js',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册