grunt-combohtml
Advanced tools
Comparing version 0.1.8 to 0.1.9
{ | ||
"name": "grunt-combohtml", | ||
"description": "combine build html with ssi.", | ||
"version": "0.1.8", | ||
"version": "0.1.9", | ||
"homepage": "", | ||
@@ -40,3 +40,3 @@ "author": { | ||
"readmeFilename": "README.md", | ||
"_id": "grunt-combohtml@0.1.7", | ||
"_id": "grunt-combohtml@0.1.8", | ||
"_from": "grunt-combohtml@", | ||
@@ -46,3 +46,3 @@ "dist": { | ||
}, | ||
"readme": "" | ||
"readme": "# grunt-combohtml\n\n合并带有SSI的html代码,并提取其中引用的本地css和js,将他们合并为一个js和一个css,并输出构建好的html\n\n## Getting Started\n\n依赖 Grunt 版本`~0.4.1`\n\n安装\n\n```shell\nnpm install grunt-combohtml --save-dev\n```\n\n安装后,在Gruntfile.js中载入任务\n\n```js\ngrunt.loadNpmTasks('grunt-combohtml');\n```\n\n## 任务配置\n\n### 步骤\n\n在`grunt.initConfig()`中添加combohtml的配置:\n\n```js\ngrunt.initConfig({\n\tcombohtml:{\n\t\toptions:{\n\t\t\tencoding:'utf8',//输出文件编码\n\t\t\treplacement:{\t\t// 抓取js/css文件时路径替换规则,留空为不替换\n\t\t\t\tfrom:/src\\//,\n\t\t\t\tto:'build/'\n\t\t\t},\n\t\t\tcomboJS:true, // 是否静态合并当前页面引用的本地js\n\t\t\tcomboCSS:true // 是否静态合并当前页面引用的css\n\t\t}, \n\t\tmain:{\n\t\t\tfiles: [\n\t\t\t\t{ \n\t\t\t\t\texpand: true,\n\t\t\t\t\tcwd:'src',\n\t\t\t\t\tsrc: ['**/*.htm'], \n\t\t\t\t\tdest: 'build/',\n\t\t\t\t\text: '.htm'\n\t\t\t\t} \n\t\t\t] \n\t\t} \n\n\t}\n});\n\n```\n\n## 说明\n\n该服务依赖[jayli-server](https://npmjs.org/package/jayli-server),支持标准格式的 SSI include\n\n\t<!--#include virtual=\"file.html\" -->\n\n## 执行任务\n\n\ttask.run(['combohtml']);\n" | ||
} |
@@ -48,3 +48,6 @@ /* | ||
var result = extract.parse(chunk); | ||
var result = extract.parse(chunk,{ | ||
comboJS:typeof options.comboJS == 'undefined' || options.comboJS === true, | ||
comboCSS:typeof options.comboCSS == 'undefined' || options.comboCSS === true | ||
}); | ||
chunk = result.content; | ||
@@ -51,0 +54,0 @@ |
@@ -15,2 +15,4 @@ // 'use strict'; | ||
var CONTENT = ''; | ||
var comboJS = true; | ||
var comboCSS = true; | ||
@@ -24,4 +26,8 @@ /* | ||
function parse(content){ | ||
function parse(content,o){ | ||
CONTENT = ''; | ||
JS_Files = []; | ||
CSS_Files = []; | ||
comboCSS = o.comboCSS; | ||
comboJS = o.comboJS; | ||
content = css(content); | ||
@@ -69,5 +75,11 @@ content = js(content); | ||
return content.replace(/<\/head>/i,function(){ | ||
return '<!--comboJS--><script src="@@script"></script>\n' | ||
+ '<!--comboCSS--><link href="@@style" rel="stylesheet" />\n' | ||
+ '</head>'; | ||
var comboStr = ''; | ||
if(comboJS){ | ||
comboStr += '<!--comboJS--><script src="@@script"></script>\n'; | ||
} | ||
if(comboCSS){ | ||
comboStr += '<!--comboCSS--><link href="@@style" rel="stylesheet" />\n'; | ||
} | ||
comboStr += '</head>'; | ||
return comboStr; | ||
}); | ||
@@ -78,5 +90,8 @@ } | ||
content = content.replace(new RegExp('(<!--css:([^>]*?\.css)-->)','gi'),function(){ | ||
content = content.replace(new RegExp('(<!--css:([^>]*?)-->)','gi'),function(){ | ||
var args = arguments; | ||
if(/http:/i.test(args[2])){ | ||
if(/http:/i.test(args[2]) || comboCSS === false){ | ||
if(/\.ico$/i.test(args[2])){ | ||
return '<link type="image/x-icon" rel="shortcut icon" href="'+args[2]+'" />'; | ||
} | ||
return '<link rel="stylesheet" href="'+args[2]+'" />'; | ||
@@ -88,5 +103,5 @@ } else { | ||
content = content.replace(new RegExp('(<!--js:([^>]*?\.js)-->)','gi'),function(){ | ||
content = content.replace(new RegExp('(<!--js:([^>]*?)-->)','gi'),function(){ | ||
var args = arguments; | ||
if(/http:/i.test(args[2])){ | ||
if(/http:/i.test(args[2]) || comboJS === false){ | ||
return '<script src="'+args[2]+'"></script>'; | ||
@@ -93,0 +108,0 @@ } else { |
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
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
42405
1113