Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequireJs minifcation - complex directory structure

we have a problem at work, we are using require js but our folder structure is a bit different, we have the following:

--js folder 
   --Folder
      ---some base js files
    -Folder 
       ---main
            --src
                ---require.js 
                --- require JS modules
         --plugin js files
         --more js files

We would like to minify all these JS files to a SINGLe js file for production as such

---js folder
    --min-all.js 

Is this possible? if so how? .. Any help would be appreciated!

Thanks!

I just thought I would clarify that the other Folders contain standard non modular javascript files, they can be a mix of plugins or simple javascript helpers.

like image 583
Nima Avatar asked Dec 19 '12 16:12

Nima


1 Answers

The short answer is: yes, RequireJS can do this.

Basically, you will need to create one JS file that requires all of the resources that you want minified. Then you will point the optimizer at that file and it will mash them all together.

require(["one", "../another/two", "folder/three", "folder/inner/four" ... ]);

If that file was called myfile.js, you would run the optimizer with similar parameters to this:

node r.js -o name=myfile out=optimized.js

If you have libraries or other files that you do not want included into the final optimized file, you would use the excludeShallow flag. e.g.

node r.js -o name=myfile out=optimized.js excludeShallow=jquery.min

There are more options so you should check out their optimization documentation if you haven't yet.

like image 53
Jeff Avatar answered Sep 21 '22 00:09

Jeff