npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-h5packer

v0.3.1

Published

移动H5页面打包工具,可以根据描述将资源打包进html,替换资源为全局资源包CDN地址,减少请求数量

Downloads

3

Readme

gulp-h5packer

移动H5页面打包工具

为了减少移动端H5页面的请求数量,往往会在发布前将页面依赖的JS, CSS文件嵌入html中,如果一些资源有全局资源包的支持,也会将其替换为CDN地址。

本插件可以根据link, script, img标签中的标记,选择将文件内容嵌入或者替换为CDN地址。

关键版本节点

0.3.0: 脱离支付宝H5开发环境独立发展

0.2.0: 替换HTML解析引擎为cheerio,提升2倍以上的效率 增加对配置项的支持

0.1.7: 可以支持网络文件的嵌入和BASE64

0.1.6: 支持img标签内图片的BASE64, 支持js和CSS的压缩

用法

首先,在待处理的html文件中加入标记。标记共有三种:

内容替换标记

<link rel="stylesheet" type="text/css" href="something.css" data-replace="true">
<script src="something.js" data-replace="true"></script>

这样会读取资源文件,把内容嵌入在标签的位置。script标签会删去src和data-replace属性,并在标签内嵌入内容。link标签会在后面产生一个style节点,并嵌入内容。标签本身会被删除。

目前插件会自动压缩css和js文件,未来可以通过配置文件取消这一功能。

资源URL替换标记

<link rel="stylesheet" type="text/css" href="local/amui.css" data-replace="amui">
<script src="zepto.js" data-replace="static-zepto"></script>

在data-replace中写入"static-全局资源包名称",即可替换为相应的地址。

该功能由于目前脱离了支付宝环境,暂时没有默认值,请在初始化参数中传入:

{
  staticUrl: {
    name: 'http://url.to.path'
  }
}

图片Base64转化标记

<img src="fake.png" data-replace="base64">

注意: 目前Base64转码不考虑文件大小因素,请不要在大图片上加这个标记!

引用

设置完HTML后,在gulpfile.js中引用:

gulp.task('pack', function (){
  var replacer = require('gulp-h5replacer');
  gulp.src('./build/*/*.html')
    .pipe(replacer())
    .pipe(gulp.dest('./pack'));
});

Todo

  1. 将文件引用的图片和无法嵌入的资源文件自动上传到蜻蜓上
  2. 增加配置选项
  3. 支持CSS内的图片BASE64