# gulp-cmd-pack

> seajs的cmd模块合并打包工具

Latest version **1.0.10** (published 2020-04-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-cmd-pack
pnpm add gulp-cmd-pack
yarn add gulp-cmd-pack
bun add gulp-cmd-pack
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2020-04-04 |
| First published | 2015-07-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 18.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | baihuibo@hotmail.com |
| Maintainers | baihuibo |
| Keywords | gulpplugin, seajs, cmd, concat, transform |

## Links

- npm: https://www.npmjs.com/package/gulp-cmd-pack
- Repository: https://github.com/baihuibo/gulp-cmd-pack
- Homepage: https://github.com/baihuibo/gulp-cmd-pack#readme
- Issues: https://github.com/baihuibo/gulp-cmd-pack/issues
- npm.io page: https://npm.io/package/gulp-cmd-pack

## Dependencies (4)

- [promise](https://npm.io/package/promise.md) ^6.1.0
- [through2](https://npm.io/package/through2.md) ^0.6.3
- [gulp-util](https://npm.io/package/gulp-util.md) ^3.0.3
- [underscore](https://npm.io/package/underscore.md) ^1.8.3

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.10 (latest) — 2020-04-04
- 1.0.9 — 2016-09-01
- 1.0.8 — 2016-06-23
- 1.0.7 — 2016-04-19
- 1.0.6 — 2015-07-31
- 1.0.5 — 2015-07-28
- 1.0.4 — 2015-07-24
- 1.0.3 — 2015-07-24
- 1.0.2 — 2015-07-20
- 1.0.1 — 2015-07-20
- 1.0.0 — 2015-07-20

## README

# gulp-cmd-pack
seajs的cmd模块合并打包工具


## 安装

```bash
npm install gulp-cmd-pack
```

## 使用

```javascript
var gulp = require('gulp');
var cmdPack = require('gulp-cmd-pack');
var uglify = require('gulp-uglify');

gulp.task('cmd', function () {
    gulp.src('path/to/module/app.js') //main文件
        .pipe(cmdPack({
            mainId: 'app', //初始化模块的id
            base: 'path/to/module/', //base路径
            alias: {
                dialog: '../bower_components/dialog/dialog.js',
                jquery: '../bower_components/jquery/dist/jquery.min.js'
            },
            ignore: ['bootstrap'] //这里的模块将不会打包进去
        }))
        .pipe(uglify({ //压缩文件，这一步是可选的
            mangle: {
                except: ['require']
            }
        }))
        .pipe(gulp.dest('path/dist/'));//输出到目录
});
```

## 模块依赖解析及合并规则

Module `path/module/a.js` :

```js
    //CommonJS 规范
    var b = require( './b' );
    module.exports =  'a' + ' ' + b;
    
    //或者cmd模块规范，require关键字必须有，不能省略
    define(function(require , exports , module){
        var b = require( './b' );
        return  'a' + ' ' + b;
    });
```

Module `path/module/b.js` :

```js
    //CommonJS
    module.exports = 'b';
    
    //or cmd
    define(function(require){
        return 'b';
    });
```

Gulp:

```js
    var cmdPack = require('gulp-cmd-wrap');
    gulp.src( 'path/module/a.js' )
        .pipe( cmdPack({
            mainId : 'a',
            base : 'path/module'
        }))
        .pipe(gulp.dest('path/dist/'));
```

Results `path/dist/a.js` :

```
define('a',['b.js'],function(require , exports , module){
    var b = require( 'b.js' );
    return 'a' + ' ' + b;
});
define('b.js' , [] ,function(require , exports , module){
    return 'b';
});
```

Use
```js
    seajs.config({
        base : 'path/dist/'
    });
    seajs.use('a');
```

## Option 参数说明
1. `option.alias`  模块别名
    作用和 `seajs.config({alias : {}})` 一样，使工具可以识别 `alias` 别名配置的路径
    
2. `option.ignore`  忽略模块列表
    写在此数组内的模块不会被打包(但是会保留require引用)
    
    Module `path/module/a.js` :
    ```js
        var $ = require('jquery');
        var b = require('./b');
        $('button').text('hello button !! ' + b);
    ```
    
    Module `path/module/b.js` : 
    ```js
        module.exports = 'b';
    ```
    
    Gulp :
    ```js
        var cmdPack = require('gulp-cmd-wrap');
        gulp.src( 'path/module/a.js' )
            .pipe( cmdPack({
                mainId : 'a',
                base : 'path/module',
                ignore : ['jquery']
            }))
            .pipe(gulp.dest('path/dist/'));
    ```
    
    Results `path/dist/a.js` :
    ```js
    define('a' , ['./b.js'] , function(require , exports , module){
       var $ = require('jquery');
       var b = require('./b.js');
       $('button').text('hello button !! ' + b);
    });
    
    define('./b.js' , [] , function(require , exports , module){
        module.exports = 'b';
    });
    ```
    
3. `option.encoding`  编码
    文件编码，默认 `UTF-8`
    
4. `option.tmpExtNames`  模板后缀名
    模板文件支持，默认值为 `['.ejs']` ，吧字符串模板转换为标准模块：
    
    Module `path/module/test.js` :
    ```js
        var testStr = require('../tmp/test.ejs');
        var str = _.template(testStr , {data : {name : 'aa'}});
        //str = '<div>aa</div>'
    ```
    Template `path/tmp/test.ejs` : 
    ```
        <div><%= data.name %></div>
    ```
    
    Gulp :
    ```js
        var cmdPack = require('gulp-cmd-wrap');
        gulp.src( 'path/module/test.js' )
            .pipe( cmdPack({
                mainId : 'test',
                base : 'path/module',
                tmpExtNames : ['.ejs'] //提供模板文件的后缀名用来区分模板
            }))
            .pipe(gulp.dest('path/dist/'));
    ```
         
    Results `path/dist/test.js` :
    ```js
    define('test' , ['../tmp/test.ejs'] , function(require , exports , module){
        var testStr = require('../tmp/test.ejs');
        var str = _.template(testStr , {name : 'aa'});
        //str = '<div>aa</div>'
    });
    
    define('../tmp/test.ejs' , [] , function(require , exports , module){
        return '<div><%= data.name %></div>'
    });
    ```

---
_Source: https://npm.io/package/gulp-cmd-pack · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
