使用 gulp 而不使用全局 gulp//edit: 并且不链接到 bin js 文件

Using gulp without global gulp //edit: and without linking to the bin js file(使用 gulp 而不使用全局 gulp//edit: 并且不链接到 bin js 文件)
本文介绍了使用 gulp 而不使用全局 gulp//edit: 并且不链接到 bin js 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个 gulpfile.js,当在命令行中输入 gulp 时,它可以完美运行.

I have a gulpfile.js that runs through perfectly when typing gulp into the commandline.

gulp bash 命令真正做的就是调用 package.json >> 中指定的 js 文件.斌>>全局安装的 gulp 的 gulp.

All the gulp bash command really does is calling the specified js file in package.json >> bin >> gulp of the globally installed gulp.

现在我想在没有全局安装的 gulp 的情况下运行 gulpfile,只需键入 node gulpfile.js 显然失败并且已经经常提到,尽管 gulp 是在本地安装并且在开始时需要gulpfile.js

Now I want to run the gulpfile without the globally installed gulp by simply typing node gulpfile.js which fails obviously and already has been mentioned quite often, despite gulp being installed locally and required at the beginning of the gulpfile.js

在没有 cli 工具的情况下使用 gulp 可以很容易地将 gulp 用作其他 npm 插件的一部分.

Using gulp without the cli tool would make it possible to use gulp as part of other npm plugins very easily.

注意:
当原始 gulpfile.js 已通过 gulp cli 工具启动时,需要另一个 gulpfile.js 从原始 gulpfile.js 工作.

Note:
Requiring another gulpfile.js works from an original gulpfile.js when this original gulpfile.js has been started via the gulp cli tool.

问题:
在不需要全局 cli gulp 工具(//或在本地链接到它)的情况下运行/需要 gulp 的最佳方式是什么?例如当 gulp 只是一个本地安装的依赖项时,能够简单地从另一个 js 文件中要求它.(换句话说,从 JS 内部以编程方式启动 gulp,无需任何 CLI 干预)

Question:
What is the best way of running/requiring gulp without the need for the global cli gulp tool (//edit: or linking to it locally)? e.g. being able to simply require it from another js file when gulp is only a locally installed dependency. (in other words starting gulp programmatically from inside JS without CLI intervention of any kind)

推荐答案

在package.json中

In package.json

"scripts": {
   "gulp": "gulp"  
},

然后这个命令 npm run gulpnpm 还提供了将额外参数传递给命令的能力.这仅适用于 npm >= 2.0

And then this command npm run gulp Also npm provides the ability to pass extra parameters to your commands. This is only the case for npm >= 2.0

更新:没有 bin 链接

Update: Without bin link

您可以查看 node_modules/.bin/gulpnode_modules/gulp/bin/gulp.js 文件以了解如何启动 gulp(第 129 行很有趣)

You can check the node_modules/.bin/gulp or node_modules/gulp/bin/gulp.js file to see how you can start gulp (Line 129 is interesting)

我认为这应该可行:

var gulp = require('gulp');

gulp.task('default', function() {
    console.log('do something');
});

gulp.start.apply(gulp, ['default']);

这篇关于使用 gulp 而不使用全局 gulp//edit: 并且不链接到 bin js 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I can get a text of all the cells of the table using testcafe(如何使用 testcafe 获取表格中所有单元格的文本)
node_modules is not recognized as an internal or external command(node_modules 未被识别为内部或外部命令)
How can I create conditional test cases using Protractor?(如何使用 Protractor 创建条件测试用例?)
PhantomJS and clicking a form button(PhantomJS 并单击表单按钮)
Clicking #39;OK#39; on alert or confirm dialog through jquery/javascript?(在警报上单击“确定或通过 jquery/javascript 确认对话框?)
QunitJS-Tests don#39;t start: PhantomJS timed out, possibly due to a missing QUnit start() call(QunitJS-Tests 不启动:PhantomJS 超时,可能是由于缺少 QUnit start() 调用)