bertramdev / asset-pipeline

The core implementation of the asset pipeline for the jvm
193 stars 92 forks source link

Grails: assets not found across plugins #330

Closed ianroberts closed 1 year ago

ianroberts commented 1 year ago

Set-up

I have a somewhat complex project layout with multiple layers of Grails plugins - the "core" of my app is one plugin, the "skin" is a second plugin that depends on the core one, then the actual Grails app depends on both the core and skin plugins and adds tenant-specific logic. The exact app is not important, the essential part is the dependencies

         core plugin
          ^       ^
          |       |
  skin plugin     |
          ^       |
          |       |
       main application

The skin plugin provides the layout that all GSPs depend on, providing some CSS and JS of its own but also depending on common CSS and JS from the core plugin.

Expected behaviour

In both bootRun and assetCompile, any page referencing the main.gsp layout gets both core.css from the core plugin and skin.css from the skin plugin.

Actual behaviour

bootRun and assetCompile (whether called directly or as a dependency of assemble) gives a warning

Unable to Locate Asset: /core.css

and the core CSS is not available in the rendered page.

Observations

Note that if I build a WAR and look inside it, the core.css has been minified and hashed inside the core plugin JAR file in WEB-INF/lib, but it was not found when building assets for the intermediate skin plugin.

Also I can refer to core.css directly from the main app (by putting <asset:stylesheet src="core.css"/> in index.gsp) and it loads correctly. So the app is able to reference assets from any of its plugins, but a plugin is not able to reference assets from a different plugin.

Is this a bug or is the behaviour by design? Is one plugin supposed to be able to depend on another plugin and include its assets? I assumed so but it's not actually stated explicitly in the documentation that plugins can use assets from plugins, only that plugins can provide assets to the app.

ianroberts commented 1 year ago

Demo application available at https://github.com/ianroberts/cross-plugin-assets

Taack commented 1 year ago
assets {
    minifyJs = true
    minifyCss = true
    configOptions = [
            commonJs: false,
            bable: false
            // babel: [enabled: false, processJsFiles: false]
            // https://github.com/errbuddy/babel-asset-pipeline
    ] //useful for custom config on extension libraries
    excludes = ['**/*esm*']
    packagePlugin = true
}

Do you have the packagePlugin = true ?

ianroberts commented 1 year ago

Do you have the packagePlugin = true ?

I did not, and I can confirm that adding this to the plugins' build.gradle files does indeed fix the problem. So I guess I can close this issue and instead open one against grails-forge asking why this option is not enabled in the default build.gradle for a plugin project on https://start.grails.org...

ianroberts commented 1 year ago

I spoke too soon, looks like this issue has already been identified and fixed in grails-forge (https://github.com/grails/grails-forge/issues/197), it's just not live on the https://start.grails.org deployment yet.