grunt-combohtml
Advanced tools
Comparing version 0.1.20 to 0.1.21
@@ -0,0 +0,0 @@ /* |
{ | ||
"name": "grunt-combohtml", | ||
"description": "combine build html with ssi.", | ||
"version": "0.1.20", | ||
"version": "0.1.21", | ||
"homepage": "", | ||
@@ -32,2 +32,3 @@ "author": { | ||
"joinbuffers": "~0.1.1", | ||
"juicer":"", | ||
"iconv-lite": "", | ||
@@ -43,9 +44,9 @@ "civet": "" | ||
"readmeFilename": "README.md", | ||
"_id": "grunt-combohtml@0.1.18", | ||
"_from": "grunt-combohtml@0.1.18", | ||
"_id": "grunt-combohtml@0.1.20", | ||
"_from": "grunt-combohtml@", | ||
"dist": { | ||
"shasum": "ecf31988faa90dc8dc65d2d6bf2c4db48e639cd3" | ||
}, | ||
"readme": "# grunt-combohtml\r\n\r\n合并带有SSI的html代码,并提取其中引用的本地css和js,将他们合并为一个js和一个css,并输出构建好的html\r\n\r\n## Getting Started\r\n\r\n依赖 Grunt 版本`~0.4.1`\r\n\r\n安装\r\n\r\n```shell\r\nnpm install grunt-combohtml --save-dev\r\n```\r\n\r\n安装后,在Gruntfile.js中载入任务\r\n\r\n```js\r\ngrunt.loadNpmTasks('grunt-combohtml');\r\n```\r\n\r\n## 任务配置\r\n\r\n### 步骤\r\n\r\n在`grunt.initConfig()`中添加combohtml的配置:\r\n\r\n```js\r\ngrunt.initConfig({\r\n\tcombohtml:{\r\n\t\toptions:{\r\n\t\t\tencoding:'utf8',//输出文件编码\r\n\t\t\treplacement:{\t\t// 抓取js/css文件时路径替换规则,留空为不替换\r\n\t\t\t\tfrom:/src\\//,\r\n\t\t\t\tto:'build/'\r\n\t\t\t},\r\n\t\t\trelative:'http://g.tbcdn.cn/group/trip/1.2.3/',// 本地资源文件名替换的前缀\r\n\t\t\tconvert2vm:false,// 是否将juicer语法块转换为vm格式\r\n\t\t\tconvert2php:false,// 是否将juicer语法块转换为php格式\r\n\t\t\tconvert2tms:false,// 是否将juicer语法块转换为php格式\r\n\t\t\tcomboJS:true, // 是否静态合并当前页面引用的本地js\r\n\t\t\tcomboCSS:true // 是否静态合并当前页面引用的css\r\n\t\t\tcomboExt:'-combo', // 合并后的js和css后缀\r\n\t\t}, \r\n\t\tmain:{\r\n\t\t\tfiles: [\r\n\t\t\t\t{ \r\n\t\t\t\t\texpand: true,\r\n\t\t\t\t\tcwd:'src',\r\n\t\t\t\t\tsrc: ['**/*.htm'], \r\n\t\t\t\t\tdest: 'build/',\r\n\t\t\t\t\text: '.htm'\r\n\t\t\t\t} \r\n\t\t\t] \r\n\t\t} \r\n\r\n\t}\r\n});\r\n\r\n```\r\n\r\n> relative和comboJS与comboCSS的配置互斥\r\n\r\n## 执行任务\r\n\r\n\ttask.run(['combohtml']);\r\n\r\n## 功能说明\r\n\r\n### SSI \r\n\r\n该服务依赖[jayli-server](https://npmjs.org/package/jayli-server),支持标准格式的 SSI include\r\n\r\n\t<!--#include virtual=\"file.html\" -->\r\n\r\n", | ||
"readme": "", | ||
"_resolved": "https://registry.npmjs.org/grunt-combohtml/-/grunt-combohtml-0.1.18.tgz" | ||
} |
# grunt-combohtml | ||
合并带有SSI的html代码,并提取其中引用的本地css和js,将他们合并为一个js和一个css,并输出构建好的html | ||
HTML代码的构建,合并SSI,并提取其中引用的本地css和js,执行动态和静态合并,并输出构建好的html | ||
@@ -31,27 +31,32 @@ ## Getting Started | ||
options:{ | ||
encoding:'utf8',//输出文件编码 | ||
replacement:{ // 抓取js/css文件时路径替换规则,留空为不替换 | ||
encoding:'utf8', | ||
replacement:{ | ||
from:/src\//, | ||
to:'build/' | ||
}, | ||
relative:'http://g.tbcdn.cn/group/trip/1.2.3/',// 本地资源文件名替换的前缀 | ||
// 本地文件引用替换为线上地址的前缀 | ||
relative:'http://g.tbcdn.cn/path/to/project/', | ||
// 配合relative使用,将页面中所有以CDN引用的JS/CSS文件名进行拼合 | ||
combineAssets: true, | ||
// KISSY Modules Maps File 地址 | ||
comboMapFile:'http://g.tbcdn.cn/path/to/maps.js', | ||
tidy:false, // 是否重新格式化HTML | ||
mockFilter:true, // 是否过滤Demo中的JuicerMock | ||
comboJS:false, // 是否静态合并当前页面引用的本地js为一个文件 | ||
comboCSS:false, // 是否静态合并当前页面引用的css为一个文件 | ||
convert2vm:false,// 是否将juicer语法块转换为vm格式 | ||
convert2php:false,// 是否将juicer语法块转换为php格式 | ||
convert2tms:false,// 是否将juicer语法块转换为php格式 | ||
comboJS:true, // 是否静态合并当前页面引用的本地js | ||
comboCSS:true // 是否静态合并当前页面引用的css | ||
comboExt: '-combo', // 合并后的js和css后缀 | ||
}, | ||
convert2php:false, // 是否将juicer语法块转换为php格式 | ||
comboExt:'-combo' // 静态合并后的js和css后缀 | ||
}, | ||
main:{ | ||
files: [ | ||
{ | ||
{ | ||
expand: true, | ||
cwd:'src', | ||
src: ['**/*.htm'], | ||
dest: 'build/', | ||
ext: '.htm' | ||
} | ||
] | ||
} | ||
cwd:'build', | ||
// 对'*.php'文件进行HTML合并解析 | ||
src: ['**/*.php'], | ||
dest: 'build/' | ||
} | ||
] | ||
} | ||
} | ||
@@ -62,4 +67,39 @@ }); | ||
> relative和comboJS与comboCSS的配置互斥 | ||
说明:relative和comboJS与comboCSS的配置互斥 | ||
合并文件提供两种模式,代码静态合并,即页面中相对路径引用的资源文件都会被抓取合并为一个: | ||
``` | ||
options:{ | ||
encoding:'utf8', | ||
replacement:{ | ||
from:/src\//, | ||
to:'build/' | ||
}, | ||
comboJS:true, | ||
comboCSS:true, | ||
comboExt:'-combo' | ||
} | ||
``` | ||
若希望页面中引用的相对路径都编译为绝对路径并组成combo的模式`http://url/??a.js,b.js`,需要开始`relative`字段,这时`comboJS`和`comboCSS`字段不起作用 | ||
``` | ||
options:{ | ||
encoding:'utf8', | ||
replacement:{ | ||
from:/src\//, | ||
to:'build/' | ||
}, | ||
// 本地文件引用替换为线上地址的前缀 | ||
relative:'http://g.tbcdn.cn/path/to/project/', | ||
// 配合relative使用,将页面中所有以CDN引用的JS/CSS文件名进行拼合 | ||
combineAssets: true, | ||
// KISSY Modules Maps File 地址,根据需要添加 | ||
comboMapFile:'http://g.tbcdn.cn/path/to/maps.js' | ||
} | ||
``` | ||
页面中的 JuicerMock 片段可以通过`mockFilter`字段来配置,原理参照[grunt-flexcombo](http://npmjs.org/grunt-flexcombo) | ||
## 执行任务 | ||
@@ -66,0 +106,0 @@ |
@@ -11,2 +11,4 @@ /* | ||
var http = require('http'); | ||
var mock = require('./mock.js'); | ||
var Juicer = require("juicer"); | ||
var ssi = require('./ssi').ssi, | ||
@@ -17,2 +19,3 @@ ssiChunk = require('./ssi').ssiChunk, | ||
chunkParser = require('./chunk').parse, | ||
combineAssets = require('./url_combine').parse, | ||
path = require('path'); | ||
@@ -28,2 +31,13 @@ | ||
// 一定是utf8格式 | ||
function mockFilter(chunk){ | ||
if(mock.checkDef(chunk)){ | ||
var pageParam = mock.getMockData(chunk); | ||
chunk = Juicer(chunk, pageParam); | ||
// chunk = delPageParamArea(chunk); | ||
chunk = tidy(chunk); | ||
} | ||
return chunk; | ||
} | ||
module.exports = function(grunt) { | ||
@@ -37,2 +51,3 @@ | ||
var done = this.async(); | ||
var comboMapFile = options.comboMapFile; | ||
@@ -66,2 +81,5 @@ var that = this; | ||
chunk = relativeParse(chunk,options.relative,filep).content; | ||
if(options.combineAssets){ | ||
chunk = combineAssets(chunk,comboMapFile).content; | ||
} | ||
} else { | ||
@@ -113,2 +131,5 @@ // 相对路径执行静态合并 | ||
chunkParser(chunk,function(chunk){ | ||
if(options.mockFilter){ | ||
chunk = mockFilter(chunk); | ||
} | ||
chunk = teardownChunk(chunk,options.encoding); | ||
@@ -194,30 +215,2 @@ if(!(chunk instanceof Buffer)){ | ||
function getDirFiles(dir){ | ||
var files = fs.readdirSync(dir); | ||
var res_f = []; | ||
var res_d = []; | ||
var r = ''; | ||
files.forEach(function(file){ | ||
var stat = fs.lstatSync(path.resolve(dir,file)); | ||
if (!stat.isDirectory()){ | ||
res_f.push(file); | ||
} else { | ||
res_d.push(file); | ||
} | ||
}); | ||
r += '<p><img src="http://img02.taobaocdn.com/tps/i2/T1WNlnFadjXXaSQP_X-16-16.png" /> <a href="../">parent dir</a></p><hr size=1 />'; | ||
res_d.forEach(function(file){ | ||
r += '<p><img src="http://img03.taobaocdn.com/tps/i3/T1nHRTFmNXXXaSQP_X-16-16.png" /> <a href="'+file+'/">'+file+'</a></p>'; | ||
}); | ||
res_f.forEach(function(file){ | ||
r += '<p><img src="http://img02.taobaocdn.com/tps/i2/T1Y7tPFg8eXXaSQP_X-16-16.png" /> <a href="'+file+'">'+file+'</a></p>'; | ||
}); | ||
return r; | ||
} | ||
function isDir(dir){ | ||
@@ -224,0 +217,0 @@ if(fs.existsSync(dir)){ |
@@ -10,3 +10,3 @@ // 'use strict'; | ||
var scriptExtern = '<script[^>]*? src=[\'"](.+?)[\'"].*<\/script>'; | ||
var styleExtern = '<link[^>]*? href=[\'"](.+?)[\'"].*>'; | ||
var styleExtern = '<link[^>]*? href=[\'"]([^\'"]+\.css)[\'"].*>'; | ||
@@ -13,0 +13,0 @@ var JS_Files = []; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
105945
21
2772
115
5
4
9
+ Addedjuicer@
+ Addedjuicer@0.6.15(transitive)
+ Addedoptimist@0.3.7(transitive)
+ Addeduglify-js@1.2.6(transitive)
+ Addedwordwrap@0.0.3(transitive)