Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using grunt to concatenate all vendor javascript files?

I'm using Yeoman (v1.x) with grunt (v0.4.2) to build an Angular project. The build task concatenates all my app/script JS files, but it leaves all of my dependency files unconcatenated, so that my built index.html makes these calls:

<script src="components/angular-unstable/angular.js"></script>
<script src="components/jquery/jquery.js"></script>
<script src="components/angular-resource/angular-resource.js"></script>
<script src="components/bootstrap/js/bootstrap-dropdown.js"></script>
<script src="components/moment/moment.js"></script>
<script src="components/underscore/underscore.js"></script>

<!-- xxxxxbuild:js scripts/scripts.js -->
<script src="scripts/274baf7d.scripts.js"></script>

I would like all of the components my project uses, i.e. angular.js, jquery.js, and so forth, to be in scripts.js. Is it easy to reconfigure the GruntFile to do so? Or is this not done by default for a practical reason?

like image 750
Zando Avatar asked May 04 '13 18:05

Zando


People also ask

What is grunt concat?

Concatenating with a custom separator In this example, running grunt concat:dist (or grunt concat because concat is a multi task) will concatenate the three specified source files (in order), joining files with ; and writing the output to dist/built. js . // Project configuration.

What is file concatenation in JavaScript?

0.0, the concatenation feature allows concatenation of the multiple web resources that are used by the application (JavaScript and CSS files) into a smaller number of files. Reducing the total number of files that are referenced by the application HTML results in fewer browser requests when the application starts.

What is grunt in Java?

Grunt is a task runner utility. It's used to automate various Javascript tasks including minification, obfuscation, and testing. It's also used to help with other types of static content such as Sass, CSS and even HTML.


1 Answers

Yes, this is easy to configure. Just add the vendors scripts in the sources you pass the grunt concat task.

// Project configuration.
grunt.initConfig({
  concat: {
    dist: {
      src: ['vendors/**/*.js', 'scripts/**/*.js'],
      dest: 'built.js'
    }
  }
});
like image 172
Simon Boudrias Avatar answered Nov 15 '22 17:11

Simon Boudrias