Sub Gruntfile.js Inheriting node_modules from root

Asked

Viewed 34 times

1

I am in a project (in Laravel 4.2) where they made a mega Gruntfile.js, ai decided to organize and create a Gruntfile.js for each set of "Assets" of projects.

The Problem: I don’t want to have to give each subproject an 'npm install' (because for each subproject I have a Gruntfile.js and a package.json), so I tried to force the read of the node_modules that already exists at the root, with:

module.exports = function(grunt) { "use strict";

//força path do node_modules (pra nao ter que baiar novamente)
grunt.file.setBase('../../../');

//força a leitura das dependencias do package.json principal
require("matchdep").filterDev("grunt-*").forEach(grunt.loadNpmTasks);

grunt.initConfig({
    pkg: grunt.file.readJSON("package.json"), //meu atual
    ...
});
}

This worked +or- because when I force dir into 'node_modules' it also reads Gruntfile.js from the root and then ends up running some unwanted tasks Project Structure

Someone has a light?

Structure of the Project:
/app
/exposure
/public
   /Assets
     /project1
         /js
         /css
         /img
         -Gruntfile.js
         -package json.
     /project2
         /js
         /css
         /img
         -Gruntfile.js
         -package json.
Gruntfile.js (patron saint)
package json. (patron saint)

  • I imagine that each of these projects evolves at a different pace and sooner or later you need updated versions of some modules at the same time others must have fixed versions to not break code that works. Although it seems too much work I think that each project should have its package.json and if npm install. Otherwise they are not different projects but the same project.

  • @Sergio na vdd are sub themes within a single project. I thought there would be a smarter way to take advantage of the npm_modules of Grunt, since most tasks are awesome: compile Less, minify, generate sprites

1 answer

0

My code was working, it only read the parent Gruntfile.js during the command "watch"

I put an options: {cwd:""} and it worked 100% now

Browser other questions tagged

You are not signed in. Login or sign up in order to post.