I've been struggling for hours trying to set up proper minification that actually rewrites urls. I've used useref and usemin, and they do good job of scanning html, aggregating all JS and CSS and outputting into one file. But, for the life of me, I cannot make the url rewrite 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 by using relative url - font/bootstrap_font.ttf
When bootstrap gets minified, it lands as part of application css, that is in my root now, so the path would point from root to /font/bootstrap_font.ttf
. Original directory hierarchy stays, so I would basically like to have this url rewritten to /vendor/bootstrap/font/bootstrap_font.ttf
And, oh, why cssmin task doesn't accept more than one file?
UPDATE Here's 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 be even used as separately called target, because apparently its configuration is wrong - it complains that it cannot accept many files. What am I doing wrong here?
From the bits and pieces I've gathered, apparently it's crucial to change usemin flow and not allow it to concatenate all the css and cssmin later - because this way, it would obviously lose the vital information about the directory origin of every css file. I've tried changing the flow, but then it doesn't work because of the same cssmin error - cannot accept many files.