[英]gulp-load-plugins not loading plugins
gulp-load-plugins
is not loading any plugins. gulp-load-plugins
没有加载任何插件。 Can anyone suggest why this might be? 任何人都可以建议为什么会这样?
Node: v0.12.0
NPM: v2.7.3
My package.json
: 我的
package.json
:
{
"name": "foo",
"version": "0.0.1",
"dependencies": {},
"devDependencies": {
"gulp": "^3.8.11",
"gulp-load-plugins": "^0.9.0"
}
}
My gulpfile.js
: 我的
gulpfile.js
:
var gulp = require('gulp');
var gulpLoadPlugins = require('gulp-load-plugins');
var plugins = gulpLoadPlugins();
console.log(JSON.stringify(plugins)); // {}
gulp.task('default');
Install other gulp plugins. 安装其他gulp插件。
tl;dr TL;博士
If that is your complete package.json
, looks like you have no other gulp plugins installed. 如果这是你的完整
package.json
,看起来你没有安装其他gulp插件。
Lets say the following is your package.json
: 让我们说以下是你的
package.json
:
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... 你
$ npm install
一切,然后......
gulpfile.js 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');
Try setting lazy loading to false. 尝试将延迟加载设置为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. 正如其他人提到的那样,安装一些插件。
Let me show you what i have and how i do it , maybe that will help. 让我告诉你我拥有什么以及我是如何做到的,也许这会有所帮助。
My package.json
: 我的
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
: 我如何运行
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- . 正如你所看到的,我所有的管道都被称为.pipe($。plugin()),意思是$代表gulp-。 If you have a plugin named gulp-name-secondname you call it like this: .pipe($.nameSecondname()) .
如果你有一个名为gulp-name-secondname的插件,你可以这样称它:.pipe($。nameSecondname())。
Top were i require gulp-load-plugins i have camelize set to true . 顶部是我需要gulp-load-plugins我将camelize设置为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. 小心gulp-load-plugins,因为它减慢了你的任务,例如我运行gulp-webserver,当我使用gulp-load-plugins时,任务在200ms后完成,而如果我正常使用它则需要20ms。 So don't use with everything, play with it see how much performance you lose on each task and prioritize.
因此,不要使用所有内容,玩它看看你在每个任务上失去了多少性能并确定优先级。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.