diff options
author | Vitaly Takmazov | 2017-06-22 15:37:09 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2017-06-22 16:12:02 +0300 |
commit | aa19744ae40767b2523ac0117792b47e08209cdf (patch) | |
tree | 83da69f6998f6cceac8d359f1b0ff566d4148c21 | |
parent | 7928ef38bbca41fdbcff17e78798b91723e2554e (diff) |
Webpack 3, chunknames in templates
-rw-r--r-- | .gitignore | 9 | ||||
-rw-r--r-- | juick-www/.eslintrc | 3 | ||||
-rw-r--r-- | juick-www/build.gradle | 2 | ||||
-rw-r--r-- | juick-www/package.json | 8 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/WebApp.java | 65 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/configuration/WwwAppConfiguration.java | 22 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/configuration/WwwServletConfiguration.java | 6 | ||||
-rw-r--r-- | juick-www/src/main/java/com/juick/www/controllers/PageTemplates.java | 9 | ||||
-rw-r--r-- | juick-www/src/main/resources/favicon.png (renamed from juick-www/src/main/webapp/favicon.png) | bin | 244 -> 244 bytes | |||
-rw-r--r-- | juick-www/src/main/resources/logo.png (renamed from juick-www/src/main/webapp/logo.png) | bin | 1184 -> 1184 bytes | |||
-rw-r--r-- | juick-www/src/main/resources/tagscloud.png (renamed from juick-www/src/main/webapp/tagscloud.png) | bin | 42316 -> 42316 bytes | |||
-rw-r--r-- | juick-www/src/main/webapp/WEB-INF/layouts/content.html | 6 | ||||
-rw-r--r-- | juick-www/webpack.config.js | 22 |
13 files changed, 100 insertions, 52 deletions
@@ -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<String, String> manifest = jsonMapper.readValue(manifestString, + new TypeReference<HashMap<String, String>>() {}); + 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("<!DOCTYPE html>"); out.print("<html>"); out.print("<head>"); out.println("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">"); - out.print("<link rel=\"stylesheet\" href=\"/style.css?v=2\"/>"); - out.print("<script type=\"text/javascript\" src=\"/scripts.js\"></script>"); + out.print("<link rel=\"stylesheet\" href=\"/" + webApp.getStyleUrl() + "\"/>"); + out.print("<script type=\"text/javascript\" src=\"/" + webApp.getScriptsUrl() + "\"></script>"); if (headers != null) { out.print(headers); } out.print("<title>" + title + "</title>"); - out.println("<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,user-scalable=no\"/>"); + out.println("<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\"/>"); out.println("<link rel=\"icon\" href=\"//i.juick.com/favicon.png\"/>"); out.println("<!--[if lt IE 9 & (!IEMobile 7)]>"); out.println("<script src=\"//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js\"></script>"); diff --git a/juick-www/src/main/webapp/favicon.png b/juick-www/src/main/resources/favicon.png Binary files differindex bc7161e2..bc7161e2 100644 --- a/juick-www/src/main/webapp/favicon.png +++ b/juick-www/src/main/resources/favicon.png diff --git a/juick-www/src/main/webapp/logo.png b/juick-www/src/main/resources/logo.png Binary files differindex 933f6099..933f6099 100644 --- a/juick-www/src/main/webapp/logo.png +++ b/juick-www/src/main/resources/logo.png diff --git a/juick-www/src/main/webapp/tagscloud.png b/juick-www/src/main/resources/tagscloud.png Binary files differindex 3e1bf169..3e1bf169 100644 --- a/juick-www/src/main/webapp/tagscloud.png +++ b/juick-www/src/main/resources/tagscloud.png diff --git a/juick-www/src/main/webapp/WEB-INF/layouts/content.html b/juick-www/src/main/webapp/WEB-INF/layouts/content.html index ea9faa0f..dedfbc30 100644 --- a/juick-www/src/main/webapp/WEB-INF/layouts/content.html +++ b/juick-www/src/main/webapp/WEB-INF/layouts/content.html @@ -3,13 +3,13 @@ <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> - <script type="text/javascript" src="/scripts.js"></script> - <link rel="stylesheet" type="text/css" href="/style.css" /> + <script type="text/javascript" src="/{{ beans.webApp.scriptsUrl }}"></script> + <link rel="stylesheet" type="text/css" href="/{{ beans.webApp.styleUrl }}" /> {% block headers %} {{ headers | default('') | raw }} {% endblock %} <title>{{ title | default('Juick') }}</title> - <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" /> + <meta name="viewport" content="width=device-width,initial-scale=1" /> <link rel="icon" href="//i.juick.com/favicon.png" /> </head> <body id="body"> diff --git a/juick-www/webpack.config.js b/juick-www/webpack.config.js index 383c62a5..f4e41ecf 100644 --- a/juick-www/webpack.config.js +++ b/juick-www/webpack.config.js @@ -1,19 +1,23 @@ var webpack = require("webpack") -var globby = require("globby") var ExtractTextPlugin = require("extract-text-webpack-plugin") var StyleLintPlugin = require('stylelint-webpack-plugin') +var AssetPipelinePlugin = require('webpack-asset-pipeline') + module.exports = { devtool: 'source-map', entry: { - "scripts" : globby.sync([ - __dirname + "/src/main/static/*.*", - require.resolve('evil-icons/assets/evil-icons.css'), + "scripts" : [ + __dirname + "/src/main/static/scripts.js", require.resolve('evil-icons/assets/evil-icons.js') - ]) + ], + "style" : [ + __dirname + "/src/main/static/style.css", + require.resolve('evil-icons/assets/evil-icons.css') + ] }, output: { - path: __dirname + "/src/main/webapp", - filename: "[name].js" + path: __dirname + "/src/main/resources", + filename: "[name].[chunkhash].js" }, module: { loaders: [ @@ -25,8 +29,10 @@ module.exports = { ] }, plugins: [ + new webpack.optimize.ModuleConcatenationPlugin(), new StyleLintPlugin({ configFile: '.stylelintrc.json', context: 'src/main/static', files: ['**/*.css'], emitErrors: false }), - new ExtractTextPlugin({ filename: "style.css", allChunks: true }) + new ExtractTextPlugin({ filename: "style.[chunkhash].css", allChunks: true }), + new AssetPipelinePlugin() ], }
\ No newline at end of file |