From 13d417c1dc53e26c83f7406fc933398eba39868b Mon Sep 17 00:00:00 2001 From: Padraig Lamont Date: Mon, 3 May 2021 13:22:53 +0800 Subject: [PATCH] #134, #156, #163: Begin support of webpack --- babel.config.json | 5 ++ compilation.json | 78 +------------------------ package.json | 27 ++++++++- src/articles/about.html | 2 +- src/articles/learn/learn.html | 2 +- src/articles/learn/rules.html | 2 +- src/articles/learn/watch.html | 2 +- src/articles/privacy.html | 2 +- src/home/{home_resources.js => home.js} | 4 ++ webpack.config.js | 55 +++++++++++++++++ 10 files changed, 96 insertions(+), 83 deletions(-) create mode 100644 babel.config.json rename src/home/{home_resources.js => home.js} (79%) create mode 100644 webpack.config.js diff --git a/babel.config.json b/babel.config.json new file mode 100644 index 0000000..a29ac99 --- /dev/null +++ b/babel.config.json @@ -0,0 +1,5 @@ +{ + "presets": [ + "@babel/preset-env" + ] +} diff --git a/compilation.json b/compilation.json index 6d85935..06d9396 100644 --- a/compilation.json +++ b/compilation.json @@ -20,6 +20,7 @@ "src/status/lost.html": "lost.html" }, + "css": { "index.css": [ "src/common/base.css", @@ -90,83 +91,8 @@ "src/status/lost.css" ] }, - "javascript": { - "index.js": [ - "src/common/utils.js", - "src/common/resources/resource_loader.js", - "src/common/resources/image_system.js", - "src/home/home_resources.js" - ], - "game/index.js": [ - "src/game/lib/reconnecting-websocket.js", - "src/game/analytics/analytics.js", - "src/game/analytics/stats.js", - "src/game/game/board.js", - "src/game/model/model.js", - "src/game/model/dice_model.js", - - "src/game/network/packet_reader.js", - "src/game/network/packet_writer.js", - "src/game/network/packets.js", - "src/game/network/network_packets.js", - "src/game/network/ai_packets.js", - "src/game/network/network.js", - "src/game/game/game.js", - - "src/game/ui/menu.js", - "src/game/ui/layout.js", - - "src/game/rendering/particles.js", - "src/game/rendering/curves.js", - "src/game/rendering/renderer.js", - "src/game/rendering/render_menu.js", - "src/game/rendering/render_overlays.js", - "src/game/rendering/render_game_ui.js", - "src/game/rendering/render_dice.js", - "src/game/rendering/render_board.js", - - "src/game/ui/screens.js", - "src/game/client.js" - ], - "game/computer_worker.js": [ - "src/common/utils.js", - "src/game/network/packet_reader.js", - "src/game/network/packet_writer.js", - "src/game/network/packets.js", - "src/game/network/ai_packets.js", - "src/game/game/board.js", - "res/royal_ur_analysis/api/api.js", - "src/game/game/simulation.js", - "src/game/game/computer_worker.js" - ], - "game/resources.js": [ - "src/common/utils.js", - "src/common/resources/resource_types.js", - "src/common/resources/resource_loader.js", - "src/common/resources/audio_system.js", - "src/common/resources/image_system.js", - "src/game/game_resources.js" - ], - "article_resources.js": [ - "src/common/utils.js", - "src/common/resources/resource_loader.js", - "src/common/resources/image_system.js", - "src/articles/base/article_resources.js", - "src/articles/base/articles.js" - ], - "dice/index.js": [ - "src/common/utils.js", - "src/common/resources/resource_loader.js", - "src/common/resources/audio_system.js", - "src/common/resources/image_system.js", - "src/common/resources/resource_types.js", - "src/articles/base/article_resources.js", - "src/game/model/dice_model.js", - "src/game/rendering/render_dice.js", - "src/articles/learn/dice.js" - ] - }, + "javascript": {}, "resources": { "src/.htaccess": ".htaccess", diff --git a/package.json b/package.json index 3135fa4..1890df2 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,25 @@ { + "name": "royalur-net", + "author": { + "name": "Paddy Lamont", + "email": "padraiglamont@gmail.com", + "url": "https://github.com/Sothatsit" + }, + "description": "A free and open-source website to let people play and learn about The Royal Game of Ur.", + "version": "1.0.0", + "license": "GPL-3.0-or-later", + "homepage": "https://royalur.net", + "repository": { + "type": "git", + "url": "git+https://github.com/Sothatsit/RoyalUrClient.git" + }, + "bugs": { + "url": "https://github.com/Sothatsit/RoyalUrClient/issues" + }, + "private": "true", + "scripts": { + "build": "webpack --mode production" + }, "devDependencies": { "@babel/cli": "^7.12.1", "@babel/core": "^7.12.3", @@ -6,7 +27,9 @@ "autoprefixer": "^10.2.5", "postcss-cli": "^8.3.1", "postcss-preset-env": "^6.7.0", - "uglify-js": "^3.11.5", - "uglifycss": "^0.0.29" + "terser-webpack-plugin": "*", + "uglifycss": "^0.0.29", + "webpack": "^5.4.0", + "webpack-cli": "^4.2.0" } } diff --git a/src/articles/about.html b/src/articles/about.html index 51da6a5..46b6a49 100644 --- a/src/articles/about.html +++ b/src/articles/about.html @@ -180,6 +180,6 @@

