I'm struggling to set up the correct definition, which really rewrites the urls. I used useref and usemin, and they do a good html scan, aggregating all JS and CSS and outputting them to a single file. But for my life, I cannot get URL rewriting to work properly. My structure is simple:
\root index.html application.css // minified application.js // minified \vendor \bootstrap \fonts // font files here bootstrap.css // pre-minified
bootstrap.css refers to font files using the relative url - font/bootstrap_font.ttf When bootstrap gets minified, it lands as part of the css application, that is, in my root now, so the path will point from root to /font/bootstrap_font.ttf . The original directory hierarchy remains, so I would like this URL to be rewritten to /vendor/bootstrap/font/bootstrap_font.ttf
And oh, why does the cssmin task not accept more than one file?
UPDATE Here is my current grunt file:
module.exports = function(grunt) { grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), useminPrepare: { html: 'web/public/index.html', options: { dest: 'web/public-dist' } }, usemin: { html: 'web/public-dist/index.html', }, copy: { all: { files: [{ expand: true, cwd: 'web/public/', src: ['**'], dest: 'web/public-dist/' }] }, resources: { files: [{ expand: true, cwd: 'web/public/', src: ['**/*.*', '!**/*.js', '!**/*.css', '!**/*.txt'], dest: 'web/public-dist/' }] } }, uglify: { options: { mangle: true, sourceMap: false, compress: true, banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n' }, standard: { files: [{ expand: true, cwd: 'web/public-dist/', src: ['**/*.js'], dest: 'web/public-dist/' }] } }, cssmin: { options: { banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n', }, standard: { files: [{ expand: true, cwd: 'web/public-dist/', src: ['**/*.css'], dest: 'web/public-dist/' }] }, } }); grunt.registerTask('package', [ 'copy:resources', 'useminPrepare', 'concat:generated','cssmin:generated', 'uglify:generated', 'usemin']); };
In this form, cssmin cannot even be used as a separately named target, because it seems that its configuration is incorrect - it complains that it cannot accept many files. What am I doing wrong here?
From the pieces and pieces that I put together, it is apparently important to change the usemin stream and not let it concatenate all css and cssmin later - because in this way it will obviously lose vital information about the directory origin of each css file. I tried to change the stream, but then it does not work due to the same cssmin error - it cannot accept many files.