gruntjs - Relative paths in CSS and Grunt minification? -



gruntjs - Relative paths in CSS and Grunt minification? -

before inquire question want point out there several similar questions posted here on stackoverflow, none of them provide accurate solution problem.

the problem

i have workflow setup grunt combines , minifies multiple css files 1 single file production environment.

the problem i'm facing font , image paths breaking after running grunt, they're still pointing towards existing relative file paths.

as example:

within static/homepage/startup/common-files/css/icon-font.css have next css rule:

@font-face{font-family:flat-ui-icons;src:url(../fonts/startup-icons.eot);

in gruntfile, specify want output of minified css file style.min.css located @ static/css/custom/homepage/. problem filepath changes, resulting in font , image dependencies no longer found , homecoming 404 status in browser.

what i've done seek solve this

i've figured there 2 options prepare issue:

copy dependant files they're relative new directory wherestyle.min.css resides. downside become messy , ruin project folder structure! change paths manually hand. again, what's point in this? grunt designed automating tasks!

does know how prepare problem? i've wasted 10 hours on , i'm starting give up. people have claimed have fixed issue on @ github issue page, nobody says how fixed it.

edit:

i've looked through clean-css library source code , seems can pass relativeto property minifier object. i've had mess around i'm still stuck. i'll study if farther this.

edit:

okay i've found documentation explains relativeto (and other) properties do. i'm still stuck on configuration should file construction though....

relativeto - path resolve relative @import rules , urls root - path resolve absolute @import rules , rebase relative urls roundingprecision - rounding precision; defaults 2; -1 disables rounding target - path folder or output file rebase urls

here's grunt configuration file reference:

module.exports = function(grunt) { grunt.initconfig({ concat: { homepage: { src: [ 'static/homepage/startup/common-files/css/icon-font.css', 'static/homepage/startup/flat-ui/bootstrap/css/bootstrap.css', 'static/homepage/startup/flat-ui/css/flat-ui.css', 'static/homepage/static/css/style.css' ], dest: 'static/css/custom/homepage/compiled.css', } }, cssmin: { homepage: { src: 'static/css/custom/homepage/compiled.css', dest: 'static/css/custom/homepage/style.min.css' } } }); grunt.loadnpmtasks('grunt-contrib-concat'); grunt.loadnpmtasks('grunt-contrib-uglify'); grunt.loadnpmtasks('grunt-contrib-cssmin'); grunt.loadnpmtasks("grunt-css-url-rewrite"); grunt.registertask('build', ['concat', 'cssmin']); grunt.registertask('default', ["build"]); };

thanks.

this isn't direct reply question, possible solution. imo, might improve off if refactor directory construction bit , tweek gruntfile.

new structure:

project-root /assets /styles (various css files) /scripts (js files) /images (image files) /fonts /vendor (if needed) /plugin files

if add together in few grunt tasks, such imagemin , copy, can have files placed new directory construction when saved or altered:

project-root /assets /dist /styles /styles.css /styles.min.css /scripts /scripts.min.js /images (minified images) /fonts (minified fonts)

to farther clarify:

concatenate css files dist/styles/style.css, minify file dist/styles/style.min.css concatenate js files dist/scripts/scripts.js, minify file dist/scripts/scripts.min.js use images minify images added assets/images folder , re-create dist/images use re-create copy fonts assets/fonts dist/fonts

your new workflow work within assets directory, add together of images there, of fonts, etc. however, reference assets in relation file when output dist folder.

all of stylesheets, scripts, etc. point dist folder.

plus, of assets nice , slim since of them go through kind of minification.

if need have vendor files, such plugins, etc., add together vendor directory (better yet add together them bower rather manually), , include files need in appropriate concat tasks.

css gruntjs relative-path minify grunt-contrib-concat

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -