7 Star 13 Fork 1

AresYe / gulp-html-resource

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

#gulp-html-resource

前端UI开发中,我们经常遇到开发引用资源路径和打包后的路径不在同一个目录,并且css,js都会进行压缩构建。 在页面测试过程,会进常手动更改路径(既麻烦又容易出错~)。

现在 就算是静态html,我们同样可以使用模板化来构建我们的UI页面啦~~

解决的痛点

  1. html模板引用资源的可配置化
  2. 可以同时进行开发调试和生产调试
  3. 解放频繁修改路径的刚度做法~~
  4. 不用依赖其他的服务端模板(ejs,jade)等

使用方式

需要一个resConfig.js配置文件

//调试模式(dev:开发模式,pro:生产模式)
var development="pro";

module.exports=function(){
	if(development=="dev"){
		return{
			suffix:"",//css,js文件后缀
			output:"html",//模板输出目录
			template:"template/**/*.html",//模板目录
			css:"dev/stylesheets",//开发版css目录
			js:"dev/javascripts",//开发版js目录
			image:"dev/images"//开发版图片目录
		}
	}
	if(development=="pro"){
		return{
			suffix:".min",
			output:"html",
			template:"template/**/*.html",
			css:"build/stylesheets",
			js:"build/javascripts",
			image:"build/images"
		}
	}
}

Template

配置需要的模板: 例如:meta.html

<link rel="stylesheet" href="../<%=cssPath%>/main<%=suffix%>.css" >
<script src="../<%=jsPath%>/main<%=suffix%>.js"></script>

index.html

<!DOCTYPE html>
<html>
  <head>
    #include('./template/common/meta.html')
    <link rel="stylesheet" href="../<%=cssPath%>/test<%=suffix%>.css" >
    <script src="../<%=jsPath%>/test<%=suffix%>.js"></script>
  </head>
  <body>
    <img src="../<%=imgPath%>/1.png" />
  </body>
</html>

Html

输出后的html:

开发模式:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="../dev/stylesheets/main.css" >
	<script src="../dev/javascripts/main.js"></script>
    <link rel="stylesheet" href="../dev/stylesheets/test.css" >
	<script src="../dev/javascripts/test.js"></script>
  </head>
  <body>
    <img src="../dev/images/1.png" />
  </body>
</html>

生产模式:

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="../build/stylesheets/main.min.css" >
    <script src="../build/javascripts/main.min.js"></script>
    <link rel="stylesheet" href="../build/stylesheets/test.min.css" >
	<script src="../build/javascripts/test.min.js"></script>
  </head>
  <body>
    <img src="../build/images/1.png" />
  </body>
</html>

初始化

在gulpfile.js中配置:

var gulp=require("gulp"),
	templateToHtml=require("./lib/index");


gulp.task("templateToHtml",function(){
	var resource=new templateToHtml();
});
The MIT License (MIT) Copyright (c) 2016 area Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

html模板资源配置自动化 展开 收起
JavaScript
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
JavaScript
1
https://gitee.com/area/gulp-html-resource.git
git@gitee.com:area/gulp-html-resource.git
area
gulp-html-resource
gulp-html-resource
master

搜索帮助