grails-lesscss-resources icon indicating copy to clipboard operation
grails-lesscss-resources copied to clipboard

Less resources in plugins are not processed

Open pparson opened this issue 13 years ago • 5 comments

I am facing the problem that less resources within plugins are not processed (i.e. not converted to css and not bundled) when run from a project. It works fine when running the plugin standalone. Also css and less files within the project are processed as expected.

I have reproduced such a constellation with the least amount of code and uploaded the plugin and project here: http://www.2shared.com/complete/4OM-RVC6/lesstest.html

If there is any patch or workaround for cases like this, I'd be very happy. Or am I abusing grails-lesscss-resources plugin?

Thanks and best regards, Peter

pparson avatar Sep 19 '12 16:09 pparson

I did some debugging and found out that lesscssResourceMapper is called with the less resource name in question (the one from the plugin). Having a breakpoint in getOriginalFileSystemFile(String) revealed that the file is not in the list of resources, the call to grailsApplication.parentContext.getResource(sourcePath).file throws an exception. I used the evaluator to call grailsApplication.parentContext.getResources("**/*") and in the list are no resources from the plugin, only the project resources.

pparson avatar Sep 19 '12 18:09 pparson

Me again... sorry for providing additional infos step by step, but I am not an expert with Grails plugins and have to dig inside.

I dived a bit deeper into the lesscss-plugin code now and would like to ask one thing: is there a special reason that getOriginalFileSystemFile must be called at all? As far as I can see, the content would be exactly the same as in originalFile and input is only used to compile from, nothing else.

So I tried editing line 24 to simply say File input = originalFile; instead of File input = getOriginalFileSystemFile(resource.sourceUrl); and everything seems to work fine - at least for my use case.

I'll keep it like this for now as a temporary workaround, however I'd be happy if there was a clean solution, i.e. which does not involve me messing about in the plugin code (and maybe creating side effects by doing so)

pparson avatar Sep 20 '12 09:09 pparson

This missing functionality makes the plugin unusable. Per my understanding of resource plugin system, this should work, but it doesn't:

resource url:[plugin: 'MyPlugin', file: 'css/local.less'], attrs: [rel: "stylesheet/less", type: 'css'], bundle: 'bundle_MyApp'

k2s avatar Jul 08 '13 21:07 k2s

It works if you define your resources in the plugin like this:

modules = {
    myModuleInPlugin {
        resource url: [dir:'/less', file:'some-styles.less', plugin: 'my-plugin'], attrs:[rel: "stylesheet/less", type:'css']
    }
}

See the plugin definition inside the url and use dash notation instead of camelCase.

vviskari avatar Aug 16 '13 10:08 vviskari

We had the same problem as described by @pparson, and it worked fine for us after changing the resources notation as suggested by @vviskari above.

jklingen avatar Jan 23 '14 17:01 jklingen