. 安装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开发框架的更多相关文章

  1. 【前端福利】用grunt搭建自动化的web前端开发环境-完整教程

    jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用! 1. 前言 各位web前端开发人员,如果你现在还不知道grunt或者听说过 ...

  2. 转:【前端福利】用grunt搭建自动化的web前端开发环境-完整教程

    原文地址:http://blog.csdn.net/wangfupeng1988/article/details/46418203 jQuery在使用grunt,bootstrap在使用grunt,百 ...

  3. 用grunt搭建自动化的web前端开发环境实战教程(详细步骤)

    用grunt搭建自动化的web前端开发环境实战教程(详细步骤) jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用!前端自动化, ...

  4. 用grunt搭建自动化的web前端开发环境-完整教程

    原稿:http://www.cnblogs.com/wangfupeng1988/p/4561993.html#!comments jQuery在使用grunt,bootstrap在使用grunt,百 ...

  5. 用grunt搭建自动化的web前端开发环境

    用grunt搭建自动化的web前端开发环境 jQuery在使用grunt,bootstrap在使用grunt,百度UEditor在使用grunt,你没有理由不学.不用! 1. 前言 各位web前端开发 ...

  6. grunt搭建自动化的web前端开发环境(转)

    1. 前言 各位web前端开发人员,如果你现在还不知道grunt或者听说过.但是不会熟练使用grunt,那你就真的真的真的out了(三个“真的”重复,表示重点).至于grunt的作用,这里不详细说了, ...

  7. 使用grunt搭建自动化的web前端开发环境

    使用grunt搭建自动化的web前端开发环境 我们一定经常听过grunt和gulp,它们都是用于搭建自动化的web前端开发环境的,这里主要介绍grunt的使用,值得一提的是,jQuery.bootst ...

  8. 基于React 的前端UI开发框架 及与Electron 的结合 https://cxjs.io/

    1.cxjs  基于React 的前端UI开发框架    https://cxjs.io/ coreu   http://coreui.io/ 2.antd-admin                ...

  9. 转: 【前端福利】用grunt搭建自动化的web前端开发环境-完整教程

    http://blog.csdn.net/wangfupeng1988/article/details/46418203

随机推荐

  1. Linux删除乱码文件名或者目录名

    有时,rz上传文件失败或者不小心输入命令会产生乱码文件名.因为用rm 删除特殊字符基本无效,故找到了下面两种简单易用的方法: 例子: [langxiaowei@mirror:~]$ ls ??     ...

  2. 错误代码2104:无法下载Silverlight应用程序。请查看Web服务器设置

    今天调试Silverlight程序,把ClientBin文件夹下的.xap文件删除后遇到这样一个问题:错误代码2104:无法下载Silverlight应用程序.请查看Web服务器设置.在网上查了一下, ...

  3. 编译器错误消息: CS0234: 命名空间“Purple”中不存在类型或命名空间名称“Model”(是否缺少程序集引用?)

    编译错误 “/storeimg”应用程序中的服务器错误. 编译错误 说明: 在编译向该请求提供服务所需资源的过程中出现错误.请检查下列特定错误详细信息并适当地修改源代码. 编译器错误消息: CS023 ...

  4. ylbtech-Bill(发票管理)-数据库设计

    ylbtech-dbs:ylbtech-Bill(发票管理)-数据库设计 -- =============================================-- DatabaseName ...

  5. Ubuntu Server如何配置SFTP

    SH File Transfer Protocol是一个比普通FTP更为安全的文件传输协议.(参考资料:http://en.wikipedia.org/wiki/SSH_File_Transfer_P ...

  6. Python标准库04 文件管理 (部分os包,shutil包)

    作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! 在操作系统下,用户可以通过操作系统的命令来管理文件,参考linux文件管理相关命令 ...

  7. iOS应用架构谈:架构设计的方法论

    缘由 之前安居客iOS app的第二版架构大部分内容是我做的,期间有总结了一些经验.在将近一年之后,前同事zzz在微信朋友圈上发了一个问题:假如问你一个iOS or Android app的架构,你会 ...

  8. rbenv安装ruby2.3.0在线安装不上。老子出绝招了(更新)

    今天把系统换成Linux mint了.感觉比ubuntu的好用太多,细节真是不错,Ubuntu感觉就是毛坯房,Linux mint真是精装修啊 问题来了.安装rbenv后,然后安装rbenv-buil ...

  9. 无法创建spool文件

    是因为没有用管理员运行CMD,并且数据库不需要使用超级管理员登录.

  10. MYSQL C API : mysql_real_query()

    enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, MYSQL_TYPE_SHORT, MYSQL_TYPE_LONG, MYSQ ...