lostintranslation
lostintranslation

Reputation: 24563

How to concat certain js files

I have the need to just concat certain 'vendor' JS files. My users won't always have access to the internet and I need to concat already minified JS files.

I have this index.html:

  <!-- build:js vendor.min.js -->
  <script type="text/javascript" src="bower_components/jquery/jquery.min.js"></script>
  <script type="text/javascript" src="bower_components/underscore/underscore.min.js"></script>
  ...
  <!-- endbuild -->

  <!-- build:js app.min.js -->
  <script type="text/javascript" src="app/app.js"></script>
  ...
  <!-- endbuild -->

I just want to concat the first group of files. Reason being is that some are already minified and some are not. The vendor files that are not minified cannot be minified.

Is there a way to run usemin to just concat the first group into a vendor.js file and concat and uglify the second group into an app.min.js file?

Upvotes: 0

Views: 136

Answers (1)

Mario Araque
Mario Araque

Reputation: 4572

You should use flow option to define your custom workflow.

For example, if you need to only concat a group of files, add this to the useminPrepare:

useminPrepare: {
  html: 'index.html',
  options: {
    flow: {
      html: {
        steps: {
          onlyconcat: ['concat']
        },
        post: {}
      }
    }
  }
}

In your index.html, change this:

<!-- build:onlyconcat vendor.min.js -->
<script type="text/javascript" src="bower_components/jquery/jquery.min.js"></script>
<script type="text/javascript" src="bower_components/underscore/underscore.min.js"></script>
...
<!-- endbuild -->

Upvotes: 1

Related Questions