How to reuse gulp tasks for multiple nodejs projects

I am trying to reuse my gulp tasks in two different projects. I am extracting my gulp tasks to the parent directory and trying to execute them. Here is my directory structure.

 parent/ gulp-tasks/ default.js project1/ node_modules/ gulpfile.js js/ project2/ node_modules/ gulpfile.js js/ 

That is all I have in my gulpfile.js in every project

 var requireDir = require('require-dir'); requireDir('../gulptasks'); 

This is what my default.js looks like:

 var gulp = require('gulp'); gulp.task('default', function() { //run code here }) 

When I try to run gulp default , I understand that gulp is undefined. I know that there are no node_modules in the parent directory, but is there a way to point to node_modules in each of the child projects? I don’t really want to get an answer about gulp, but how do I structure my projects to make my code reusable?

+5
source share
1 answer
  • Why do you need to structure this path? Can you break them into a repo? This way you can set each of them as dependencies.
  • You can have package.json in the root of parent . Then you will have access to the node_modules shared folders.
0
source

Source: https://habr.com/ru/post/1208456/


All Articles