Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

wxml-minify

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wxml-minify

miniprogram wxml minify

latest
Source
npmnpm
Version
1.0.5
Version published
Maintainers
1
Created
Source

wxml-minify

压缩wxml,减小程序包大小。微信开发者工具只压缩了js, json, css, 实际wxml也可以进行压缩来减小包大小。

使用

$ yarn add wxml-minify -D
const minify = require('wxml-minify');

minify(`
<view class="{{a ? 'b' : 'c'}}">
  <!-- comment -->
  <view wx:if="{{a && b}}">hello</view>
  <view wx:else">world</view>
  <image class="d" id="e" lazy-load />
</view>
`)
// <view class="{{a?'b':'c'}}"><view wx:if="{{a&&b}}">hello</view>
// <view wx:else">world</view>
// <image class="d"id="e" lazy-load/></view>

原理

目前通过以下途径压缩,压缩率20%以上:

  • 去除标签内空白符
  • 去除注释
  • js表达式压缩
  • 去除属性间空格
  • 内容为空的标签使用/>结尾
  • 属性值为true的使用简写形式 <image lazy-load/>

5和6可以使用prettier插件prettier-plugin-auto-close-empty-tagprettier-plugin-format-true-value-attribute)进行规范

Keywords

miniprogram

FAQs

Package last updated on 05 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts