使用grunt构建seajs教程一

准备工作:

假设你已经会使用grunt,不熟悉的自行谷歌。

我们这边将构建分为三步进行:

1、使用 grunt-cmd-transport 将Seajs模块转换为Modules/Transport规范。

2、使用 grunt-cmd-concat 合并模块。在合并模块前一定要先转换为Modules/Transport规范的模块。

3、grunt-contrib-uglify 压缩JS

项目结构:

app // 存放seajs代码模块

js   // 第三方js库

build // 存放 grunt-cmd-transport 编译的中间文件

dist  // 最终发布的目录

Start

1、使用npm init 命令创建package.json

2、加入以下依赖:

  "dependencies": {
    "grunt": "~0.4.1",
    "grunt-cmd-concat": "~0.2.0",
    "grunt-contrib-uglify": "~0.2.0",
    "grunt-contrib-clean": "~0.4.0",
    "grunt-cmd-transport": "^0.4.1"  // 0.5.1不知为何有个目录不能构建
  }

3、使用 npm install 命令安装依赖

4、创建 Gruntfile.js G必须为大写,写入以下代码

module.exports = function(grunt){
    grunt.initConfig({
        pkg : grunt.file.readJSON('package.json'),
        //grunt-cmd-concat 配置
        transport : {
            options : {
                debug : false,
                paths: ['app/'],
                include: 'all'
            },
            cywebos : {
                files : [{
                    expand : true,
                    cwd  : 'app/',
                    src  : ['**/*.js', '!datas/*.js'],
                    filter : 'isFile',
                    dest : 'build'
                }]
            }
        }
    });
    grunt.registerTask('default', ['transport']);
};

 

运行命令:grunt transport:cywebos

 

posted @ 2015-06-19 11:16  一只找壳的蜗牛  阅读(148)  评论(0编辑  收藏  举报