chore(组件): 由于easycom会自动注册components和uni_modules 目录下的组件,所以去除引用部分

This commit is contained in:
2026-01-05 15:27:34 +08:00
parent be51b30fb4
commit 8ef6975ee1
18 changed files with 321 additions and 227 deletions

View File

@@ -47,9 +47,6 @@ export default {
type: Object type: Object
} }
}, },
components: {
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
},
mixins: [DiyMinx], mixins: [DiyMinx],
data() { data() {
return { return {

View File

@@ -186,9 +186,6 @@ export default {
type: Object type: Object
} }
}, },
components: {
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
},
mixins: [DiyMinx], mixins: [DiyMinx],
data() { data() {
return { return {

View File

@@ -304,7 +304,6 @@ export default {
} }
}, },
components: { components: {
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
}, },
mixins: [DiyMinx], mixins: [DiyMinx],

View File

@@ -31,7 +31,6 @@ export default {
components: { components: {
uniGrid: () => import('@/components/uni-grid/uni-grid.vue'), uniGrid: () => import('@/components/uni-grid/uni-grid.vue'),
uniGridItem: () => import('@/components/uni-grid-item/uni-grid-item.vue'), uniGridItem: () => import('@/components/uni-grid-item/uni-grid-item.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
data() { data() {
return { return {

View File

@@ -260,7 +260,6 @@ export default {
name: 'diy-goods-list', name: 'diy-goods-list',
components: { components: {
nsGoodsSkuIndex: () => import('@/components/ns-goods-sku/ns-goods-sku-index.vue'), nsGoodsSkuIndex: () => import('@/components/ns-goods-sku/ns-goods-sku-index.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
props: { props: {
value: { value: {

View File

@@ -78,9 +78,6 @@ export default {
} }
} }
}, },
components: {
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
},
mixins: [DiyMinx], mixins: [DiyMinx],
data() { data() {
return { return {

View File

@@ -104,7 +104,6 @@ export default {
} }
}, },
components: { components: {
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
}, },
mixins: [DiyMinx], mixins: [DiyMinx],

View File

@@ -1,13 +1,260 @@
<template> <template>
<view data-component-name="diy-group" class="diy-group"> <view data-component-name="diy-group" class="diy-group">
<view v-for="(item, index) in diyDataArray" :key="index" :style="item.pageStyle"> <view v-for="(item, index) in diyDataArray" :key="index" :style="item.pageStyle">
<!-- 动态组件加载 --> <view v-if="addonIsExist.store && item.componentName == 'StoreShow'">
<component <!-- 门店展示 -->
:is="getComponent(item.componentName)" <diy-store :value="item"></diy-store>
v-if="shouldShowComponent(item)" </view>
:value="item"
v-bind="getComponentProps(item)" <template v-if="item.componentName == 'Kefu'">
></component> <!-- 客服按钮 -->
<diy-kefu :value="item"></diy-kefu>
</template>
<template v-if="item.componentName == 'Form'">
<!-- 表单组件 -->
<diy-form :value="item"></diy-form>
</template>
<template v-if="addonIsExist.store && item.componentName == 'StoreLabel'">
<!-- 门店标签 -->
<diy-store-label :value="item"></diy-store-label>
</template>
<template v-if="item.componentName == 'Picture'">
<!-- 单图组组件 -->
<diy-picture :value="item"></diy-picture>
</template>
<template v-if="item.componentName == 'Listmenu'">
<!-- 列表按钮组件 -->
<diy-listmenu :value="item"></diy-listmenu>
</template>
<template v-if="item.componentName == 'Text'">
<!-- 文本 -->
<diy-text :value="item"></diy-text>
</template>
<template v-if="item.componentName == 'Notice'">
<!-- 公告 -->
<diy-notice :value="item"></diy-notice>
</template>
<template v-if="item.componentName == 'GraphicNav'">
<!-- 图文导航 -->
<diy-graphic-nav :value="item"></diy-graphic-nav>
</template>
<template v-if="item.componentName == 'ImageAds'">
<!-- 图片广告 -->
<diy-img-ads :value="item"></diy-img-ads>
</template>
<template v-if="item.componentName == 'Search'">
<!-- 搜索 -->
<diy-search :value="item" :topNavColor="topNavColor" :global="diyGlobalData.global"
:haveTopCategory="haveTopCategory" :followOfficialAccount="followOfficialAccount"></diy-search>
</template>
<template v-if="item.componentName == 'RichText'">
<!-- 富文本 -->
<diy-rich-text :value="item"></diy-rich-text>
</template>
<template v-if="item.componentName == 'HorzLine'">
<!-- 辅助线 -->
<diy-horz-line :value="item"></diy-horz-line>
</template>
<template v-if="item.componentName == 'HorzBlank'">
<!-- 辅助空白 -->
<diy-horz-blank :value="item"></diy-horz-blank>
</template>
<template v-if="item.componentName == 'Coupon' && addonIsExist.coupon">
<!-- 优惠券 -->
<diy-coupon :value="item"></diy-coupon>
</template>
<template v-if="item.componentName == 'GoodsList'">
<!-- 商品列表 -->
<diy-goods-list :value="item"></diy-goods-list>
</template>
<template v-if="item.componentName == 'ManyGoodsList'">
<!-- 多商品组 -->
<diy-many-goods-list :value="item" :global="diyGlobalData.global"
:scrollTop="scrollTop"></diy-many-goods-list>
</template>
<template v-if="item.componentName == 'RubikCube'">
<!-- 魔方橱窗 -->
<diy-rubik-cube :value="item"></diy-rubik-cube>
</template>
<template v-if="item.componentName == 'Video'">
<!-- 视频 -->
<diy-video :value="item"></diy-video>
</template>
<template v-if="item.componentName == 'Seckill' && addonIsExist.seckill">
<!-- 秒杀 -->
<diy-seckill :value="item"></diy-seckill>
</template>
<template v-if="item.componentName == 'Pintuan' && addonIsExist.pintuan">
<!-- 拼团 -->
<diy-pintuan :value="item"></diy-pintuan>
</template>
<template v-if="item.componentName == 'Groupbuy' && addonIsExist.groupbuy">
<!-- 团购 -->
<diy-groupbuy :value="item"></diy-groupbuy>
</template>
<!-- 拼团返利 -->
<template v-if="item.componentName == 'Pinfan' && addonIsExist.pinfan">
<diy-pinfan :value="item"></diy-pinfan>
</template>
<template v-if="item.componentName == 'Bargain' && addonIsExist.bargain">
<!-- 砍价 -->
<diy-bargain :value="item"></diy-bargain>
</template>
<template v-if="item.componentName == 'Presale' && addonIsExist.bargain">
<!-- 预售 -->
<diy-presale :value="item"></diy-presale>
</template>
<template v-if="item.componentName == 'Notes' && addonIsExist.notes">
<!-- 店铺笔记 -->
<diy-notes :value="item"></diy-notes>
</template>
<template v-if="item.componentName == 'FloatBtn'">
<!-- 浮动按钮 -->
<diy-float-btn :value="item"></diy-float-btn>
</template>
<template v-if="item.componentName == 'LiveInfo'">
<!-- 小程序直播 -->
<!-- #ifdef MP-WEIXIN -->
<diy-live :value="item"></diy-live>
<!-- #endif -->
</template>
<template v-if="item.componentName == 'FenxiaoGoodsList'">
<!-- 分销商品 -->
<diy-fenxiao-goods-list :value="item"></diy-fenxiao-goods-list>
</template>
<template v-if="item.componentName == 'GoodsRecommend'">
<!-- 商品推荐 -->
<diy-goods-recommend :value="item"></diy-goods-recommend>
</template>
<template v-if="item.componentName == 'GoodsBrand'">
<!-- 商品品牌 -->
<diy-goods-brand :value="item"></diy-goods-brand>
</template>
<template v-if="item.componentName == 'Article'">
<!-- 文章 -->
<diy-article :value="item"></diy-article>
</template>
<template v-if="item.componentName == 'MerchList'">
<!-- 商户列表 -->
<diy-merch-list :value="item"></diy-merch-list>
</template>
<template v-if="item.componentName == 'MemberInfo'">
<!-- 自定义会员中心会员信息 -->
<diy-member-info ref="diyMemberIndex" :value="item" :global="diyGlobalData.global"></diy-member-info>
</template>
<template v-if="item.componentName == 'MemberMyOrder'">
<!-- 自定义会员中心我的订单 -->
<diy-member-my-order ref="diyMemberMyOrder" :value="item"></diy-member-my-order>
</template>
<template v-if="item.componentName == 'QuickNav'">
<!-- 快捷导航 -->
<diy-quick-nav :value="item"></diy-quick-nav>
</template>
<template v-if="item.componentName == 'PaymentQrcode'">
<!-- 付款码 -->
<diy-payment-qrcode :value="item"></diy-payment-qrcode>
</template>
<template v-if="item.componentName == 'HotArea'">
<!-- 热区 -->
<diy-hot-area :value="item"></diy-hot-area>
</template>
<template v-if="item.componentName == 'FollowOfficialAccount'">
<!-- 关注公众号 -->
<diy-follow-official-account :value="item"></diy-follow-official-account>
</template>
<template v-if="item.componentName == 'Map'">
<!-- 地图组件 -->
<diy-map :value="item"></diy-map>
</template>
<template v-if="item.componentName == 'Audio'">
<!-- 音频 -->
<diy-audio :value="item"></diy-audio>
</template>
<template v-if="item.componentName == 'ImageNav'">
<!-- 图片导航 -->
<diy-image-nav :value="item"></diy-image-nav>
</template>
<template v-if="item.componentName == 'Digit'">
<!-- 数字 -->
<diy-digit :value="item"></diy-digit>
</template>
<template v-if="item.componentName == 'VideoList'">
<!-- 视频列表 -->
<diy-video-list :value="item"></diy-video-list>
</template>
<template v-if="item.componentName == 'BottomNav'">
<!-- 底部导航 -->
<diy-bottom-nav :value="item"></diy-bottom-nav>
</template>
<template v-if="item.componentName == 'CategoryItem'">
<!-- 分类项 -->
<diy-category-item :value="item"></diy-category-item>
</template>
<template v-if="item.componentName == 'Category'">
<!-- 分类 -->
<diy-category :value="item"></diy-category>
</template>
<template v-if="item.componentName == 'Icon'">
<!-- 图标 -->
<diy-icon :value="item"></diy-icon>
</template>
<template v-if="item.componentName == 'Group'">
<!-- 组件组 -->
<diy-group :diyData="item"></diy-group>
</template>
<!-- 自定义扩展组件 --> <!-- 自定义扩展组件 -->
<diy-comp-extend :value="item"></diy-comp-extend> <diy-comp-extend :value="item"></diy-comp-extend>
@@ -18,14 +265,9 @@
<script> <script>
// 组件组展示 // 组件组展示
import DiyMinx from './minx.js' import DiyMinx from './minx.js'
import diyCompExtend from './diy-comp-extend.vue'
export default { export default {
name: 'DiyGroup', name: 'DiyGroup',
mixins: [DiyMinx], mixins: [DiyMinx],
components: {
diyCompExtend
},
props: { props: {
diyData: { diyData: {
type: Object, type: Object,
@@ -44,61 +286,10 @@ export default {
default: () => ({}) default: () => ({})
}, },
}, },
mixins: [DiyMinx],
data() { data() {
return { return {
diyGlobalData: null, diyGlobalData: null
// 动态组件映射
componentMap: {
StoreShow: () => import('./diy-store.vue'),
Kefu: () => import('./diy-kefu.vue'),
Form: () => import('./diy-form.vue'),
StoreLabel: () => import('./diy-store-label.vue'),
Picture: () => import('./diy-picture.vue'),
Listmenu: () => import('./diy-listmenu.vue'),
Text: () => import('./diy-text.vue'),
Notice: () => import('./diy-notice.vue'),
GraphicNav: () => import('./diy-graphic-nav.vue'),
ImageAds: () => import('./diy-img-ads.vue'),
Search: () => import('./diy-search.vue'),
RichText: () => import('./diy-rich-text.vue'),
HorzLine: () => import('./diy-horz-line.vue'),
HorzBlank: () => import('./diy-horz-blank.vue'),
Coupon: () => import('./diy-coupon.vue'),
GoodsList: () => import('./diy-goods-list.vue'),
ManyGoodsList: () => import('./diy-many-goods-list.vue'),
RubikCube: () => import('./diy-rubik-cube.vue'),
Video: () => import('./diy-video.vue'),
Seckill: () => import('./diy-seckill.vue'),
Pintuan: () => import('./diy-pintuan.vue'),
Groupbuy: () => import('./diy-groupbuy.vue'),
Pinfan: () => import('./diy-pinfan.vue'),
Bargain: () => import('./diy-bargain.vue'),
Presale: () => import('./diy-presale.vue'),
Notes: () => import('./diy-notes.vue'),
FloatBtn: () => import('./diy-float-btn.vue'),
LiveInfo: () => import('./diy-live.vue'),
FenxiaoGoodsList: () => import('./diy-fenxiao-goods-list.vue'),
GoodsRecommend: () => import('./diy-goods-recommend.vue'),
GoodsBrand: () => import('./diy-goods-brand.vue'),
Article: () => import('./diy-article.vue'),
MerchList: () => import('./diy-merch-list.vue'),
MemberInfo: () => import('./diy-member-info.vue'),
MemberMyOrder: () => import('./diy-member-my-order.vue'),
QuickNav: () => import('./diy-quick-nav.vue'),
PaymentQrcode: () => import('./diy-payment-qrcode.vue'),
HotArea: () => import('./diy-hot-area.vue'),
FollowOfficialAccount: () => import('./diy-follow-official-account.vue'),
Map: () => import('./diy-map.vue'),
Audio: () => import('./diy-audio.vue'),
ImageNav: () => import('./diy-image-nav.vue'),
Digit: () => import('./diy-digit.vue'),
VideoList: () => import('./diy-video-list.vue'),
BottomNav: () => import('./diy-bottom-nav.vue'),
CategoryItem: () => import('./diy-category-item.vue'),
Category: () => import('./diy-category.vue'),
Icon: () => import('./diy-icon.vue'),
Group: () => import('./diy-group.vue')
}
}; };
}, },
created() { created() {
@@ -180,75 +371,7 @@ export default {
return data; return data;
} }
}, },
methods: { methods: {}
// 获取组件
getComponent(componentName) {
return this.componentMap[componentName] || null;
},
// 判断组件是否应该显示
shouldShowComponent(item) {
// 检查是否有对应的组件映射
if (!this.componentMap[item.componentName]) {
return false;
}
// 根据组件名称和附加组件状态进行判断
const addonChecks = {
StoreShow: 'store',
StoreLabel: 'store',
Coupon: 'coupon',
Seckill: 'seckill',
Pintuan: 'pintuan',
Groupbuy: 'groupbuy',
Pinfan: 'pinfan',
Bargain: 'bargain',
Presale: 'bargain',
Notes: 'notes'
};
const addonName = addonChecks[item.componentName];
if (addonName) {
return this.addonIsExist[addonName];
}
// 小程序直播组件特殊处理
if (item.componentName === 'LiveInfo') {
// #ifdef MP-WEIXIN
return true;
// #endif
// #ifndef MP-WEIXIN
return false;
// #endif
}
return true;
},
// 获取组件属性
getComponentProps(item) {
const props = {};
// 为特定组件添加额外属性
switch (item.componentName) {
case 'Search':
props.topNavColor = this.topNavColor;
props.global = this.diyGlobalData.global;
props.haveTopCategory = this.haveTopCategory;
props.followOfficialAccount = this.followOfficialAccount;
break;
case 'ManyGoodsList':
props.global = this.diyGlobalData.global;
props.scrollTop = this.scrollTop;
break;
case 'MemberInfo':
props.global = this.diyGlobalData.global;
break;
}
return props;
}
}
}; };
</script> </script>

View File

@@ -131,9 +131,6 @@ export default {
type: Object type: Object
} }
}, },
components: {
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
},
mixins: [DiyMinx], mixins: [DiyMinx],
data() { data() {
return { return {

View File

@@ -51,9 +51,6 @@ export default {
} }
} }
}, },
components: {
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
},
data() { data() {
return { return {
loading: true, loading: true,

View File

@@ -60,7 +60,6 @@ export default {
components: { components: {
uniPopup: () => import('@/components/uni-popup/uni-popup.vue'), uniPopup: () => import('@/components/uni-popup/uni-popup.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
data() { data() {
return { return {

View File

@@ -66,7 +66,6 @@ export default {
components: { components: {
uniPopup: () => import('@/components/uni-popup/uni-popup.vue'), uniPopup: () => import('@/components/uni-popup/uni-popup.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
data() { data() {
return { return {

View File

@@ -178,7 +178,6 @@ export default {
components: { components: {
uniPopup: () => import('@/components/uni-popup/uni-popup.vue'), uniPopup: () => import('@/components/uni-popup/uni-popup.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
mixins: [DiyMinx], mixins: [DiyMinx],
data() { data() {

View File

@@ -214,7 +214,6 @@ export default {
components: { components: {
uniPopup: () => import('@/components/uni-popup/uni-popup.vue'), uniPopup: () => import('@/components/uni-popup/uni-popup.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
mixins: [DiyMinx], mixins: [DiyMinx],
data() { data() {

View File

@@ -122,7 +122,6 @@ export default {
components: { components: {
uniPopup: () => import('@/components/uni-popup/uni-popup.vue'), uniPopup: () => import('@/components/uni-popup/uni-popup.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
data() { data() {
return { return {

View File

@@ -245,7 +245,6 @@ export default {
components: { components: {
uniPopup: () => import('@/components/uni-popup/uni-popup.vue'), uniPopup: () => import('@/components/uni-popup/uni-popup.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
mixins: [DiyMinx], mixins: [DiyMinx],
data() { data() {

View File

@@ -41,7 +41,6 @@ export default {
components: { components: {
uniPopup: () => import('@/components/uni-popup/uni-popup.vue'), uniPopup: () => import('@/components/uni-popup/uni-popup.vue'),
nsLogin: () => import('@/components/ns-login/ns-login.vue'), nsLogin: () => import('@/components/ns-login/ns-login.vue'),
XSkeleton: () => import('@/uni_modules/x-skeleton/components/x-skeleton/x-skeleton.vue'),
}, },
mixins: [DiyMinx], mixins: [DiyMinx],
data() { data() {

View File

@@ -1,74 +1,71 @@
module.exports = { module.exports = {
productionSourceMap: false, productionSourceMap: false,
configureWebpack: config => { configureWebpack: config => {
// 生产环境下开启极限压缩 console.log('开始尝试配置极限压缩');
if (process.env.NODE_ENV === 'production') {
console.log('生产环境下开启极限压缩');
// 确保minimizer数组存在 // 确保minimizer数组存在
if (config.optimization && config.optimization.minimizer && Array.isArray(config.optimization.minimizer)) { if (config.optimization && config.optimization.minimizer && Array.isArray(config.optimization.minimizer)) {
// 查找TerserWebpackPlugin实例而不是依赖索引 // 查找TerserWebpackPlugin实例而不是依赖索引
const terserPluginIndex = config.optimization.minimizer.findIndex(plugin => { const terserPluginIndex = config.optimization.minimizer.findIndex(plugin => {
return plugin.constructor && plugin.constructor.name === 'TerserWebpackPlugin' || return plugin.constructor && plugin.constructor.name === 'TerserWebpackPlugin' ||
(plugin.options && plugin.options.terserOptions); (plugin.options && plugin.options.terserOptions);
}); });
if (terserPluginIndex !== -1) { if (terserPluginIndex !== -1) {
// 确保options对象存在 // 确保options对象存在
if (!config.optimization.minimizer[terserPluginIndex].options) { if (!config.optimization.minimizer[terserPluginIndex].options) {
config.optimization.minimizer[terserPluginIndex].options = {}; config.optimization.minimizer[terserPluginIndex].options = {};
}
// 设置terserOptions - 极限压缩配置
config.optimization.minimizer[terserPluginIndex].options.terserOptions = {
compress: {
drop_console: true, // 去除所有console语句
drop_debugger: true, // 去除debugger语句
dead_code: true, // 移除死代码
unused: true, // 移除未使用的变量
toplevel: true, // 清理顶层作用域未使用的变量
passes: 5, // 增加压缩次数以获得更好的压缩效果
sequences: true, // 合并连续的变量声明
evaluate: true, // 提前计算常量表达式
reduce_vars: true, // 合并或移除变量
join_vars: true, // 合并变量声明
conditionals: true, // 优化条件表达式
comparisons: true, // 优化比较操作
booleans: true, // 优化布尔表达式
typeofs: true, // 优化typeof操作
collapse_vars: true, // 折叠定义后不再修改的变量
reduce_funcs: true, // 合并或移除未使用的函数
inline: true, // 内联简单函数
side_effects: true, // 移除有副作用的代码
keep_fargs: false, // 移除未使用的函数参数
keep_fnames: false, // 不保留函数名称
pure_funcs: ['console.log', 'console.warn', 'console.error', 'console.info'], // 标记为纯函数的console方法
pure_getters: true // 假设getter函数没有副作用
},
format: {
ascii_only: true, // 确保输出ASCII字符
comments: false, // 去除所有注释
beautify: false, // 不美化输出
ecma: 5, // 输出兼容ECMAScript 5
wrap_func_args: false, // 不包裹函数参数
bracketize: true, // 使用大括号包裹所有块
quote_style: 1 // 使用单引号
},
parse: {
ecma: 8, // 使用ECMAScript 8解析
bare_returns: true // 允许顶级return语句
},
mangle: {
toplevel: true, // 混淆顶层作用域的变量名
keep_fnames: false, // 不保留函数名称
keep_classnames: false // 不保留类名称
},
module: false, // 不是ES模块
sourceMap: false // 不生成source map
};
console.log('terserOptions配置完成');
} }
// 设置terserOptions - 极限压缩配置
config.optimization.minimizer[terserPluginIndex].options.terserOptions = {
compress: {
drop_console: true, // 去除所有console语句
drop_debugger: true, // 去除debugger语句
dead_code: true, // 移除死代码
unused: true, // 移除未使用的变量
toplevel: true, // 清理顶层作用域未使用的变量
passes: 5, // 增加压缩次数以获得更好的压缩效果
sequences: true, // 合并连续的变量声明
evaluate: true, // 提前计算常量表达式
reduce_vars: true, // 合并或移除变量
join_vars: true, // 合并变量声明
conditionals: true, // 优化条件表达式
comparisons: true, // 优化比较操作
booleans: true, // 优化布尔表达式
typeofs: true, // 优化typeof操作
collapse_vars: true, // 折叠定义后不再修改的变量
reduce_funcs: true, // 合并或移除未使用的函数
inline: true, // 内联简单函数
side_effects: true, // 移除有副作用的代码
keep_fargs: false, // 移除未使用的函数参数
keep_fnames: false, // 不保留函数名称
pure_funcs: ['console.log', 'console.warn', 'console.error', 'console.info'], // 标记为纯函数的console方法
pure_getters: true // 假设getter函数没有副作用
},
format: {
ascii_only: true, // 确保输出ASCII字符
comments: false, // 去除所有注释
beautify: false, // 不美化输出
ecma: 5, // 输出兼容ECMAScript 5
wrap_func_args: false, // 不包裹函数参数
bracketize: true, // 使用大括号包裹所有块
quote_style: 1 // 使用单引号
},
parse: {
ecma: 8, // 使用ECMAScript 8解析
bare_returns: true // 允许顶级return语句
},
mangle: {
toplevel: true, // 混淆顶层作用域的变量名
keep_fnames: false, // 不保留函数名称
keep_classnames: false // 不保留类名称
},
module: false, // 不是ES模块
sourceMap: false // 不生成source map
};
console.log('配置极限压缩完成');
} }
} }
} }