From 6251fcf0757ef978bb3be63e5bf7c2274aa8fc82 Mon Sep 17 00:00:00 2001 From: fecaille Date: Thu, 31 Mar 2016 16:22:15 +0200 Subject: [PATCH] Optim: populate html template with resource links and hash --- package.json | 2 + .../opengroupe/cloud/saas/Application.java | 13 ++++++- src/main/resources/static/js/app.render.jsx | 4 ++ .../resources/static/js/nashorn-polyfill.js | 2 + .../resources/templates/index-template.html | 20 ++++++++++ webpack.config.js | 37 +++++++++++++------ 6 files changed, 66 insertions(+), 12 deletions(-) create mode 100644 src/main/resources/templates/index-template.html diff --git a/package.json b/package.json index 53f072c..75cf92b 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,8 @@ "css-loader": "^0.23.1", "extract-text-webpack-plugin": "^1.0.1", "file-loader": "^0.8.5", + "html-loader": "^0.4.3", + "html-webpack-plugin": "^2.15.0", "postcss-loader": "^0.8.2", "style-loader": "^0.13.1", "url-loader": "^0.5.7", diff --git a/src/main/java/com/opengroupe/cloud/saas/Application.java b/src/main/java/com/opengroupe/cloud/saas/Application.java index 4e2ac8f..3d60668 100644 --- a/src/main/java/com/opengroupe/cloud/saas/Application.java +++ b/src/main/java/com/opengroupe/cloud/saas/Application.java @@ -2,7 +2,8 @@ package com.opengroupe.cloud.saas; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; +import org.springframework.context.annotation.Bean; +import org.thymeleaf.templateresolver.ServletContextTemplateResolver; //@EnableOAuth2Sso @SpringBootApplication @@ -11,4 +12,14 @@ public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } + + @Bean + public ServletContextTemplateResolver templateResolver() { + ServletContextTemplateResolver resolver = new ServletContextTemplateResolver(); + resolver.setPrefix("/templates/"); + resolver.setSuffix(".html"); + resolver.setTemplateMode("LEGACYHTML5"); + resolver.setCacheable(false); + return resolver; + } } diff --git a/src/main/resources/static/js/app.render.jsx b/src/main/resources/static/js/app.render.jsx index 8da2f07..0e1003b 100644 --- a/src/main/resources/static/js/app.render.jsx +++ b/src/main/resources/static/js/app.render.jsx @@ -5,6 +5,7 @@ import React from 'react'; import ReactDOM from 'react-dom'; import ReactDOMServer from 'react-dom/server'; import App from './app.jsx'; +import $ from 'jquery'; require('bootstrap/dist/css/bootstrap.css'); @@ -25,3 +26,6 @@ global.renderServer = function (comments) { ); }; +if( !global.nashorn ) { + renderClient(initialData); +}; \ No newline at end of file diff --git a/src/main/resources/static/js/nashorn-polyfill.js b/src/main/resources/static/js/nashorn-polyfill.js index 0ccc16a..2ae426d 100644 --- a/src/main/resources/static/js/nashorn-polyfill.js +++ b/src/main/resources/static/js/nashorn-polyfill.js @@ -1,5 +1,7 @@ var global = window = this; +global.nashorn = true; + var console = { debug: print, warn: print, diff --git a/src/main/resources/templates/index-template.html b/src/main/resources/templates/index-template.html new file mode 100644 index 0000000..2d5b495 --- /dev/null +++ b/src/main/resources/templates/index-template.html @@ -0,0 +1,20 @@ + + + + + Comments channel + + +
+ +
+
+
+ +
+ + + + \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index d1cb047..c8dbcc3 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,15 +1,16 @@ var path = require('path'), webpack = require('webpack'), CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin"), - ExtractTextPlugin = require("extract-text-webpack-plugin"); + ExtractTextPlugin = require("extract-text-webpack-plugin"), + HtmlWebpackPlugin = require('html-webpack-plugin'); -var source_dir = __dirname + '/src/main/resources/static/js', +var source_dir = __dirname + '/src/main/resources/static', node_dir = __dirname + '/node_modules'; var config = { entry: { - app: [source_dir + '/app.render'], - vendors: [source_dir + '/vendors'] + app: [source_dir + '/js/app.render'], + vendors: [source_dir + '/js/vendors'] }, resolve: { extensions: ['', '.js', '.jsx', '.css'] @@ -18,12 +19,19 @@ var config = { cache: true, debug: true, output: { - path: './target/classes/static/js', - filename: '[name].bundle.js' + path: './target/classes/static', + filename: 'js/[name].bundle.js', + publicPath: '/' }, plugins: [ - new ExtractTextPlugin("../css/[name].css"), + new ExtractTextPlugin("css/[name].css"), new CommonsChunkPlugin("vendors", null, true), + new HtmlWebpackPlugin({ + template: path.join(__dirname, 'src/main/resources/templates/index-template.html'), + filename: '../templates/index.html', + xhtml: true, + hash: true + }) ], module: { loaders: [ @@ -42,24 +50,31 @@ var config = { }, { test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, - loader: "file?name=../css/[name].[ext]" + loader: "file?name=font/[name].[ext]" }, { test: /\.(woff|woff2)$/, - loader:"url?prefix=font/&limit=5000&name=../css/[name].[ext]" + loader:"url?prefix=font/&limit=5000&name=font/[name].[ext]" }, { test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, - loader: "url?limit=10000&mimetype=application/octet-stream&&name=../css/[name].[ext]" + loader: "url?limit=10000&mimetype=application/octet-stream&&name=font/[name].[ext]" }, { test: /\.svg(\?v=\d+\.\d+\.\d+)?$/, - loader: "url?limit=10000&mimetype=image/svg+xml&&name=../css/[name].[ext]" + loader: "url?limit=10000&mimetype=image/svg+xml&&name=font/[name].[ext]" + }, + { + test: /\.html$/, + loader: 'html-loader?minimize=false' } ] }, postcss: function () { return []; + }, + htmlLoader: { + removeAttributeQuotes: false, } };