Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect image paths #35

Closed
roelvanduijnhoven opened this issue Aug 16, 2013 · 13 comments
Closed

Incorrect image paths #35

roelvanduijnhoven opened this issue Aug 16, 2013 · 13 comments

Comments

@roelvanduijnhoven
Copy link

For a project I am developing I want to bundle two CSS files from seperate directories into a file in a third directory. Each of these two source CSS files reference to images relative to their working directory. Obviously the paths are no longer correct after they have been bundled and stored in a third location.

I would expect css min to rewrite the url's so the change of location is reflected. This could be either done by:

  • Rewriting the URLs to be absolute
  • Rewriting the URLs so the relative path is updated

How can I accomplish this task? Or am I tackling the problem of bundling external libraries in a wrong way? Is the solution perhaps to just manually copy the needed assets to the correct location?

@shama
Copy link
Member

shama commented Aug 16, 2013

This task is a wrapper for clean-css. You could try requesting this feature over there.

I believe they have root and relativeTo for @import inlining... not sure about url paths.

@shama shama closed this as completed Aug 16, 2013
@kylecordes
Copy link

As you pointed out, clean-css has this features. If I understand right from here:

https://github.com/GoalSmashers/clean-css

grunt-contrib-cssmin would need to expose and/or automatically use the root or relativeto settings for this to work. Does it do so? Does it actually work?

@calebolin
Copy link

+1

@Sanabria
Copy link

+1!

@christang
Copy link

+2!

@jamesplease jamesplease reopened this May 3, 2014
@jamesplease
Copy link
Member

PRs are welcome to introduce these options to this task :)

@spooky
Copy link

spooky commented May 27, 2014

+1

2 similar comments
@dmkuznetsov
Copy link

+1

@delijah
Copy link

delijah commented Jul 30, 2014

+1

@mrbbdx
Copy link

mrbbdx commented Jul 30, 2014

@roelvanduijnhoven @kylecordes @calebolin @Sanabria @christang @jmeas @spooky @dmkuznetsov @delijah

I fixed this on my project by adding the following grunt task, and yes, it actually works:

cssmin: {
    options: {
//        relativeTo: './', // Not needed for me
        root: './'
    },
    combine: {
        files: {
            'build/build.css': includes.css
        }
    }
}

Hope this helps someone else

@Buntix
Copy link

Buntix commented Aug 18, 2014

Looking in https://github.com/gruntjs/grunt-contrib-cssmin/blob/master/tasks/cssmin.js it seems to pass the options straight through, so presumably all the cleanCSS options should work.

As well as the absolute url fix from @bobjones above it's also possible to rebase with relative URLs using target: (I'm using it on a project where the development version has a completely different path to the production one). The cleanCSS options for this are at https://github.com/GoalSmashers/clean-css#how-to-rebase-relative-image-urls

As an example, my current Gruntfile.coffee config (pre any attempt to tidy - there's definitely something awry as I needed to double up /css/css/ in the target: to get the url rebasing right) is

    cssmin: 
      options:
        target: './web/css/css/'


      combine:
        files:
          'web/css/theme_combined.css': [
            'web/css/lib/ui-lightness/jquery-ui-1.10.3.custom.css'
            'web/css/lib/socialstream/css/dcsns_dark.css'
            'web/css/theme/bootstrap.css'
            'web/css/theme/bootstrap-theme.css'
            'web/css/theme/fonts/font-awesome/css/font-awesome.css'
            'web/css/theme/style.css'
            'web/css/theme/global.css'
            'web/css/theme/colors/magenta.css'
            'web/css/theme/theme-responsive.css'
          ]

@cdaringe
Copy link

Indeed, the rev history on the homepage states "2013-09-14   v0.6.2   Support relative URLs via clean-css ~1.1.1.". Not sure who has tested it yet, but if so, it may be nice to toss up a README update PR

@cdaringe
Copy link

#150 . as @bobjones mentions, you can pass this in via the options argument. Thus, @roelvanduijnhoven, can you create multiple targets using options: {relativeTo: '/path/name'}, then have a final target that combines the output of the former?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests