1

Perhaps my google-fu is failing me today, however I am looking for an example/way to configure grunt.js to insert the contents of the post-compile javascript (and CSS) into the final rendered HTML document (to help with load/render times).

Has anyone done this, or can point me in the right direction?

1 Answer 1

2

Take a look at grunt-usemin. With this task you can add comments to your head around your script/style tags. The task will find all sources between the start/end of the comment and concat/minify/build requirejs for this files

<!-- build:js build/js/app.js -->
<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 -->

This block for example will result in a file app.js holding all the minified/concatenated files and create a new html file that replace the block with <script src="build/js/app.js"></script>

Sign up to request clarification or add additional context in comments.

2 Comments

Does this place nice with RequireJS? I believe they are depreciating requireJS support, but I'm not sure. Is there another requirejs specific solution?
No. It does not play nice with grunt-contrib-requirejs. grunt-contrib-requirejs a more full solution and you would waste time implementing usemin only to have it superseded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.