用Grunt搭建基于LESS的前端html开发框架
. 安装Node.js
http://nodejs.org/download/
2. 加速NPM安装
npm install -g cnpm --registry=http://r.cnpmjs.org
安装cnpm国内镜像, 以后所有npm命令换成用cnpm执行即可
3. 安装grunt
npm install -g grunt-cli
4. 在工程目录下建立配置文件Gruntfile.js
本例中, 所做的事情包括:
a. 组合一些less到一个文件
b. 用less编译不同版本的css
c. 填充html模版并部署
d. 实时侦听以上变化并自动做相应编译
<!-- code begin -->
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
concat: {
options: {
banner: '/*! APP.common.css@<%= pkg.name %> - v<%= pkg.version %> - ' +
'<%= grunt.template.today("yyyy-mm-dd") %> */'
},
mobileLess: {
src: ['src/mobile/less/APP_common/*.less'],
dest: 'src/mobile/less/APP.common_grunt.less',
}
},
less: {
development: {
options: {
compress: false,
yuicompress: false
},
files: {
"css/APP.common.css": "src/mobile/less/APP.common_grunt.less",
"css/APP.web.index.css": "src/web/less/APP.web.index.less"
}
},
production: {
options: {
modifyVars: {
imagepath_page: '"/misc/images/"',
imagepath: '"/misc/images/"'
},
compress: true,
yuicompress: true,
optimization: 2
},
files: {
"css/pub/APP.common.css": "src/mobile/less/APP.common_grunt.less",
"css/pub/APP.web.index.css": "src/web/less/APP.web.index.less"
}
}
},
htmlbuild: {
mobile: {
src: 'src/mobile/html/*.html',
desc: './',
options: {
beautify: true,
relative: true,
sections: {
layout: {
footbar: 'src/mobile/html/inc/footbar.html'
}
}
}
},
web: {
src: 'src/web/html/*.html',
desc: './'
}
},
watch: {
options: {
livereload: true
},
grunt: {
files: ['Gruntfile.js']
},
styles: {
files: [
'src/**/less/*.less',
'src/**/less/**/*.less'
],
tasks: [
'concat:mobileLess',
'less'
],
options: {
nospawn: true
}
},
htmls: {
files: [
'src/**/html/*.html',
'src/**/html/**/*.html'
],
tasks: [
'htmlbuild'
],
options: {
nospawn: true
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-html-build');
grunt.registerTask('default', ['watch']);
};
<!-- code end -->
5. 建立并配置 package.json
在项目目录下运行 npm init , 填写出现的各种选项, 或者直接回车到完成
打开生成的 package.json, 并添加 devDependencies 节点 --如果后续的编译出错, 往往是这里的版本号不够新
<!-- code begin -->
{
"name": "html",
"version": "0.0.0",
"description": "",
"main": "Gruntfile.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.4.0",
"grunt-contrib-less": "~0.11.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-html-build": "~0.3.2"
}
}
<!-- code end -->
6. 安装项目依赖包
在项目目录下运行 cnpm install , 将把 package.json->devDependencies下注明的依赖包下载到 node_modules
7. 运行grunt
在项目目录下执行 grunt 即可
用Grunt搭建基于LESS的前端html开发框架的更多相关文章
- 【前端福利】用grunt搭建自动化的web前端开发环境-完整教程
jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用! 1. 前言 各位web前端开发人员,如果你现在还不知道grunt或者听说过 ...
- 转:【前端福利】用grunt搭建自动化的web前端开发环境-完整教程
原文地址:http://blog.csdn.net/wangfupeng1988/article/details/46418203 jQuery在使用grunt,bootstrap在使用grunt,百 ...
- 用grunt搭建自动化的web前端开发环境实战教程(详细步骤)
用grunt搭建自动化的web前端开发环境实战教程(详细步骤) jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用!前端自动化, ...
- 用grunt搭建自动化的web前端开发环境-完整教程
原稿:http://www.cnblogs.com/wangfupeng1988/p/4561993.html#!comments jQuery在使用grunt,bootstrap在使用grunt,百 ...
- 用grunt搭建自动化的web前端开发环境
用grunt搭建自动化的web前端开发环境 jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用! 1. 前言 各位web前端开发 ...
- grunt搭建自动化的web前端开发环境(转)
1. 前言 各位web前端开发人员,如果你现在还不知道grunt或者听说过.但是不会熟练使用grunt,那你就真的真的真的out了(三个“真的”重复,表示重点).至于grunt的作用,这里不详细说了, ...
- 使用grunt搭建自动化的web前端开发环境
使用grunt搭建自动化的web前端开发环境 我们一定经常听过grunt和gulp,它们都是用于搭建自动化的web前端开发环境的,这里主要介绍grunt的使用,值得一提的是,jQuery.bootst ...
- 基于React 的前端UI开发框架 及与Electron 的结合 https://cxjs.io/
1.cxjs 基于React 的前端UI开发框架 https://cxjs.io/ coreu http://coreui.io/ 2.antd-admin ...
- 转: 【前端福利】用grunt搭建自动化的web前端开发环境-完整教程
http://blog.csdn.net/wangfupeng1988/article/details/46418203
随机推荐
- Report_客制化Excel报表中的XLS标记(案例)
2014-06-06 Created By BaoXinjian
- mvc无法找到资源
昨天装了vs2015,但是第二步没有完成.今天急急忙忙的用13打开一个mvc的项目,但是添加的控制器怎么都不能访问. 无法找到资源. 说明: HTTP 404.您正在查找的资源(或者它的一个依赖项)可 ...
- JAVA 下拉列表和滚动条
//下拉列表和滚动条 import java.awt.*; import javax.swing.*; public class Jiemian7 extends JFrame{ JPanel mb1 ...
- 集成paypal支付
https://developer.paypal.com cocoapods 管理 引入 pod 'PayPal-iOS-SDK' 1.在appdelegate #import <PayPalM ...
- text透明无边框
<input type="text" style="border:0px;background-color:transparent;outline:none;&qu ...
- 如何判断VS.NET设计时?
方法一: if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv") //...Then ...
- Nginx 内置全局变量
Nginx在使用过程中,有不少的内置全局变量可以用做条件判断和编程控制,本文总结一些已知的指令,以供参考. $arg_PARAMETER 这个变量包含在查询字符串时GET请求PARAMETER的值. ...
- arm交叉编译器gnueabi、none-eabi、arm-eabi、gnueabihf、gnueabi区别
命名规则 交叉编译工具链的命名规则为:arch [-vendor] [-os] [-(gnu)eabi] arch – 体系架构,如ARM,MIPSvendor – 工具链提供商os – 目标操作系统 ...
- oracle插入主键数据、sequence和触发器
一.创建表: id number;并设为主键 name VARCHAR2(20 BYTE) 二. 插入数据 2.1 insert into addservice.test_table (id,na ...
- 《Head First 设计模式》ch.2 观察者(Observer)模式
观察者模式 定义了对象之间一对多以来,这样一来,当一个对象改变状态时,它所有的依赖者都会收到通知并自动更新 设计原则-松耦合 松耦合将对象之间的互相依赖降到了最低——只要他们之间的接口仍被遵守 观察者 ...