html查看器processor,htmlprocessor

这个模块是grunt-processhtml和gulp-processhtml任务背后的HTML处理器。它支持通过特殊注释处理HTML文件,可以指定输出文件、传递数据、设置环境、递归处理、更改注释标记等功能。使用该工具,可以方便地列出替换的文件,以便于构建过程中的文件管理和合并操作。例如,可以用来自动化CSS和JS文件的合并和压缩,而无需手动更新构建配置。
摘要由CSDN通过智能技术生成

Process html file using special comments

htmlprocessor

htmlprocessor.svg

node-htmlprocessor.svg?branch=master

htmlprocessor.svg

node-htmlprocessor.svg

npm install -g htmlprocessor

Grunt/Gulp task

This module is the processor behind grunt-processhtml, gulp-processhtml tasks.

For plenty of examples visit the documentation.

CLI

Outputs help

$ htmlprocessor -h

Usage: htmlprocessor file-to-process.html [options]

-h, --help display this help message

-v, --version display the version number

-l, --list file to output list of replaced files

-o, --output file to output processed HTML to

-d, --data pass a JSON file to processor

-e, --env specify an environment

-r, --recursive recursive processing

-c, --comment-marker change the comment marker

-i, --include-base set the directory to include files from

-s, --strip strip blocks matched by other environments

--custom-block-type specify custom block type

Outputs version number

$ htmlprocessor -v

Outputs to file-to-process.processed.html.

$ htmlprocessor file-to-process.html

Outputs to processed/file.html.

$ htmlprocessor file-to-process.html -o processed/file.html

Pass some data

$ htmlprocessor file-to-process.html -o processed/file.html -d data.json

Specify an environment

$ htmlprocessor file-to-process.html -o processed/file.html -e dev

Allow recursive processing

$ htmlprocessor file-to-process.html -o processed/file.html -r

Change the comment marker to

$ htmlprocessor file-to-process.html -o processed/file.html --comment-marker process

List option

Create a list of files that were replaced and use that list to streamline the build process.

Note: This new option does not affect in any way the previous existing functionality (i.e. it's backward compatible).

$ htmlprocessor file-to-process.html -o processed/file.html --list wrk/replacement.list

Assumning you have this code in an HTML (or JSP)

.

.

.

.

.

.

.

.

.

The file "wrk/replacement.list" will contain something like this:

file-to-process.html:js/bower_components/bootstrap/dist/css/bootstrap.css

file-to-process.html:content/bootstrap-responsive.min.css

file-to-process.html:content/styles.css

file-to-process.html:content/myApplicationStyles.css

file-to-process.html:js/bower_components/jquery/dist/jquery.js

file-to-process.html:js/bower_components/angular/angular.js

file-to-process.html:js/bower_components/angular-route/angular-route.js

file-to-process.html:app/app.js

file-to-process.html:app/filters/filters.js

file-to-process.html:app/controllers/applications.js

And you can use these commands to concatenate and eventually minify without having to update the build to tell

it where it should pickup each files. Also, in this way it orders the global file content in the same manner

as your individual includes originally were.

sh -c "cat `cat wrk/replacement.list | grep '\.js$' | cut -d: -f2` > dist/js/myApplication.js"

sh -c "cat `cat wrk/replacement.list | grep '\.css$' | cut -d: -f2` > dist/css/myApplication.css"

If you processed more than a single "html" file, you can change the grep like this:

... | grep 'file-to-process.html:.*\.js$' | ... > dist/js/myApplication.js

... | grep 'other-file-to-process.html:.*\.js$' | ... > dist/js/myApplicationOther.js

The originating file name is included in the list file for that very purpose.

License

Repository

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值