+-
如何将gulp任务拆分成多个文件

我有这个gulpgulpfile.js文件夹

const source = require('vinyl-source-stream');
const gulp = require('gulp');

module.exports = function(args) {
  gulp.task('default', function() {});
}

我有这个projectgulpfile.js文件夹

const projectGulp = require('../gulp/gulpfile.js')

projectGulp();

project文件夹里面我有一个package.jsonvinyl-source-stream添加为dev依赖,现在我在这个文件夹上运行yarn install

当我运行gulp时,我得到Cannot find module vinyl-source-stream错误。

如果我对gulp文件夹做,并做yarn install vinyl-source-stream它工作正常。现在我得到Task default is not in your gulpfile错误。

0
投票

我建议你做以下事情:

  $ yarn install --check-files

--check-files标志验证是否未从node_modules文件夹中删除包。 (见yarn documentation)。

万一它不起作用,你应该尝试:

  $ rm -rf ./node_modules/
  $ npm cache clean
  $ npm install

然后可能看看vinyl-source-stream是否应该是:

  $ ls ./node_modules/vinyl-source-stream

由于我主要在Windows上工作,我遇到了所有可能的纱虫。我曾经有过与this类似的问题,那就是简单地删除所有内容并调用npm帮助的情况。纱线有时无法弄清楚依赖性是否会丢失,尤其是gulp。