2

Presently using grunt-contrib-requirejs plugin which has got

optimize : 'uglify2'

but no concat files to a single file option is found in that plugin. how to add or any example. I need all js files to be concatenated and uglified to a single file which has to be loaded in the very first load itself.

Thanks.

Bachan-user3143666
  • 343
  • 2
  • 5
  • 14
  • I'm having a hard time tryin to do this. Have you managed to make it work? My situation is pretty much like yours. I have some files that need to be concatenated and some others that do not. And some of them must be grouped like modules. Using the modules options from requirejs is not helping at all. – darksoulsong Mar 06 '14 at 09:18
  • As @Andrey Shustariov said It is possible, using modules array and dir field instead of name and out fields in build config, But at the time of constructing require modules itself everything needs to be done and dependencies needs to be managed .Later in the grunt build file it is possible to make customized multiple builds as per our requirement by mentioning each modules , like set of templates : templateA, templateB etc as one module , templateC, templateD not under grunt build, templateF and tempalteZ as another module etc.,Hope this gives u an idea. – Bachan-user3143666 Mar 07 '14 at 09:26

1 Answers1

0

Here is boilerplate repository that does exactly what you need.

Andrew Shustariov
  • 2,530
  • 1
  • 17
  • 17
  • Thanks, But i want required js libraries, templates and custom written libraries as separate files, so is it possible to fragment and make the single file into three or more files – Bachan-user3143666 Jan 22 '14 at 09:25
  • Templates are available in repository (see /src/hello/ folder). Please, clerify what do you mean by 'fragmenting'? – Andrew Shustariov Jan 22 '14 at 09:44
  • Followed the procedures as in boilerplate above and have built the file using grunt , its cleanly concatenated and uglified but how to refer it in html page's require source data-main. referring the optimized file shows no effect on page load rather no script error is also shown in console.. – Bachan-user3143666 Jan 22 '14 at 09:45
  • 1
    Fragmenting in the sense, The optimized file has got all the JavaScript files referred in requirejs config, But is there any way to make the templates (in my case it is .hbs handlebars template files) as one js file , and libraries such as Jquery, twitter bootstrap etc as on js file and the custom written JavaScript application js files as one js file . but all these should be modulated in requirejsmainconfig, is such configuration available.. – Bachan-user3143666 Jan 22 '14 at 09:55
  • As I understood, you want to put diferrent parts of code in diferrent modules (not single). It is possible, using [modules](https://github.com/jrburke/r.js/blob/master/build/example.build.js#L338) array and [dir](https://github.com/jrburke/r.js/blob/master/build/example.build.js#L58) field instead of [name](https://github.com/jrburke/r.js/blob/master/build/example.build.js#L420) and out fields in build config – Andrew Shustariov Jan 22 '14 at 10:30
  • About boilerplate code: to build application you need to execute ```grunt build``` and then server ```out``` folder via http. Default ```grunt``` task only runs grunt-watch - good for development process. – Andrew Shustariov Jan 22 '14 at 10:34