Sponsor the Site

- + diff --git a/src/articles/learn/learn.html b/src/articles/learn/learn.html index a733811..2118e9d 100644 --- a/src/articles/learn/learn.html +++ b/src/articles/learn/learn.html @@ -48,6 +48,6 @@

Learn about the The Royal Game of Ur

- + diff --git a/src/articles/learn/rules.html b/src/articles/learn/rules.html index f80edc8..e153bad 100644 --- a/src/articles/learn/rules.html +++ b/src/articles/learn/rules.html @@ -132,6 +132,6 @@

Play The Royal Game of Ur

- + diff --git a/src/articles/learn/watch.html b/src/articles/learn/watch.html index 58a50e0..e437613 100644 --- a/src/articles/learn/watch.html +++ b/src/articles/learn/watch.html @@ -64,6 +64,6 @@

- + diff --git a/src/articles/privacy.html b/src/articles/privacy.html index 29043e5..0e8d945 100644 --- a/src/articles/privacy.html +++ b/src/articles/privacy.html @@ -174,6 +174,6 @@

Contact Us

- + diff --git a/src/home/home_resources.js b/src/home/home.js similarity index 79% rename from src/home/home_resources.js rename to src/home/home.js index 3724505..89f1993 100644 --- a/src/home/home_resources.js +++ b/src/home/home.js @@ -2,6 +2,10 @@ // This file manages the loading of resources for the home page. // +import "../common/utils" +import "../common/resources/resource_loader" +import "../common/resources/image_system" + const resourceLoader = new ResourceLoader(), imageSystem = new ImageSystem(resourceLoader); diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 0000000..4542e63 --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,55 @@ +const path = require("path"), + TerserPlugin = require("terser-webpack-plugin"); + +/** Returns an absolute path of a file relative to this config. **/ +function abs(...args) { + return path.resolve.apply(this, [__dirname].concat(args)); +} + +/** Joins several relative file pieces into one relative file path. **/ +function rel(...args) { + return "./" + path.join.apply(this, args); +} + +module.exports = { + output: { + path: abs('build', 'js') + }, + entry: { + home: { + import: rel('src', 'home', 'home.js'), + filename: rel('index.js') + }, + game: { + import: rel('src', 'game', 'client.js'), + filename: rel('game', 'index.js') + }, + gameWorker: { + import: rel('src', 'game', 'game', 'computer_worker.js'), + filename: rel('game', 'computer_worker.js') + }, + gameResources: { + import: rel('src', 'game', 'game_resources.js'), + filename: rel('game', 'resources.js') + }, + articles: { + import: rel('src', 'articles', 'base', 'articles.js'), + filename: rel('articles.js') + }, + dice: { + import: rel('src', 'articles', 'learn', 'dice.js'), + filename: rel('dice', 'index.js') + } + }, + optimization: { + minimize: true, + minimizer: [ + new TerserPlugin({ + terserOptions: { + mangle: false + } + }) + + ] + }, +};