-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40298 from phillip-kruger/web-dependency-alignment
Align web-dependency-locator with some of the web-bundler features
- Loading branch information
Showing
11 changed files
with
334 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Binary file added
BIN
+16.1 KB
docs/src/main/asciidoc/images/web-dependency-locator-screenshot01.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
//// | ||
This guide is maintained in the main Quarkus repository | ||
and pull requests should be submitted there: | ||
https://github.com/quarkusio/quarkus/tree/main/docs/src/main/asciidoc | ||
//// | ||
= Web dependency locator | ||
include::_attributes.adoc[] | ||
:categories: web | ||
:summary: Learn more about how to use the web dependency locator | ||
:numbered: | ||
:sectnums: | ||
:sectnumlevels: 4 | ||
:topics: http,web,webjars,mvnpm,vertx,servlet,undertow | ||
:extensions: io.quarkus:quarkus-web-dependency-locator | ||
:web-locator-ga: quarkus-web-dependency-locator | ||
|
||
This document shows how static resources can be served from web dependency jars like https://www.webjars.org[WebJars] and https://mvnpm.org[mvnpm]. | ||
|
||
== Using the `{web-locator-ga}` extension | ||
|
||
[source,xml,subs="attributes+",role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"] | ||
.pom.xml | ||
---- | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>{web-locator-ga}</artifactId> | ||
</dependency> | ||
---- | ||
|
||
[source,gradle,subs="attributes+",role="secondary asciidoc-tabs-target-sync-gradle"] | ||
.build.gradle | ||
---- | ||
implementation("io.quarkus:{web-locator-ga}") | ||
---- | ||
|
||
=== WebJars | ||
If you are using https://www.webjars.org[WebJars], like the following JQuery one: | ||
|
||
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"] | ||
.pom.xml | ||
---- | ||
<dependency> | ||
<groupId>org.webjars</groupId> | ||
<artifactId>jquery</artifactId> | ||
<version>3.1.1</version> | ||
</dependency> | ||
---- | ||
|
||
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"] | ||
.build.gradle | ||
---- | ||
implementation("org.webjars:jquery:3.1.1") | ||
---- | ||
|
||
you can reference the files in the jar from your HTML, example `/webjars/jquery/3.1.1/jquery.min.js`. | ||
|
||
The above is available by default, however, adding the `{web-locator-ga}` extension allows you to reference the files without having to include the version in the path, example `/webjars/jquery/jquery.min.js`. | ||
|
||
=== Mvnpm | ||
|
||
If you are using https://mvnpm.org[mvnpm], like the following Lit one: | ||
|
||
[source,xml,role="primary asciidoc-tabs-target-sync-cli asciidoc-tabs-target-sync-maven"] | ||
.pom.xml | ||
---- | ||
<dependency> | ||
<groupId>org.mvnpm</groupId> | ||
<artifactId>lit</artifactId> | ||
<version>3.1.2</version> | ||
</dependency> | ||
---- | ||
|
||
[source,gradle,role="secondary asciidoc-tabs-target-sync-gradle"] | ||
.build.gradle | ||
---- | ||
implementation("org.mvnpm:lit:3.1.2") | ||
---- | ||
|
||
you can reference the files in the jar from your HTML, example `/_static/lit/3.1.2/index.js`. | ||
|
||
The above is available by default, however, adding the `{web-locator-ga}` extension allows you to reference the files without having to include the version in the path, example `/_static/lit/index.js`. | ||
|
||
==== ImportMaps | ||
|
||
Mvnpm jars also allows you to use an https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap[importmap], that will | ||
allow you to just use module imports, example `import { LitElement, html, css} from 'lit';`. | ||
|
||
The importmap is generated by the `{web-locator-ga}` extension, and available at `/_importmap/generated_importmap.js`. | ||
This means adding the following to your `index.html` will allow you to import web libraries by name: | ||
|
||
[source,html] | ||
---- | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>My app</title> | ||
<script src="/_importmap/generated_importmap.js"></script> <1> | ||
<script type="module"> | ||
import '@lit'; <2> | ||
import 'app/demo-app.js'; <3> | ||
</script> | ||
</head> | ||
</html> | ||
---- | ||
<1> Use the generated importmap | ||
<2> Import web libraries | ||
<3> Import your own files, this can be done by adding `quarkus.web-dependency-locator.import-mappings.app/ = /app/` to the config. Any key-value pair can be added. | ||
|
||
===== Automatic imports | ||
|
||
You can also automate the imports above. To do this, move your web assests from `src/main/resources/META-INF/resources` to `src/main/web` | ||
and now replace the above scripts and imports with `{#bundle /}`: | ||
|
||
[source,html] | ||
---- | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>My app</title> | ||
{#bundle /} <1> | ||
</head> | ||
</html> | ||
---- | ||
<1> This will be replaced at build time with the importmap script, and also include any CSS and JavaScript discovered in the `/app` directory. | ||
|
||
This allows you to add libraries, js and css without having to change your HTML. Hot-reload is also supported. | ||
|
||
=== Dev UI | ||
|
||
When adding the `{web-locator-ga}` extension , you can see the files being served, and the generated importmap, in the Dev UI: | ||
|
||
image:web-dependency-locator-screenshot01.png[alt=Card in Dev UI] | ||
image:web-dependency-locator-screenshot02.png[alt=Files] | ||
image:web-dependency-locator-screenshot03.png[alt=Importmap] |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.