borodean / postcss-assets

An asset manager for PostCSS
MIT License
537 stars 32 forks source link

wrong path calculation with grunt variable <%= paths.destinationdir %> #66

Closed erredeco closed 7 years ago

erredeco commented 7 years ago

I have defined on my Gruntfile.js:

module.exports = function(grunt) {
    ...
    paths: {
        ...
        destinationdir: './dist/',
        ...
    }
    ...
}

Using as configuration:

options: {
  processors: [

    require('postcss-assets')({
        cachebuster: true,
        loadPaths: ['Img-layout/'],
        relative:true,
        basePath:'<%= paths.destinationdir %>Assets/' 
    }),
  ]
},
dist: {
  src: '<%= paths.destinationdir %>Assets/Css/*.css'
}

I obtain the error Fatal error: Asset not found or unreadable: myimage.jpg

Using instead:

cachebuster: true,
loadPaths: ['Img-layout/'],
relative: true,
basePath:'./dist/Assets/' 

Everything works. I can't understand why.

borodean commented 7 years ago

@erredeco I'm not really good at Grunt, so I am wondering: does Grunt variable is expected to be evaluated when it is not the part of the main configuration object? Because in your case it is not: the variable is set on a separate object which is passed to the plugin function.

My assumption that it is not getting evaluated at all because of that.

erredeco commented 7 years ago

@borodean I've understood why it fails. Thank you... I'll try to find if there is a way to pass it to the plugin function. I am not expert, too.

borodean commented 7 years ago

@erredeco I think if my assumption on why it fails is right, it would be cool if grunt-postcss supports passing plugins and their options separately (so options are a part of the main configuration object and variables would get substituted there).

cc @nDmitry