I have this problem: In order to refactor the frontend part of an existing project, I'm trying to use Grunt compiler into this. This project has the following structure:
file1.jsp loads file1.js file2.jsp loads file2.js
So the javascript files generated from grunt contains file1 + file2. The problem is: if in the file1.js I have:
$(document).on('ready', function()...)
var funct = function() {
...
};
$('.class').on('click', function(){...})
And also in the file2 I have another definition of the funct variable and also the jquery part, with the generated javascript file, file1.jsp and file2.jsp calls both the same functions. I would like to keep the previous behavior, but I would also to load a single js file, instead of multiple js files in different jsp pages.
UPDATE:
I a few words, I have this structure:
js
- eu
- folder1
-- file1.js
- folder2
-- file2.js
...
What I want to do is: minify all js files inside js/eu folder, than concat all the minified files and load the applicationScripts.min.js file into my index.jsp instead of loading all single files inside the related jsp file.
The Gruntfile.js is:
concat:
{ options:
{ separator: '\n' },
dist: {
src: [ 'js/eu_min/**/*.min.js' ],
dest: 'js/applicationScripts.min.js' } },
uglify:
{ options:
{ pretty: true },
dist: {
files: {
expand: true,
src: "js/eu/**/*.js",
dest: "js/eu_min/",
ext: ".min.js" } } },
watch: { files: [ 'js/eu/**/*.js' ],
tasks: [ 'uglify', 'concat' ] }
Thanks for your support