Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

126
Vistas
Grunt doesn't "require" JavaScript files from all folders in path when building the Destination file

I have a source with a lot of files and I'm generating a single file as the destination file , however when the file is generated it doesn't requires some js files that are located in path

The file that needs to be required is located at src/components/employees/index.js.

It's contents:

module.exports = { 
  IncludeMe: 'Some-Payload-Goes-Here......'
}

The main.js file:

const employeesData = require('src/components/employees')
const getEmployeeData = (... .... ....) => {
  try {     
   ...
   ...   // Data manipulations
   ...
   
   return { 
   
    ...employeesData
   };
  } catch (err) {
    return err;
  }
}

module.exports = getEmployeeData;

And this is the GruntFile

module.exports = (grunt) => {
    grunt.initConfig({
      'string-replace': {
        dist: {
          files: {
            'output/': [
              'src/**/*.js',
              'main.js',
              '!src/**/*.test.js',
              '!src/**/index.js',
            ],
          },
          options: {
            replacements: [{
              pattern: /module\.exports[\s]?=[\s]?([a-zA-Z0-9,\{\}\s]+)\;/ig,
              replacement: ''
            },
              {
                pattern: /const[\s]?([a-zA-Z0-9\{\}\s\,]+)[\s]?=[\s]?require\(([a-zA-Z0-9.\/\\\']+)\)\;/ig,
                replacement: ''
              }]
          }
        }
      },
      uglify: {
        prod: {
          files: { 'output/main.js': ['output/src/**/*.js', 'output/main.js'] },
          options: {
            report: true,
            preserveComments: false,
            compress: true,
            beautify: true
          },
        },
      },
      clean: ['output/src/', 'output/main.js']
    });
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-string-replace');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.registerTask('default', ['string-replace', 'uglify', 'clean']);
  };
  

The generated file looks as follows:

   try {
        var u = {
            ...u = {},
            ...employeesData 
        };
        return Object.keys(u).length ? u : {};
    } catch (r) {
        
    }

Notice it doesn't put the contents of employeesData.

Any idea how to fix this ?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda