Repository navigation
Serve the console's webjars from a configurable base URL - #29
Merged
Merged
Conversation
The console links its webjars at <contextPath>/webjars/..., which Spring Boot serves off the classpath. An application that mirrors its static files to a CDN has no way to put these there too: the only lever is webjars.enabled=false, which means excluding the jars, supplying all four libraries and maintaining a layout — a large step for a question only about where bytes are fetched from. grails.plugin.console.webjars.baseUrl replaces that base for every link the plugin emits, the import map included, while the version in each URL is still resolved from the classpath. Unset, nothing changes. WebjarVersions.url() builds the URL, keeping the build-time default-version fallback the generator had, and returns null for a webjar that is not on the classpath so a caller can leave the tag out instead of emitting one with a null version in it. The gulp fragments generate through it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The console links its webjars at
<contextPath>/webjars/..., served by Spring Boot's classpathmapping. An application that mirrors its static files to a CDN has no way to put these there too.
The only lever today is
webjars.enabled = false, which is a much bigger step than the questiondeserves: exclude four jars, supply jQuery, Bootstrap and Bootstrap Icons yourself, and maintain a
layout to do it — all to change where bytes are fetched from, not which files or versions.
What
grails.plugin.console.webjars.baseUrlreplaces the base for every link the plugin emits, theCodeMirror import map included:
The version in each URL is still resolved from the runtime classpath, so this stays compatible with
an application overriding a webjar version. Unset, the default remains
<contextPath>/webjarsandnothing changes.
WebjarVersions.url(contextPath, name, file, defaultVersion = null)builds the URL. It keeps thebuild-time default-version fallback the generator already had for CodeMirror, and returns
nullfor a webjar that is not on the classpath, so a caller can leave the tag out rather than emit one
with a null version in it. The gulp fragments (
_webjarsCss.gsp,_webjarsJs.gsp,_webjarsModules.gsp) now generate through it, which also removes the repeated${request.contextPath}/webjars/...from 13 import-map entries.This is deliberately narrower than
webjars.enabled = false, and the two compose: an applicationthat wants to supply its own copies still turns the tags off, and one that just wants them served
from elsewhere sets a base.
Tests
WebjarVersionsSpeccovers the URL shape under a context path, the empty and null context path,the default-version fallback, classpath precedence over that fallback, and the null for an absent
webjar. Full plugin suite: 47 tests, all passing.