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 ?