22 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 23 |
24 |├── .gitattributes ├── .gitignore ├── .npmignore ├── README.md ├── example ├── assets │ ├── css │ │ ├── a.css │ │ └── b.css │ └── js │ │ ├── a.js │ │ ├── b.js │ │ └── c.js ├── dist │ ├── inline.html │ ├── inlineCss.html │ ├── inlineJs.html │ ├── inlineScript.html │ └── inlineStyle.html ├── gulpfile.js ├── inline.html ├── inlineCss.html ├── inlineJs.html ├── inlineScript.html ├── inlineStyle.html └── test.js ├── index.js └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | npm-debug.log 3 | .idea 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | #node js 6 | #======================================= 7 | 8 | node_modules 9 | example 10 | npm-debug.log 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # gulp-html-inline 2 | 3 | [![NPM version][npm-image]][npm-url] 4 | [![Downloads][downloads-image]][downloads-url] 5 |  6 | 7 | [npm-image]: https://img.shields.io/npm/v/gulp-html-inline.svg?style=flat-square 8 | [npm-url]: https://npmjs.org/package/gulp-html-inline 9 | [downloads-image]: http://img.shields.io/npm/dm/gulp-html-inline.svg?style=flat-square 10 | [downloads-url]: https://npmjs.org/package/gulp-html-inline 11 | 12 | combo and minify `css` and `js` to html. no matter the file is online or not. 13 | 14 | ## Features 15 | 16 | + css、js自动内联 17 | + css、js可选择压缩 18 | + css、js文件的url上query为 "_toinline",即表示内联 19 | + css、js文件的url上query为 "_tohash",即表示获取文件MD5值作为缓存版本号 20 | 21 | ## Usage 22 | 23 | ```javascript 24 | var gulp = require('gulp'); 25 | var htmlInline = require('gulp-html-inline'); 26 | 27 | gulp.src('inline.html') 28 | .pipe(htmlInline({ minifyJs: true })) 29 | .pipe(gulp.dest('dist')); 30 | ``` 31 | 32 | ## Html 33 | ```html 34 | 35 | 36 | 37 | 38 | 39 | 48 | 49 | 50 | 51 | 52 | 53 | 60 | 61 | ``` 62 | ## Options 63 | ```javascript 64 | gulp.src('./src/*.html') 65 | .pipe(htmlInline({ 66 | queryKey: '_rvc', //指定需要内联的url后面必须带缓存query key, 默认 _rvc 67 | toInline: '_toinline', //指定需要内联的url后面必须带的query key, 默认 _toinline 68 | toHash: '_tohash', //指定需要内联的url后面必须带的query key, 默认 _toinline 69 | hashSize: 8, //指定hash值长度,默认 8 70 | minifyJs: true //选择是否压缩js, 71 | //资源文件路径 72 | basePath: '../' 73 | })) 74 | // ... 75 | ``` 76 | 77 | #License 78 | ISC 79 | -------------------------------------------------------------------------------- /example/assets/css/a.css: -------------------------------------------------------------------------------- 1 | .layout{ 2 | background-color: white; 3 | font-family: "Microsoft YaHei"; 4 | font-size: 1.2em; 5 | color: #000; 6 | } 7 | .layout .content{ 8 | width: 100%; 9 | height: 100%; 10 | padding: 0px; 11 | position: relative; 12 | } 13 | .layout .content .left{ 14 | position: absolute; 15 | left: 0; 16 | top: 0; 17 | width: 35% 18 | height: 100%; 19 | } 20 | .layout .content .right{ 21 | position: absolute; 22 | right: 0; 23 | top: 0; 24 | width: 65%; 25 | height: 100%; 26 | } -------------------------------------------------------------------------------- /example/assets/css/b.css: -------------------------------------------------------------------------------- 1 | .app{ 2 | background-color: powderblue; 3 | font-family: "Microsoft YaHei"; 4 | font-size: 1.2em; 5 | color: #555; 6 | } 7 | .app .content{ 8 | width: 100%; 9 | height: 100%; 10 | padding: 10px 20px; 11 | } 12 | .app .content > p{ 13 | font-size: inherit; 14 | color: orange; 15 | line-height: 1.65em; 16 | } -------------------------------------------------------------------------------- /example/assets/js/a.js: -------------------------------------------------------------------------------- 1 | ;(function(){ 2 | 3 | 'use strict'; 4 | 5 | var SYST = function(){ 6 | this.name = 'Rodey'; 7 | }; 8 | 9 | window.SYST = new SYST(); 10 | 11 | }).call(this); 12 | -------------------------------------------------------------------------------- /example/assets/js/b.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Rodey on 2015/11/5. 3 | */ 4 | 5 | 6 | window.onload = function(){ 7 | 8 | console.log(SYST); 9 | 10 | }; 11 | -------------------------------------------------------------------------------- /example/assets/js/c.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by Rodey on 2015/11/5. 3 | */ 4 | 5 | document.body.addEventListener('click', function(evt){ 6 | var text = document.querySelector('#content').innerHTML; 7 | alert(text); 8 | }, false); 9 | -------------------------------------------------------------------------------- /example/dist/inline.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |22 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 23 |
24 |20 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 21 |
22 |19 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 20 |
21 |19 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 20 |
21 |22 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 23 |
24 |44 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 45 |
46 |20 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 21 |
22 |19 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 20 |
21 |19 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 20 |
21 |44 | 压缩html中的css和js(可将link和script中的href或者src引入的文件直接压缩替换到html中) 45 |
46 |