更多gulp常用插件使用請訪問:gulp常用插件匯總
gulp-load-plugins這是一款批量引入package.json文件中的依賴項工具。
更多使用文檔請點擊訪問gulp-load-plugins工具官網。
安裝
npm install --save-dev gulp-load-plugins
使用
給定一個package.json
文件,該文件具有以下依賴關系:
{
"dependencies": {
"gulp-jshint": "*",
"gulp-concat": "*"
}
}
之前你在Gulpfile.js中使用插件的方式:
const gulp = require('gulp');
const gulpJshint = require('gulp-jshint');
const gulpConcat = require('gulp-concat');
現在到您的Gulpfile.js:
const gulp = require('gulp');
const plugins = require('gulp-load-plugins')();
const gulpJshint = plugins.jshint; ////其實可以不用定義變量,直接在需要使用這個插件的地方 plugins.jshint() 就可以了
const gulpConcat = plugins.concat; //其實可以不用定義變量,直接在需要使用這個插件的地方 plugins.concat() 就可以了
有了這個插件您不必在gulfile.js中手動引入每個gulp插件了。