main-bower-files

概念

通過讀取並分析bower.json文件裏override屬性裏main路徑下定義的插件及相關依賴,返回一個文件數組。

Github

https://github.com/ck86/main-bower-files

安裝

$ npm install –save-dev main-bower-files

使用

1. 直接使用

var gulp = require('gulp');
var mainBowerFiles = require('main-bower-files');

gulp.task('TASKNAME', function() {
    return gulp.src(mainBowerFiles())
        .pipe(/* what you want to do with the files */)
});

2.也可以增加配置:

var gulp = require('gulp');
var mainBowerFiles = require('main-bower-files');

gulp.task('TASKNAME', function() {
    return gulp.src(mainBowerFiles(/* options */), { base: 'path/to/bower_components' })
        .pipe(/* what you want to do with the files */)
});

配置項

1.override option
這塊配置是配置到bower.json文件裏的

1.1 main Type: String or Array or Object
這個配置能夠指定想要選擇的文件,特別是根據環境來選擇想要的bower文件,例如根據process.env.NODE_ENV,當env=development時選擇file.js,當env=production時選擇file.min.js

{
    "overrides": {
        "BOWER-PACKAGE": {
            "main": {
                "development": "file.js",
                "production": "file.min.js"
            }
        }
    }
}

或者使用glob匹配規則來篩選想要的文件

{
    "overrides": {
        "BOWER-PACKAGE": {
            "main": "**/*.js"
        }
    }
}

1.2 ignore Type: Boolean Default: false
這是個布爾類型,選擇true或false來選擇是否忽略該包

{
    "overrides": {
        "BOWER-PACKAGE": {
            "ignore": true
        }
    }
}

1.3 dependencies Type: Object
可以重載需要的依賴,也可以set null來忽略依賴

2.common option
這些配置是配置到main-bower-files的配置中,像這樣:mainBowerFiles(/* options*/) ,這些配置一般用的比較少

  • debugging
  • main
  • env
  • paths
  • checkExistence
  • includeDev
  • includeSelf
  • filter
  • overrides

具體意思參見github解釋:

debugging Type: boolean Default: false
Set to true to enable debugging output.

main Type: String or Array or Object Default: null
You can specify for all packages a default main property which will be used if the package does not provide a main property.

env Type: String Default: process.env.NODE_ENV
If process.env.NODE_ENV is not set you can use this option.

paths Type: Object or String
You can specify the paths where the following bower specific files are located:
bower_components, .bowerrc and bower.json,For example:

mainBowerFiles({
    paths: {
        bowerDirectory: 'path/for/bower_components',
        bowerrc: 'path/for/.bowerrc',
        bowerJson: 'path/for/bower.json'
    }
})
.pipe(gulp.dest('client/src/lib'));

If a String is supplied instead, it will become the basepath for default paths.
For example:

mainBowerFiles({ paths: 'path/for/project' });
/*
 {
 bowerDirectory: 'path/for/project/bower_components',
 bowerrc: 'path/for/project/.bowerrc',
 bowerJson: 'path/for/project/bower.json'
 }
*/

checkExistence Type: boolean Default: false
Set this to true if you want that the plugin checks every file for existence.If enabled and a file does not exists, the plugin will throw an exception.

includeDev Type: mixed Default: false
You can include your devDependencies in two ways:
Set this option to inclusive or true to add the devDependencies to your dependencies
or use exclusive to exclude your dependencies

includeSelf Type: boolean Default: false
Set this to true to add the main files to your dependencies

filter Type: RegExp or function or glob Default: null
You can filter the list of files by a regular expression, glob or callback function (the first and only argument is the file path).

overrides Type: object Default: {}
Set default overrides option which can be overridden in the overrides section of the bower.json

group Type: String or Array Default: null
You can specify a group of dependencies you want to read from bower.json
For example:

{
    "dependencies": {
        "BOWER-PACKAGE-1": "*",
        "BOWER-PACKAGE-2": "*",
        "BOWER-PACKAGE-3": "*",
        "BOWER-PACKAGE-4": "*"
    },
    "group": {
        "home": [ "BOWER-PACKAGE-1" ],
        "contact": [ "BOWER-PACKAGE-4" ],
        "admin": [ "BOWER-PACKAGE-1", "BOWER-PACKAGE-2", "BOWER-PACKAGE-3" ]
    }
}
mainBowerFiles({ paths: 'path/for/project', group: 'home' });

You can select multiple groups with an array.

mainBowerFiles({ paths: 'path/for/project', group: ['home', 'contact'] });

You can include all packages except for those listed in a group with the ! operator.

mainBowerFiles({ paths: 'path/for/project', group: '!home' });
發佈了80 篇原創文章 · 獲贊 52 · 訪問量 39萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章