<dependency>
<groupId>org.webjars.npm</groupId>
<artifactId>@webcomponents/webcomponentsjs</artifactId>
<version>2.5.0</version>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.webjars</groupId>
<artifactId>webjars-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactId>@webcomponents/webcomponentsjs</artifactId>
<outputDirectory>${project.basedir}/src/main/resources/static/webcomponentsjs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/webcomponents/**")
.addResourceLocations("classpath:/static/webcomponentsjs/");
}
}
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Custom Element</title>
<script src="/webcomponents/webcomponentsjs/webcomponents-bundle.js"></script>
</head>
<body>
<app-custom-element></app-custom-element>
<script>
class CustomElement extends HTMLElement {
constructor() {
super();
// Add your custom element's logic here
}
}
customElements.define('app-custom-element', CustomElement);
</script>
</body>
</html>