Question

I'm a bit confused of why the yeoman angular generator has the concat tasks inside the useminPrepare task since the concat and uglify are run later in the build task.

// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
  html: '<%= yeoman.app %>/index.html',
  options: {
    dest: '<%= yeoman.dist %>',
    flow: {
      html: {
        steps: {
          js: ['concat', 'uglifyjs'],
          css: ['cssmin']
        },
        post: {}
      }
    }
  }
},



  grunt.registerTask('build', [
    'clean:dist',
    'bowerInstall',
    'useminPrepare',
    'concurrent:dist',
    'autoprefixer',
    'concat',
    'ngmin',
    'copy:dist',
    'cdnify',
    'cssmin',
    'uglify',
    'rev',
    'usemin',
    'htmlmin'
  ]);

can someone enlighten me?

Was it helpful?

Solution

The useminPrepare task does not actually do any minification, but instead it parses HTML and sets the appopriate configuration for other tasks. For example, if you have this in your HTML:

<!-- build:js js/app.js -->
<script src="js/app.js"></script>
<script src="js/controllers/thing-controller.js"></script>
<script src="js/models/thing-model.js"></script>
<script src="js/views/thing-view.js"></script>
<!-- endbuild -->

The useminPrepare task will set the following configuration:

{
  concat: {
    '.tmp/concat/js/app.js': [
      'app/js/app.js',
      'app/js/controllers/thing-controller.js',
      'app/js/models/thing-model.js',
      'app/js/views/thing-view.js'
    ]
  },
  uglifyjs: {
    'dist/js/app.js': ['.tmp/concat/js/app.js']
  }
}

And the block in the HTML will then be replaced with with:

<script src="dist/js/app.js"></script>

For more information, see https://github.com/yeoman/grunt-usemin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top