From aa19744ae40767b2523ac0117792b47e08209cdf Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Thu, 22 Jun 2017 15:37:09 +0300 Subject: Webpack 3, chunknames in templates --- .gitignore | 9 ++- juick-www/.eslintrc | 3 +- juick-www/build.gradle | 2 +- juick-www/package.json | 8 ++- juick-www/src/main/java/com/juick/www/WebApp.java | 65 ++++++++++++++------- .../www/configuration/WwwAppConfiguration.java | 22 ++++++- .../www/configuration/WwwServletConfiguration.java | 6 +- .../com/juick/www/controllers/PageTemplates.java | 9 ++- juick-www/src/main/resources/favicon.png | Bin 0 -> 244 bytes juick-www/src/main/resources/logo.png | Bin 0 -> 1184 bytes juick-www/src/main/resources/tagscloud.png | Bin 0 -> 42316 bytes .../src/main/webapp/WEB-INF/layouts/content.html | 6 +- juick-www/src/main/webapp/favicon.png | Bin 244 -> 0 bytes juick-www/src/main/webapp/logo.png | Bin 1184 -> 0 bytes juick-www/src/main/webapp/tagscloud.png | Bin 42316 -> 0 bytes juick-www/webpack.config.js | 22 ++++--- 16 files changed, 100 insertions(+), 52 deletions(-) create mode 100644 juick-www/src/main/resources/favicon.png create mode 100644 juick-www/src/main/resources/logo.png create mode 100644 juick-www/src/main/resources/tagscloud.png delete mode 100644 juick-www/src/main/webapp/favicon.png delete mode 100644 juick-www/src/main/webapp/logo.png delete mode 100644 juick-www/src/main/webapp/tagscloud.png diff --git a/.gitignore b/.gitignore index dd3cfa84..0be9451b 100644 --- a/.gitignore +++ b/.gitignore @@ -14,8 +14,7 @@ deps/* **/.project **/.settings/** **/bin/** -juick-www/src/main/webapp/scripts.js* -juick-www/src/main/webapp/style.css* - -juick-spring-www/src/main/webapp/scripts.js* -juick-spring-www/src/main/webapp/style.css* \ No newline at end of file +juick-www/src/main/resources/*.js +juick-www/src/main/resources/*.css +juick-www/src/main/resources/*.map +juick-www/src/main/resources/manifest.json \ No newline at end of file diff --git a/juick-www/.eslintrc b/juick-www/.eslintrc index c4d57a6c..1af934cd 100644 --- a/juick-www/.eslintrc +++ b/juick-www/.eslintrc @@ -51,6 +51,7 @@ "no-shadow": "off", "no-cond-assign": "off", "no-sparse-arrays": "off", - "no-unused-vars": "off" + "no-unused-vars": "off", + "no-useless-escape": "off" } } diff --git a/juick-www/build.gradle b/juick-www/build.gradle index 55a15a83..5a11e9e2 100644 --- a/juick-www/build.gradle +++ b/juick-www/build.gradle @@ -35,7 +35,7 @@ dependencies { } compileFrontend.dependsOn 'npmInstall' -war.dependsOn 'compileFrontend' +processResources.dependsOn 'compileFrontend' compileJava.options.encoding = 'UTF-8' gretty { diff --git a/juick-www/package.json b/juick-www/package.json index f33c3d8f..56468076 100644 --- a/juick-www/package.json +++ b/juick-www/package.json @@ -16,19 +16,21 @@ "babel-loader": "^7.0.0", "babel-preset-es2015": "^6.24.1", "css-loader": "^0.28.1", - "eslint": "^3.1.1", + "eslint": "^4.0.0", "eslint-loader": "^1.4.1", "extract-text-webpack-plugin": "^2.1.0", "file-loader": "^0.11.1", "globby": "^6.1.0", "script-loader": "^0.7.0", - "style-loader": "^0.17.0", + "style-loader": "^0.18.2", "stylelint": "^7.11.1", "stylelint-config-standard": "^16.0.0", "stylelint-webpack-plugin": "^0.7.0", "uglify-loader": "^2.0.0", "url-loader": "^0.5.7", - "webpack": "^2.5.1" + "webpack": "^3.0.0", + "webpack-asset-pipeline": "^1.1.1", + "webpack-manifest-plugin": "^1.1.0" }, "dependencies": { "autosize": "^3.0.16", diff --git a/juick-www/src/main/java/com/juick/www/WebApp.java b/juick-www/src/main/java/com/juick/www/WebApp.java index 72eb3fbc..6d809245 100644 --- a/juick-www/src/main/java/com/juick/www/WebApp.java +++ b/juick-www/src/main/java/com/juick/www/WebApp.java @@ -20,14 +20,10 @@ package com.juick.www; import com.juick.Message; import com.juick.Tag; import com.juick.service.TagService; -import com.juick.service.UserService; -import com.juick.www.controllers.PageTemplates; -import org.apache.commons.lang3.BooleanUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.math.NumberUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.core.env.Environment; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.annotation.Value; import rocks.xmpp.addr.Jid; import rocks.xmpp.core.XmppException; import rocks.xmpp.core.session.Extension; @@ -35,6 +31,8 @@ import rocks.xmpp.core.session.XmppSessionConfiguration; import rocks.xmpp.core.session.debug.LogbackDebugger; import rocks.xmpp.extensions.component.accept.ExternalComponent; +import javax.annotation.PostConstruct; +import javax.inject.Inject; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -44,35 +42,42 @@ import java.util.stream.Stream; * * @author Ugnich Anton */ -public class WebApp implements AutoCloseable { +public class WebApp implements DisposableBean { private static Logger logger = LoggerFactory.getLogger(WebApp.class); private ExternalComponent xmpp; - Environment env; - PageTemplates templates; - UserService userService; + @Inject TagService tagService; + @Value("${img_path:/var/www/juick.com/i/}") private String imgDir; + @Value("${upload_tmp_dir:/var/www/juick.com/i/tmp/}") private String tmpDir; + @Value("${xmpp_host:localhost}") + private String xmppHost; + @Value("${xmpp_password:secret}") + private String xmppPassword; + @Value("${www_xmpp_jid:www.juick.local}") + private String xmppJid; + @Value("${xmpp_port:5347}") + private int xmppPort; + @Value("${xmpp_disabled:false}") + private boolean isXmppDisabled; - public WebApp(Environment env, PageTemplates templates, UserService userService, TagService tagService) { - this.env = env; - this.templates = templates; - this.userService = userService; - this.tagService = tagService; - tmpDir = env.getProperty("upload_tmp_dir", "/var/www/juick.com/i/tmp/"); - imgDir = env.getProperty("img_path", "/var/www/juick.com/i/"); - boolean isXmppDisabled = BooleanUtils.toBoolean(env.getProperty("xmpp_disabled")); + private String scriptsUrl; + private String styleUrl; + + @PostConstruct + public void init() { if (!isXmppDisabled) { - setupXmppComponent(Jid.of(env.getProperty("www_xmpp_jid", "www.juick.local")), - env.getProperty("xmpp_password"), NumberUtils.toInt(env.getProperty("xmpp_port", StringUtils.EMPTY), 5347)); + setupXmppComponent(Jid.of(xmppJid), + xmppPassword, xmppPort); } } @Override - public void close() { + public void destroy() { try { if (xmpp != null) xmpp.close(); @@ -87,7 +92,7 @@ public class WebApp implements AutoCloseable { .extensions(Extension.of(Message.class)) .debugger(LogbackDebugger.class) .build(); - xmpp = ExternalComponent.create(componentJid.toString(), password, configuration, "localhost", port); + xmpp = ExternalComponent.create(componentJid.toString(), password, configuration, xmppHost, port); xmpp.addConnectionListener(e -> logger.error(e.toString(), e.getCause())); try { xmpp.connect(); @@ -128,4 +133,20 @@ public class WebApp implements AutoCloseable { } return tags; } + + public String getStyleUrl() { + return styleUrl; + } + + public String getScriptsUrl() { + return scriptsUrl; + } + + public void setScriptsUrl(String scriptsUrl) { + this.scriptsUrl = scriptsUrl; + } + + public void setStyleUrl(String styleUrl) { + this.styleUrl = styleUrl; + } } diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java index 2cf1faed..a5bc3f73 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java @@ -1,13 +1,16 @@ package com.juick.www.configuration; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.www.HelpService; -import com.juick.www.controllers.PageTemplates; import com.juick.www.WebApp; +import com.juick.www.controllers.PageTemplates; +import org.apache.commons.io.IOUtils; +import org.springframework.beans.factory.annotation.Value; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.caffeine.CaffeineCacheManager; import org.springframework.context.annotation.Bean; @@ -17,6 +20,9 @@ import org.springframework.core.env.Environment; import javax.annotation.Resource; import javax.inject.Inject; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.HashMap; /** * Created by aalexeev on 11/22/16. @@ -31,10 +37,20 @@ public class WwwAppConfiguration { private UserService userService; @Inject private TagService tagService; + @Inject + private ObjectMapper jsonMapper; + @Value("#{servletContext.contextPath}") + private String servletContextPath; @Bean - public WebApp webApp() { - return new WebApp(env, templates(), userService, tagService); + public WebApp webApp() throws IOException { + WebApp app = new WebApp(); + String manifestString = IOUtils.toString(getClass().getClassLoader().getResourceAsStream("manifest.json"), StandardCharsets.UTF_8); + HashMap manifest = jsonMapper.readValue(manifestString, + new TypeReference>() {}); + app.setScriptsUrl(manifest.get("scripts.js")); + app.setStyleUrl(manifest.get("style.css")); + return app; } @Bean public PageTemplates templates() { diff --git a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java index 43ca37db..ae51f1cd 100644 --- a/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java +++ b/juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java @@ -38,11 +38,11 @@ public class WwwServletConfiguration extends WebMvcConfigurationSupport { protected void addResourceHandlers(ResourceHandlerRegistry registry) { registry.setOrder(0); registry.addResourceHandler( - "/scripts.js*", - "/style.css*", + "/scripts*.js*", + "/style*.css*", "/*.png", "/favicon.ico") - .addResourceLocations("/") + .addResourceLocations("classpath:/") .setCacheControl(CacheControl.maxAge(30, TimeUnit.DAYS).mustRevalidate().cachePublic()) .resourceChain(true) .addResolver(new PathResourceResolver()); diff --git a/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java b/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java index 925d1013..5f758608 100644 --- a/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java +++ b/juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java @@ -23,6 +23,7 @@ import com.juick.service.MessagesService; import com.juick.service.TagService; import com.juick.service.UserService; import com.juick.util.MessageUtils; +import com.juick.www.WebApp; import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.StringEscapeUtils; import org.slf4j.Logger; @@ -64,19 +65,21 @@ public class PageTemplates { MessagesService messagesService; @Inject UserService userService; + @Inject + WebApp webApp; public void pageHead(PrintWriter out, com.juick.User visitor, String title, String headers) { out.println(""); out.print(""); out.print(""); out.println(""); - out.print(""); - out.print(""); + out.print(""); + out.print(""); if (headers != null) { out.print(headers); } out.print("" + title + ""); - out.println(""); + out.println(""); out.println(""); out.println("