(I keept finding this question when googling for a solution, so I just share the solution i found here so that others like me can find it.)
I just discovered a grunt plugin called grunt-bridge that can wrap static files in a html template with the static
tag. The documentation is not great but I figured how to get it to work for my project.
If you have scripts like this:
<!-- build:js({.tmp,app}) /scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/util/util.js"></script>
...
And the final output it to output something like this:
<script src="{% static 'adjangoappname/scripts/94223d51.scripts.js' %}"></script>
Install gruntbridge with npm install grunt-bridge --save-dev
and
add a config like this in the grunt.initConfig of the Gruntfile.js:
bridge: {
distBaseHtml: {
options: {
pattern: '{% static \'adjangoappname{path}\' %}',
html: '<%= yeoman.minifiedDir %>/index.html', dest: '<%= yeoman.templateDir %>/index.html'
}
},
distIndexHtml: {
options: {
pattern: '{% static \'adjangoappname{path}\' %}',
html: '<%= yeoman.minifiedDir %>/index.html', dest: '<%= yeoman.templateDir %>/index.html'
}
},
// ... etc for each html file you want to modify
},
Where <%= yeoman.minifiedDir %>
is the output directory of the final minified html files, and <%= yeoman.minifiedDir %>
is the destination template directory.
Replace adjangoappname
with the name of your django app or whatever directory prefix you want to have.
Then add grunt-bridge last in the registerTask list like this:
grunt.registerTask('build', [
//...
'htmlmin',
'bridge'
]);
(I think it's possible to make the config more compact, but this is the first method I discovered that worked)
grunt build
, there should not be a usemin block served to the client, this is only for grunt and has nothing to do with the backend (afaik). – Decentreplace: { example: { src: ['<%= yeoman.dist %>/*.html'], overwrite: true, replacements: [{ from: '<script src="scripts', to: '<script src="/static/mdb/scripts' }] } }
– Montfort