javascript gulp-load-plugins 不加载插件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29288870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gulp-load-plugins not loading plugins
提问by Ben Aston
gulp-load-plugins
is not loading any plugins. Can anyone suggest why this might be?
gulp-load-plugins
没有加载任何插件。谁能建议为什么会这样?
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');
回答by SteamDev
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
包.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');
回答by Shawn Mclean
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.
正如其他人提到的,安装一些插件。
回答by Dragutescu Alexandru
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- . If you have a plugin named gulp-name-secondname you call it like this: .pipe($.nameSecondname()) .
正如你所看到的,我所有的管道都被称为 .pipe($.plugin()) ,意思是 $ 代表 gulp- 。如果你有一个名为 gulp-name-secondname 的插件,你可以这样称呼它: .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 .
最重要的是我是否需要 gulp-load-plugins 我已将骆驼化设置为 true 。延迟加载仅加载您使用的插件,而不是所有插件。
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.
小心使用 gulp-load-plugins 因为它会减慢您的任务速度,例如我运行 gulp-webserver ,当我将它与 gulp-load-plugins 一起使用时,如果我正常使用它,则任务在 200 毫秒后完成,而 20 毫秒。所以不要用所有的东西,玩它看看你在每项任务上损失了多少性能并确定优先级。