From f62bf56e563127f6139bde1075c499c08b7d15f3 Mon Sep 17 00:00:00 2001 From: Jussi Steenari Date: Mon, 22 Feb 2021 17:10:30 +0200 Subject: [PATCH 1/3] webui: Add cache invalidation support * use webpack hash functionality to generate unique filenames for `b2share-bundle.js` * index.html created from template (html-webpack-plugin) Signed-off-by: Jussi Steenari Co-authored-by: Harri Hirvonsalo --- webui/app/index.html | 6 +- webui/package.json | 2 + webui/templates/index_template.html | 99 +++++++++++++++++++++++++++++ webui/webpack.config.devel.js | 22 ++++++- webui/webpack.config.js | 23 ++++++- 5 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 webui/templates/index_template.html diff --git a/webui/app/index.html b/webui/app/index.html index 07f6135e3c..a26975ddc5 100644 --- a/webui/app/index.html +++ b/webui/app/index.html @@ -29,7 +29,7 @@ - +
@@ -93,7 +93,7 @@
- - + + diff --git a/webui/package.json b/webui/package.json index e2b8b4cf3b..497499622f 100644 --- a/webui/package.json +++ b/webui/package.json @@ -36,10 +36,12 @@ }, "dependencies": { "bootstrap": "^3.3.6", + "clean-webpack-plugin": "^1.0.1", "dotenv-webpack": "^1.5.7", "fast-json-patch": "^0.5.6", "font-awesome": "^4.4.0", "history": "^3.3.0", + "html-webpack-plugin": "^2.30.1", "immutable": "^3.7.6", "lodash": "^4.17.20", "moment": "^2.29.1", diff --git a/webui/templates/index_template.html b/webui/templates/index_template.html new file mode 100644 index 0000000000..1b2498f104 --- /dev/null +++ b/webui/templates/index_template.html @@ -0,0 +1,99 @@ + + + + + + + + B2SHARE + + + + + + + + + + + + + + + + + + + +
+
+
+
+
+
+ +
+
+
+
+
+ + +
+
+ + + + diff --git a/webui/webpack.config.devel.js b/webui/webpack.config.devel.js index 2ff54ad42f..ac54c6612d 100644 --- a/webui/webpack.config.devel.js +++ b/webui/webpack.config.devel.js @@ -2,13 +2,22 @@ var path = require('path'); var webpack = require('webpack'); const Dotenv = require('dotenv-webpack'); var WatchTimePlugin = require('webpack-watch-time-plugin'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const CleanWebpackPlugin = require('clean-webpack-plugin'); console.log("Using configuration file from", __dirname+'/../webui.cfg'); +let cleanOptions = { + root: __dirname+'/app', + verbose: true, + dry: false +} + + module.exports = { entry: ['./src/main.jsx'], devtool: 'cheap-module-eval-source-map', - output: { path: __dirname+"/app", filename: 'b2share-bundle.js' }, + output: { path: __dirname+"/app/", filename: 'js/b2share-bundle.[hash].js'}, plugins: [ // Note: Only values used in source code will be included in the bundle. // See dotenv-webpack documentation for more details. @@ -16,7 +25,16 @@ module.exports = { path: __dirname+'/../webui.cfg', // load this file instead of '.env'. systemvars: true, // load environment variables from 'process.env'. }), - WatchTimePlugin + WatchTimePlugin, + new CleanWebpackPlugin('js', cleanOptions), + //inject false prevents script tag from being automatically injected + //the script tag is injected directly in index_template.html code instead + new HtmlWebpackPlugin({ + inject: false, + hash: false, + template: 'templates/index_template.html', + filename: 'index.html' + }), ], module: { loaders: [ diff --git a/webui/webpack.config.js b/webui/webpack.config.js index 3d75459d6c..868be8f608 100644 --- a/webui/webpack.config.js +++ b/webui/webpack.config.js @@ -1,13 +1,23 @@ var path = require('path'); var webpack = require('webpack'); const Dotenv = require('dotenv-webpack'); +const HtmlWebpackPlugin = require('html-webpack-plugin'); +const CleanWebpackPlugin = require('clean-webpack-plugin'); console.log("Using configuration file from", __dirname+'/../webui.cfg'); +let cleanOptions = { + root: __dirname+'/app', + verbose: true, + dry: false +} + + + module.exports = { entry: ['./src/main.jsx'], devtool: 'source-map', - output: { path: __dirname+"/app", filename: 'b2share-bundle.js' }, + output: { path: __dirname+"/app/", filename: 'js/b2share-bundle.[hash].js'}, plugins: [ new webpack.DefinePlugin({ 'process.env': { @@ -22,6 +32,17 @@ module.exports = { }), new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/), // trim down moment.js new webpack.optimize.OccurenceOrderPlugin(), + + new CleanWebpackPlugin('js', cleanOptions), + + //inject false prevents script tag from being automatically injected + //the script tag is injected directly in index_template.html code instead + new HtmlWebpackPlugin({ + inject: false, + hash: false, + template: 'templates/index_template.html', + filename: 'index.html' + }), new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin({ compressor: { From a0681fda2be30426c3fdaac41db89c714aa8fff1 Mon Sep 17 00:00:00 2001 From: Jussi Steenari Date: Wed, 24 Feb 2021 15:17:24 +0200 Subject: [PATCH 2/3] update .gitignore to include new /js directory and index.html Signed-off-by: Jussi Steenari --- .gitignore | 4 +- webui/app/index.html | 99 -------------------------------------------- 2 files changed, 3 insertions(+), 100 deletions(-) delete mode 100644 webui/app/index.html diff --git a/.gitignore b/.gitignore index 3e9ecd618a..1dc6e019ad 100644 --- a/.gitignore +++ b/.gitignore @@ -47,6 +47,8 @@ app_instance/ webui/app/b2share-bundle.js webui/app/b2share-bundle.js.map webui/app/lib/ +webui/app/index.html +webui/app/js/ webui/app/vendors/ webui/src/version.js -webui/package-lock.json \ No newline at end of file +webui/package-lock.json diff --git a/webui/app/index.html b/webui/app/index.html deleted file mode 100644 index a26975ddc5..0000000000 --- a/webui/app/index.html +++ /dev/null @@ -1,99 +0,0 @@ - - - - - - - - B2SHARE - - - - - - - - - - - - - - - - - - - -
-
-
-
-
-
- -
-
-
-
-
- - -
-
- - - - From 44c0d0aaed40e96e4ab0be994876e47c85833587 Mon Sep 17 00:00:00 2001 From: Jussi Steenari Date: Tue, 16 Mar 2021 10:24:20 +0200 Subject: [PATCH 3/3] MODIFY: Changed links in index_template Signed-off-by: Jussi Steenari --- webui/templates/index_template.html | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/webui/templates/index_template.html b/webui/templates/index_template.html index 1b2498f104..41c5975fec 100644 --- a/webui/templates/index_template.html +++ b/webui/templates/index_template.html @@ -60,8 +60,7 @@ - +