Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulp-load-plugins not loading plugins

gulp-load-plugins is not loading any plugins. Can anyone suggest why this might be?

Node: v0.12.0
NPM: v2.7.3

My package.json:

{
  "name": "foo",
  "version": "0.0.1",
  "dependencies": {},
  "devDependencies": {
    "gulp": "^3.8.11",
    "gulp-load-plugins": "^0.9.0"
  }
}

My gulpfile.js:

var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();

console.log(JSON.stringify(plugins)); // {}

gulp.task('default');
like image 361
Ben Aston Avatar asked Mar 26 '15 21:03

Ben Aston


3 Answers

Install other gulp plugins.

tl;dr

If that is your complete package.json, looks like you have no other gulp plugins installed.

Lets say the following is your package.json:

package.json

{
  "name": "foo",
  "version": "0.0.1",
  "dependencies": {},
  "devDependencies": {
    "gulp": "^3.8.11",
    "gulp-load-plugins": "^0.9.0",
    "gulp-rename": "^1.2.0",
    "gulp-concat": "^2.5.2"
  }
}

You $ npm install everything, then...

gulpfile.js

var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();

// `plugins.rename` should exist
// `plugins.concat` should exist

console.log(JSON.stringify(plugins));

gulp.task('default');
like image 149
SteamDev Avatar answered Nov 05 '22 13:11

SteamDev


Try setting lazy loading to false.

var gulp = require('gulp');
var plugins= require('gulp-load-plugins')({lazy:false});

console.log(JSON.stringify(plugins));

gulp.task('default');

And as others mentioned, install some plugins.

like image 7
Shawn Mclean Avatar answered Nov 05 '22 14:11

Shawn Mclean


Let me show you what i have and how i do it , maybe that will help.

My package.json :

{
  "dependencies": {
    "gulp": "*",
    "gulp-autoprefixer": "*",
    "gulp-html-validator": "0.0.5",
    "gulp-image-optimization": "^0.1.3",
    "gulp-plumber": "*",
    "gulp-rev-collector": "^0.1.4",
    "gulp-rev-manifest-replace": "0.0.5",
    "gulp-ruby-sass": "*",
    "gulp-sass": "*",
    "gulp-scss-lint": "^0.1.10",
    "gulp-sourcemaps": "*",
    "imagemin-optipng": "^4.2.0",
    "imagemin-pngquant": "^4.0.0",
    "vinyl-paths": "^1.0.0"
  },
  "devDependencies": {
    "del": "^1.1.1",
    "gulp-cached": "^1.0.4",
    "gulp-concat": "^2.5.2",
    "gulp-cssmin": "^0.1.6",
    "gulp-filesize": "0.0.6",
    "gulp-gzip": "^1.0.0",
    "gulp-htmlhint": "0.0.9",
    "gulp-htmlmin": "^1.1.1",
    "gulp-if": "^1.2.5",
    "gulp-imagemin": "^2.2.1",
    "gulp-load-plugins": "^0.8.0",
    "gulp-rename": "^1.2.0",
    "gulp-rev": "^3.0.1",
    "gulp-uglify": "^1.1.0",
    "gulp-useref": "^1.1.1",
    "gulp-webserver": "^0.9.0",
    "run-sequence": "^1.0.2"
  }
}

How i run gulp-load-plugins :

 'use strict';
    var gulp = require('gulp'),
          $ = require('gulp-load-plugins')({
            pattern: ['gulp-*', 'gulp.*'],
            replaceString: /\bgulp[\-.]/,
            lazy: true,
            camelize: true
          }),

And this is an example of a plugin:

 // html optimization 
      gulp.task('htmloptimize', function () {
          return gulp.src(dev.html) 
            .pipe($.htmlmin({
              collapseWhitespace: true
            }))
            .pipe(gulp.dest(dist.dist))
      });

As you can see all my pipes are called .pipe($.plugin()) meaning $ stands for gulp- . If you have a plugin named gulp-name-secondname you call it like this: .pipe($.nameSecondname()) .

Top were i require gulp-load-plugins i have camelize set to true . Lazy loading loads only the plugins you use not all of them .

Careful with gulp-load-plugins because it slows your tasks , for example i run gulp-webserver , when i use it with gulp-load-plugins the task finishes after 200ms versus 20ms if i use it normally. So don't use with everything, play with it see how much performance you lose on each task and prioritize.

like image 4
Dragutescu Alexandru Avatar answered Nov 05 '22 15:11

Dragutescu Alexandru