Gruntjs: grunt-usemin使用心得
grunt-usemin:
Replaces references to non-optimized scripts or stylesheets into a set of HTML files
usemin exports 2 different tasks:
useminPrepareprepares the configuration to transform specific construction (blocks) in the scrutinized file into a single line, targeting an optimized version of the filesuseminreplaces the blocks by the file they reference, and replaces all references to assets by their revisioned version if it is found on the disk. This target modifies the files it is working on.
Usually, useminPrepare is launched first, then the steps of the transformation flow (for example, concat, uglify, and cssmin), and then, in the end usemin is launched.
我的工作目录
workspace/
——app/
——js/
——tpl/
Gruntfile.js配置
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
useminPrepare: {
html: ['app/tpl/**/*.html'],
options: {
// 测试发现这里指定的dest,是usemin引入资源的相对路径的开始
// 在usemin中设置assetsDirs,不是指定的相对路径
// List of directories where we should start to look for revved version of the assets referenced in the currently looked at file
dest: 'build/tpl' // string type
}
},
usemin: {
html: ['build/tpl/**/*.html'], // 注意此处是build/
options: {
assetsDirs: ['build/js']
}
},
copy: {
html: {
expand: true, // 需要该参数
cwd: 'app/',
src: ['tpl/**/*.html'], // 会把tpl文件夹+文件复制过去
dest: 'build'
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-usemin');
// 最后就是顺序了,没错concat,uglify在这里哦!
grunt.registerTask('default', [
'copy:html',
'useminPrepare',
'concat:generated',
'uglify:generated',
'usemin'
]);
};
源html结构
<body>
<p>this is a grunt usemin</p> <script src="../js/globle.js"></script> <!-- build:js ../js/page.js -->
<script src="../js/libs.js"></script>
<script src="../js/page.js"></script>
<!-- endbuild -->
</body>
打包后的html
<body>
<p>this is a grunt usemin</p> <script src="../js/globle.js"></script> <script src="../js/page.js"></script>
</body>
感谢gruntjs,yeoman
https://github.com/yeoman/grunt-usemin
Gruntjs: grunt-usemin使用心得的更多相关文章
- Grunt usemin
yeoman/grunt-usemin 用来将 HTML 文件中(或者 templates/views)中没有优化的 script 和 stylesheets 替换为优化过的版本. usemin 暴露 ...
- Grunt usemin前端自动化打包流程
前端优化是尽量减少http请求,所以我们需要尽量合并压缩文件,然后调用压缩后的文件,比如多个css文件压缩成一个,多个js文件合并压缩等,usemin能够自动在html中使用压缩后的文件,达到上面的目 ...
- Grunt Part 2
Objectives and Outcomes In this exercise, you will continue to learn to use Grunt, the task runner. ...
- windows下安装node环境,以及grunt试水笔记
grunt,当下前端界知名度最高的工作流处理工具. 在一线的互联网公司,它早已经被用烂了,而我真正接触,是在去年年底... 期间还因为内心太杂分心玩乐而荒废学途,以致到最近才重拾学业,在这里BS一下自 ...
- 前端资料QQ群交流
转:https://github.com/jsfront/src/blob/master/qq.md 这本来是我QQ群内部的一份公共约定的日常交流规则,后来得到大伙的一致认可,并用实际行动来捍卫它,使 ...
- JavaScript资源分享
一. 资源教程: 综合类 前端知识体系 前端知识结构 Web前端开发大系概览 Web前端开发大系概览-中文版 Web Front-end Stack v2.2 En类资源汇总 免费的编程中文书籍索引 ...
- 终极教程【zhong】
just for a better future! 资源教程 aiim 综合类 前端知识体系 前端知识结构 Web前端开发大系概览 We ...
- Top JavaScript Frameworks, Libraries & Tools and When to Use Them
It seems almost every other week there is a new JavaScript library taking the web community by storm ...
- js 框架及uI框架
转载自:http://www.techweb.com.cn/network/system/2015-12-23/2245809.shtml 这篇文章主要描述现今流行的一些 Javascript web ...
随机推荐
- 开源游戏“2048”IOS移植版
简介: 这个游戏是我在今年(2014/05)课余时闲着无聊做的一个益智类小游戏,总共花了4个工作日才完成,为了游戏的效率,做了很多优化,目前在IE5以上浏览器能够流畅运行,运行时如果屏幕分辨率不兼容, ...
- MetaWeblog API调用
http://rpc.cnblogs.com/metaweblog/webenh 在网上闲逛,突然对博客的接口感兴趣,经考察,多数博客都对metaWeblog Api 提供了支持,虽然windows ...
- mysql 判断表字段或索引是否存在
判断字段是否存在: DROP PROCEDURE IF EXISTS schema_change; DELIMITER // CREATE PROCEDURE schema_change() BEGI ...
- Serena Dimensions 介绍
Serena Dimensions是配置管理工具,基于进程的软件更改和配置管理解决方案. 官方网址:http://www.serena.com/index.php/en/products/applic ...
- asp.net mvc 之旅—— 第二站 窥探Controller下的各种Result
平时我们在Action中编码的时候,我们都知道所有的Action返回值类型都是ActionResult,并且我们的返回值也是各种奇葩,比如:Json(),Content(), View()等等...当 ...
- Access字段类型“查阅向导”
1.显示控件有:“列表框”和“组合框”两种 2.组合框:第一个字段为“填充字段” 3.通过查阅向导建立的会自动添加“关系”(外键),因此在删除或修改字段时需要先删除二者关系,最好不通过“查阅向导”建立 ...
- SQL Server调优系列基础篇(并行运算总结)
前言 上三篇文章我们介绍了查看查询计划的方式,以及一些常用的连接运算符.联合运算符的优化技巧. 本篇我们分析SQL Server的并行运算,作为多核计算机盛行的今天,SQL Server也会适时调整自 ...
- 使用SQL检测死锁
第一步:首先创建两个测试表,表goods_sort和goods 表goods_sort:创建并写入测试数据 IF EXISTS(SELECT name FROM sysobjects WHERE na ...
- Ezchip Tilera Tile-Mx100: Der 100-ARM-Netzwerkprozessor
Ezchip Tilera Tile-Mx100: Der 100-ARM-Netzwerkprozessor ARM-Kerne statt VLIW-Einheiten: Tileras neue ...
- SpringMVC从入门到精通之第二章
这一章原本我是想写一个入门程序的,但是后来仔细想了一下,先从下面的图中的组件用代码来介绍,可能更效果会更加好一点.第一节:开发准备介绍之前先说下我的开发调试环境:JDK 1.7的64位 .Eclips ...