@moomfe/hu-template-minifier

1.3.3 • Public • Published

Hu-Template-Minifier

该类库将使用了 模板字符串 - 标签 ( Template literals ) 功能实现模板定义的类库中的 HTML 代码进行压缩.



Overview

html`
  <div title=${ 'title' } class="a ${ b } c ${ d }">
    <div>...</div>
    ${
      html`
        <div>
          <span>Something ...</span>
        </div>
      `
    }
    <div>...</div>
  </div>
`

// ↓↓↓

html`<div title=${ 'title' } class="a ${ b } c ${ d }"> <div>...</div> ${
      html`<div> <span>Something ...</span> </div>`
    } <div>...</div> </div>`

Installation

npm install @moomfe/hu-template-minifier

Usage

// 使用 minifier 的 rollup 插件
const minifier = require('@moomfe/hu-template-minifier/rollup');

rollup({
  plugins: [
    minifier(/* options */)
  ]
});

Plugin Options

{
  // 需要进行压缩的文件后缀
  extensions: [ '.js' ], // 默认值
      // 可包含多个
      extensions: [ '.js', '.ts' ],

  // 需要包含的文件
  include: undefined, // 默认值 ( 包含全部 )
      // 普通匹配
      include: 'index.js',
      // 使用 minimatch 格式进行匹配
      include: 'components/*/index.js',
      include: 'components/**/index.js',
      // 使用正则进行匹配
      include: /api\.js/,
      // 使用支持的格式组成数组进行匹配
      include: [
        'components/*/index.js',
        /api\.js/
      ],

  // 需要从已包含的文件中排除的文件
  // 使用的格式与 include 选项一致, 不再进行举例
  exclude: undefined, // 默认值

  // 保留一个空格
  conservativeCollapse: true,

  // 移除注释
  removeComments: false
}

Supports

Transplant From

License

Hu-Template-Minifier is licensed under a MIT License.

Package Sidebar

Install

npm i @moomfe/hu-template-minifier

Weekly Downloads

0

Version

1.3.3

License

MIT

Unpacked Size

46 kB

Total Files

17

Last publish

Collaborators

  • zhang-wei