grunt + sass 使用记录
环境依赖
- Nodejs for grunt
- Ruby for sass
配置文件
package.json
{
"name": "app",
"version": "1.0.0",
"devDependencies": {
"grunt": "^0.4.5",
"grunt-contrib-watch": "^0.6.1",
"grunt-contrib-sass": "^0.8.1",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-concat": "^0.5.0",
"grunt-contrib-cssmin": "^0.10.0",
"grunt-contrib-uglify": "^0.6.0",
"grunt-contrib-htmlmin": "^0.3.0",
"grunt-contrib-imagemin": "^0.9.2"
}
}
Gruntfile.js
module.exports = function (grunt) {
// grunt config
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
sass: {
options: {
style: 'expanded'
},
scss: {
files: [{
src: 'src/css/main.scss',
dest: 'src/css/main.css'
}]
}
},
jshint: {
files: ['gruntfile.js', 'src/js/*.js']
},
concat: {
options: {
banner: '/*! <%= pkg.name %> <%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n',
separator: '\n/*---------分割线---------*/\n'
},
js: {
files: [{
src: ['src/js/base.js', 'src/js/script.js'],
dest: 'dist/js/<%= pkg.name %>.js'
}]
}
},
cssmin: {
css: {
files: [{
src: 'src/css/main.css',
dest: 'dist/css/<%= pkg.name %>.min.css'
}]
}
},
uglify: {
js: {
files: [{
src: 'dist/js/<%= pkg.name %>.js',
dest: 'dist/js/<%= pkg.name %>.min.js'
}]
}
},
htmlmin: {
options: {
removeComments:true,
collapseWhitespace:true
},
dist: {
files: [{
expand: true, // all html
cwd: 'src/',
src: ['**/*.html'],
dest: 'dist/'
}]
}
},
imagemin: {
img: {
files: [{
expand: true, // all images
cwd: 'src/',
src: ['**/*.{png,jpg,gif}'],
dest: 'dist/'
}]
}
},
watch: {
css: {
files: 'src/css/main.scss',
tasks: ['sass']
},
js: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
}
}
});
// load task
grunt.loadNpmTasks('grunt-contrib-sass');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.loadNpmTasks('grunt-contrib-imagemin');
grunt.loadNpmTasks('grunt-contrib-watch');
// regist task
grunt.registerTask('compile', ['watch']);
grunt.registerTask('default', ['sass', 'jshint', 'concat', 'cssmin', 'uglify']);
grunt.registerTask('html', ['htmlmin']);
grunt.registerTask('img', ['imagemin']);
};
参考资源:
grunt + sass 使用记录的更多相关文章
- sass安装记录
之前曾经安装过一次sass,不过可惜没使用,现在换了电脑重新安装,又上网找了些资料,终于安装成功,现在就当做个记录方便下次安装. 首先 到官网下载个最新版的ruby :http://rubyinsta ...
- window 安装 sass compass 记录
1.安装Ruby 安装sass 和compass 需要 Ruby 的环境,还区分xp 和win7-8 下版本区别 ruby 官网中文 ruby 官网英文 注意: xp: 下载 [xp不能下载包含64位 ...
- css3/sass 样式记录
css3 width: calc(50% - 10px) sass 1.奇偶行 .classNameA { background:red; &:nth-child(even) { backgr ...
- Grunt 使用记录
想了解Grunt,可以先去官网 看看. 第一次接触Grunt是通过Coding的移动端项目, 刚开始因为环境的问题折腾了一两天,然后就顿悟了. Grunt构建工具对于前端开发而言,简直是神器(ps.虽 ...
- grunt配置sass项目自动编译
1.安装Ruby和SASS 首先我们需要在电脑上安装Ruby和SASS.如果您使用的是Mac,您就没必要安装Ruby.如果您使用的是Window系统,你需要安装Ruby. 2.安装Nodejs 由于使 ...
- 使用Grunt启动和运行
开始使用Grunt 大多数开发人员都一致认为,JavaScript开发的速度和节奏在过去的几年里已经相当惊人.不管是Backbone.js和Ember.js的框架还是JS Bin社区,这种语言的发展变 ...
- 【转】自动化任务运行器 Grunt 迅速上手
原文转自:http://blog.jobbole.com/51586/ 这篇文章将带领你用Grunt来提速和优化网站开发的流程.首先我们会简短介绍Grunt的功能,然后我们直接上手,介绍如何用Grun ...
- Grunt自动化构建环境搭建
1.环境准备 需要安装Git.Node.Bower.Grunt.Ruby NodeJS https://nodejs.org/en/ Ruby http://rubyinstaller.org/ ...
- Grunt Part 1
Grunt Part 1 Objectives and Outcomes In this exercise, you will learn to use Grunt, the task runner. ...
随机推荐
- if if 和 if elif 的区别
再一次编程中意外使用了if if 也实现了 if elif的功能,所以搜索了下其中的区别: 1.if if 和 if elif 是有区别的,只是在某些情况下才会一样的效果: 2.随意使用会导致意外的错 ...
- leetcode:234. Palindrome Linked List
这个题目非常好.http://blog.csdn.net/u012249528/article/details/47124771给出了三种解法,其中前两个是不满足条件的,不过具有参考价值: 第一种办法 ...
- 《精通Spring4.X企业应用开发实战》读后感第六章(使用外部属性文件)
- p2371&bzoj2118 墨墨的等式
传送门(bzoj) 题目 墨墨突然对等式很感兴趣,他正在研究a1x1+a2y2+…+anxn=B存在非负整数解的条件,他要求你编写一个程序,给定N.{an}.以及B的取值范围,求出有多少B可以使等式存 ...
- jquery的命名空间
function A( event ){ alert( 'A' );}function B( event ){ alert( 'B' );}function C( event ){ ...
- Note: File Recipe Compression in Data Deduplication Systems
Zero-Chunk Suppression 检测全0数据块,将其用预先计算的自身的指纹信息代替. Detect zero chunks and replace them with a special ...
- ProtoBuf练习(一)
基础数据类型 protobuf语言的基础字段类型相当于C++语言的基础类型 工程目录结构 $ ls proto/ TFixed.proto TInt.proto TScalar.proto TStr. ...
- 采用DCT进行图像压缩
一.实验目的:熟悉变换编码的图像压缩方法 二.实验内容:以所给图像为例,采用dct进行图像压缩编码,通过改变模板矩阵中非零元素的个数,得到不同缩编码图像, 根据公式 ,编写程序计算原图像和dct变换后 ...
- 2017-10-26 NOIP模拟赛2
财富 (treasure) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有n个小伙伴.每个小伙伴有一个身高hi. 这个游戏是这样的,LYK生活的环境是 ...
- 2017-10-13 NOIP模拟赛
入阵曲 #include<iostream> #include<cstdio> #define maxn 401 #ifdef WIN32 #define PLL " ...