0

On migrating from Grails 2.5 to Grails 3 it is recommended that not to use the resource plugin as post Grails 3 resource plugin is deprecated. As a alternative I used asset pipeline.Is there a recommended method of replacing resources plugin modules when moving to the asset-pipeline plugin? Custom tags are used in GSP files which are suppose to include the content from the CSS files. Currently I am creating empty .js or .css files that require the resources that were in the module, then replace CSS content referring to the empty file. If there is a better way to do this?

<html>
<head>
<g:layoutHead/>
<r:layoutResources />
<r:external uri="/css/mycss.css" type="css" />
<g:customStylesheetIncludes/>
</head>
<body>
<g:layoutBody/>
<r:layoutResources />
</body>
</html>

Which is going to be handled by the custom taglib :

class MyResourcesTagLib {

    def customStylesheetIncludes = { attrs ->
        def controller = attrs.controller ?: controllerName
        def action = attrs.action ?: actionName

        writeCssIfExists( out, "css/my-custom.css" )

        // Determine the current page
        writeCssIfExists( out, "css/views/$controller/${action}-custom.css" )
    }

    private resourceExists( resPath ) {
        return grailsApplication.parentContext.getResource( resPath ).file.exists()
    }

    private writeCssIfExists( writer, css ) {
        if (resourceExists(css)) {
            def baseUri = grailsAttributes.getApplicationUri(request)

            baseUri += (baseUri.endsWith('/') ? '' : '/')

            writer << r.external(uri: baseUri, type: 'css')
        }
    }
}

How can I handle the same using asset pipeline in Grails 3, any suggestions or lead is highly appreciated

Soven K Rout
  • 123
  • 1
  • 9
  • Asset pipeline works fine for assets under the assets folder, but given the proliferation of web components and javascript frameworks, we often find ourselves checking out external projects, outside of a Grails project, that we want to package and distribute with our application. So, rather than copying the assets of an external project into your grails app how do you make a reference to external folders, that will insure that those assets will be included with your app whenever you run the app during development, and when you WAR the app for deployment? This may be one approach. – Soven K Rout Apr 03 '20 at 10:42

1 Answers1

0

A possible workaround would to create a Gradle task which copies those assets in the external folder to the appropriate grails-app/assets folders

Sergio del Amo
  • 76,835
  • 68
  • 152
  • 179